llarava
asked on
Need assistance with a batch that waits 5 min and then returns a 0 on success
Can someone please help us with a bat script that will wait 5 minutes and then return a 0 on success?
We need to call the script from this registry key : HKLM\Software\Citrix\Machi neIdentity ServiceAge nt\ImagePr eparation\ After
The values are expected to be an executable or script (bat), returning 0 on success
Basically we need to VM to wait 5 minutes before it's shutdown by the system on returning a 0 on success the shutdown will triggered.
Thank you!
We need to call the script from this registry key : HKLM\Software\Citrix\Machi
The values are expected to be an executable or script (bat), returning 0 on success
Basically we need to VM to wait 5 minutes before it's shutdown by the system on returning a 0 on success the shutdown will triggered.
Thank you!
Create a small BAT script that has a one liner to call powershell and use it's delay command, like:
»bp
powershell -command "start-sleep -s 300"
»bp
ASKER
Hello, thanks for the reply. No need to ping or do anything special just wait 5 min then after that time return a 0 on success. I was told that if the script returns 0 on success then system will proceed with the shutdown.
ping waits 1 second between two pings... ping 127.0.0.1 if ping localhost aka ping your own system. ==> will always work.
301 Intervals of 1 second = 5 minutes.... So you don't need to PING something, you need the 300 intervals of 1 second. ( that is define 301 ICMP messages with 1 second in between).
See above script... it will wait 5 minutes and exit 0 as requested.
Alternatively the Powersehll above may work for you if you have powershell on your system.
301 Intervals of 1 second = 5 minutes.... So you don't need to PING something, you need the 300 intervals of 1 second. ( that is define 301 ICMP messages with 1 second in between).
See above script... it will wait 5 minutes and exit 0 as requested.
Alternatively the Powersehll above may work for you if you have powershell on your system.
The powershell approach isn't "anything special", the problem is that the standard BAT script language didn't have a command to do a delay.
In newer versions of Windows, like Windows 10, you can do the below. So try that on the computer involved and see if it exists/works there.
»bp
In newer versions of Windows, like Windows 10, you can do the below. So try that on the computer involved and see if it exists/works there.
timeout /t 300 /nobreak>nul
»bp
ASKER
Ok I see. Would the powershell be returning a 0 on exit?
By default when a BAT script ends it will return 0.
»bp
»bp
ASKER
Hi Noci - to your code above can we add something to create a txt log file somewhere in the root drive. the exit 0 is not doing what the vendor is saying should do and I need to know that the script is being executed. by adding the creation of a log I would be able to know if at least the script is executed. thank you!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Another trick can be to use the delay between ping attempts.
So: ping 127.0.0.1 -n 10
Will sleep 9 seconds. (9 intervals between attempts).
So ping 127.0.0.1 -n 301 >nul
would wait 5 minutes.
The next batch file would do the trick:
Open in new window