Welcome to OCS Inventory NG community support, where you can ask questions and receive answers from other members of the community.

Please ask questions only in English or French.

Release 2.12.3 available

The official documentation can be found on https://wiki.ocsinventory-ng.org. Read it before asking your question.

exit code not working in my package

Hello,

I'm trying to deploy a package zipped with these 2 files:

1. SETUP.cmd

echo 'start of the installation' >>  C:\Logs\result.txt
START "INSTALLATION THROUGH OCS" /wait MyProgram.exe /S
 
echo %errorlevel% >> C:\Logs\result.txt
echo 'before reboot' >> C:\Logs\result.txt
shutdown.exe /r /f
echo 'after reboot' >> C:\Logs\result.txt
exit /b %errorlevel%

 

2. MyProgram.exe. It's a executable created with NSIS.

When I always deploy the SETUP.cmd, it does not reach this part of the code:

echo %errorlevel% >> C:\Logs\result.txt
echo 'before reboot' >> C:\Logs\result.txt
shutdown.exe /r /f
echo 'after reboot' >> C:\Logs\result.txt
exit /b %errorlevel%

After some hours, the package's deployment ends as error due to the timeout. What am I doing wrong? When I launch the SETUP.cmd manually, it works perfectly fine. It does all of the steps from the code.

Thanks in advance for any tip/advice

in OCS Inventory NG agent for Windows by (230 points)
edited by

5 Answers

+1 vote
packages are only executed during a running pc. After reboot the package isn't located on the pc anymore.

The after installation part in your test runs before reboot in your test .. you just have a log file which tells you the oposite.

If you really want to resume a batch script .. you have to copy the script with an installation script to a folder which survives the reboot .. and then you have to manage some "magic" with registry keys like described here

https://superuser.com/questions/1215040/resume-batch-script-after-reboot
Another way is to create a task which runs once after reboot.
Kind regards sokatra
by (24.4k points)
edited by
0 votes

Hello Sokatra,

Thank you for your tips. I think I didn't explain myself correctly.

I just want to do a reboot after the executable's execution and return the code to the OCS Server.

This part of the code never runs even if the .EXE has finished the installation:

echo %errorlevel% >> C:\Logs\result.txt
echo 'before reboot' >> C:\Logs\result.txt
shutdown.exe /r /f
echo 'after reboot' >> C:\Logs\result.txtexit /b errorlevel% 

If I launch the SETUP.cmd MANUALLY everything happens. Even the reboot. 

If I do an OCS Deployment, it only launchs the .EXE and nothing else. It doesn't even reach the echo with the errorlevel.

The executable is like 60mbs and takes like half minute to be installed. Am I doing something wrong? I have tried many tips/fixes but nothing worked out.

This command does a reboot in 30s: shutdown /r /f. Being so, I should be able to log the before/after reboot and the error code. But as I said, everything below the execution of the .EXE doesn't happen through an OCS deployment.

Kinds regards,

Josh

by (230 points)
0 votes
Everything after the 'shutdown' will be never executed !

When the command is launched, a warning windows appear, and, after 30 seconds, the pc start to reboot. So some command could be executed but not really after reboot, just inside the delay.

It's quite dangerous to restart a computer (inside a package deployement):

- first, maybe the user is working and not happy to see its computer restart without asking him,

 - second, if the job had error, maybe the computer don't restart correctly.

It's better, like windows update, to run something and wait the user restart the computer when he will be ready.

Look at https://ss64.com/nt/shutdown.html

You can see the effect of /f : I'm not sure the user will be happy with this !

-------

Or maybe NSIS has problem with 'start /wait', see https://googlethatforyou.com?q=nsis%20installer%20start%20%2Fwait
by (20.1k points)
edited by
0 votes

Hello jacquesh,

Thank you for your advices and the information. There's no need to worry about the user. We're doing the reboot because it's imperative in our environment. There's no user doing anything in the system meanwhile the deployment is being done.

Kind regards,

Josh

by (230 points)
edited by
0 votes
as jacquesh explained .. the after section will not be executed after the real reboot.

If you really want to reboot with a standard reboot command the i recommend to use the

shutdown -s -t <number in seconds>

command. So try to shutdown in 3 minutes .. so ocs-inventory has a chance to report the success before the reboot

perhaps try to use the start command before the shutdown command

start shutdown.exe /r /f

But there are much more possibilities to warn the user about the reboot.

shutdown -r -t 300 -c "This system is shutting down in 300 seconds.."
With the help of some scripts you can even do much more.
For example i silently deploy a package with ocs-inventory.
Inside of my script i create a message for the user where he gets warned about something (reboot, and so forth)

Kind regards

Sokatra
by (24.4k points)
 
Powered by Question2Answer
...