Waits or checks for receipt of a service control code.
SvcWaitForCmd(timeout)
(i) timeout timeout flag (in milliseconds)
(i) control codes The following control codes may be returned:
Value |
Control code |
Meaning |
-1 |
|
Script not running as a service |
0 |
|
Timeout occurred or no codes to process |
1 |
SERVICE_CONTROL_STOP |
Requests the service to stop |
2 |
SERVICE_CONTROL_PAUSE |
Requests the service to pause |
3 |
SERVICE_CONTROL_CONTINUE |
Requests the paused service to resume |
5 |
SERVICE_CONTROL_SHUTDOWN |
Requests the service to perform cleanup tasks, because the system is shutting down |
12 |
SERVICE_CONTROL_HARDWAREPROFILECHANGE |
Computer's hardware profile has changed. |
13 |
SERVICE_CONTROL_POWEREVENT |
Power status has changed. |
14 |
SERVICE_CONTROL_SESSIONCHANGE |
Session status has changed ( requires XP/2003 or newer. ) |
15 |
SERVICE_CONTROL_PRESHUTDOWN |
System will be shutting down ( requires Vista/2008 or newer. ) |
128-255 |
|
User-defined control code |
32768 |
SERVICE_CONTROL_LOGOFF |
Logoff notification |
If any control codes have been received but not yet processed (using this function), this function immediately returns the value of that control code. WinBatch maintains a list of up to 16 unprocessed control codes that have been received, and this function returns the first (oldest) one in the list, then clears that code from the list, so the next time this function is called it will return the next control code in the list, if any.
If there are no unprocessed control codes in the list, the behavior depends on the value specified by "timeout". If "timeout" is -1, the function will wait until a control code is received, and then return its value. If "timeout" is zero, the function will immediately return a value of 0. If "timeout" is neither zero nor -1, then the function will wait until the timeout expires or a control code is recieved, whichever somes first.
The SERVICE_CONTROL_INTERROGATE message which is used by the Service Control Manager is handled automatically by the WinBatch service processing. It uses a best guess approach and considers information provided by the script via the SvcSetState function.
Once the SERVICE_CONTROL_SHUTDOWN command has been received, there is approximately only 20 seconds to process.