I am writing a vbscript to install a .exe application. Script works fine except that once the script is completed I need SCCM 2012 to get a exit code of 3010 so that it would schedule a restart of the PC.
The .exe when run with silent switch suppresses the reboot but the application won't work until restarted. Could you help with a vbscript to return 3010 once setup is finished.
If your script runs under cscript.exe, use WScript.Quit:
copy con 27878706.vbs
WScript.Quit 3010
^Z
1 file(s) copied.
cscript 27878706.vbs
echo %ERRORLEVEL%
3010
Related
I need to trigger the execution of a powershell script on remote server under different user. This script uses 'gpg.exe' so the execution has to be on the remote server with a path pointing to 'gpg.exe'.
I created a bat file on remote server with following commands:
REM RUNTEST.BAT
time /T
SET PowerShellDir=C:\Windows\System32\WindowsPowerShell\v1.0
CD /D "%PowerShellDir%"
echo started
start /wait powershell.exe "Start-Transcript -Path D:\logs\testlog.txt;import-module
'\\ServerName\FolderName\Script\AutomationScript.ps1';Stop-Transcript"
time /T
echo done
exit /b
Then invoked this bat file from PowerShell on another machine:
runas /user:DOMAIN\serviceuser "\\ServerName\FolderName\Script\Execute.bat"
These steps do execute the PowerShell script successfully and the output is also as expected. However, this requires 'gpg.exe' to be available on the path mentioned in the PowerShell script on the machine which will invoke the execution. Is there a way the script can look for pre-requisites (like gpg.exe, folder structure etc) only on the remote server, not the machine which invoked the bat file?
Not sure if OS makes any difference, the remote server has Windows Server 2019 and calling machine has Win 10. The remote server has the required folder structure, gpg.exe, bat file to execute the PowerShell script successfully. The calling machine will not have 'gpg.exe' & the folder structure.
I'm installing PostgreSQL 10.10 on my windows 10 PC. But I'm getting the following error immediately after running the exe file.
Not sure where exactly things are going wrong. Whether it is windows user level or postgres level.
This is the installation log file...
Log started 08/13/2019 at 20:37:56
Preferred installation mode : qt
Trying to init installer in mode qt
Mode qt successfully initialized
Executing icacls "C:\Users\subbu\AppData\Local\Temp/postgresql_installer_d8432abdb1" /inheritance:r
Script exit code: 0
Script output:
processed file:
C:\Users\subbu\AppData\Local\Temp/postgresql_installer_d8432abdb1
Successfully processed 1 files; Failed processing 0 files
Script stderr:
Executing icacls "C:\Users\subbu\AppData\Local\Temp/postgresql_installer_d8432abdb1" /T /Q /grant "subbu:(OI)(CI)F"
Script exit code: 5
Script output:
Successfully processed 1 files; Failed processing 1 files
Script stderr:
C:\Users\subbu\AppData\Local\Temp/postgresql_installer_d8432abdb1\*: Access is denied.
Error running icacls:
"C:\Users\subbu\AppData\Local\Temp/postgresql_installer_d8432abdb1" /T /Q /grant "subbu:(OI)(CI)F": C:\Users\subbu\AppData\Local\Temp/postgresql_installer_d8432abdb1*: Access is denied.
Cannot delete file C:/Users/subbu/AppData/Local/Temp/postgresql_installer_d8432abdb1
Just run the installer again as Administrator (Right click the installer to do so).
I'm writing a script that normally will get called by another application (VMware vCenter Server). From that application I trigger a batch file (redirect.bat) and pass a variable which is the powershell script name (TestMe.ps1).
The script is placed on a Windows Server and when I go into the command prompt of the Windows Server and call the redirect script, I see that my PowerShell script runs as expected. However when I trigger it from the app the Powershell script is not run or doesn't produce output. I have confirmation that the redirect.bat is run, because the redirect.bat writes a line in a log file.
The vCenter Server app is running under Local System account. Could it be a permissions error? Is LocalSystem allowed to run Powershell scripts?
I now have no clue if the Powershell script even starts, because it (of course) is not visible in my console when running. The batch file always returns errorlevel = 0.
Any tips on how to insert debugging info in the script that should always give output? Tips on how to troubleshoot this?
redirect.bat:
set POWERSHELL=C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -nologo -noprofile -noninteractive
SET ERRORLEVEL =
echo %1 > G:\DataStoreAlarms\Log\Redirect-batch.txt
start %POWERSHELL% -command "&"%1""
echo Error level: %ERRORLEVEL% >> G:\DataStoreAlarms\Log\Redirect-batch.txt
I call redirect.bat from the command line and from the app like this:
redirect.bat G:\DataStoreAlarms\Scripts\TestGabrie.ps1
TestGabrie.ps1:
$String = "This is a test"
$String | Out-File -FilePath "G:\DataStoreAlarms\Log\Powershell.txt" -Append
Regards
Gabrie
Problem seemed to be the START command:
start %POWERSHELL% -command "&"%1""
After changing it to this, it worked:
%POWERSHELL% -command "&"%1""
Thanks for all your help.
I have the following batch script:
echo %time% >> C:\file.txt
C:\MyProgram\program.exe /arg1 >> C:\file.txt
echo ------- >> C:\file.txt
I have created a service with
sc create ProgramRun type= own start= auto binPath= "cmd /c cd /d c:\MyProgram\ && start script.bat"
After a reboot, in file.txt I have printed the correct time, but without my program ouput. In that program, I have some simple printf
What can I do to write the output to a file without editing the program?
As a Windows Service, your program is being run in the context of the Local System account, which may not have the rights necessary to launch and run your program properly. Try editing the service and setting the Log On credentials to a Windows account that you know can execute your program properly.
Also, while the Windows Service Control Manager (SCM) will happily start your batch file, the outcome reported will always be failure, specifically "Error 1053: The service did not respond to the start or control request in a timely fashion". This is because your batch file can not communicate with the SCM! Have a look at Microsoft's free (and basic) Srvany "service wrapper" to avoid this problem.
I am trying to start windows 7 unattended using the startnet.cmd file. The problem is that when the start setup.exe command is triggered, the setup runs and closes, but cannot reboot because the startnet.cmd is still open. If I put "exit", it starts the setup and exits immediately. Is there a way to check uf the setup ran successfully and then perform an exit?
wpeinit
net use u: \\192.168.2.10\windows
u:
start setup.exe /unattend:\\192.168.2.10\windows\unattend.xml /noreboot
REM ping -n 30 127.0.0.1
REM exit
I think your commands are correct but you explicitly state that setup.exe shall not initiate a reboot after the first phase of the setup procedure has completed.
The black cmd.exe Window will have to remain open during the setup procedure. If it's terminated then Windows PE performs an immediate reboot. Hence your setup.exe process will be terminated. I think your comment using ping to delay the exit very well shows that you have tried to delay terminating the shell process. But as you can't know how long the setup process will take you cannot fill any good value in the delay algorithm.
Although I think you don't need to. You are launching setup.exe using start which detaches the process and returns to the shell immediately. In fact since setup.exe is the last command you run you could also live with the fact that setup.exe is not detached. Either by not using start or by using start /wait
wpeinit
net use u: \\192.168.2.10\windows
u:
setup.exe /unattend:\\192.168.2.10\windows\unattend.xml /noreboot
exit
or
wpeinit
net use u: \\192.168.2.10\windows
u:
start /wait setup.exe /unattend:\\192.168.2.10\windows\unattend.xml /noreboot
exit
Although I think the entire purpose of this would be to return to the shell and perform the exit (which initiates a reboot) command after setup.exe terminates.
As there are no more commands to be executed I suggest letting setup.exe do the reboot itself by removing the /noreboot flag:
wpeinit
net use u: \\192.168.2.10\windows
u:
start setup.exe /unattend:\\192.168.2.10\windows\unattend.xml
This should keep the shell process (cmd.exe) open while setup is running. At the end of the setup process it will initiate a reboot (initiated by setup.exe) and therefore also te