Shutdown Windows, QM, macro, etc

Syntax

shutdown action [flags] [computer|command|threadname] [wait|threadid] [message]

 

Parts

action - one of values below.

0 Log off Windows.
1 Shut down Windows.
2 Restart Windows (reboot).
3 Shut down and power off.
4 Hibernate.
5 Suspend (sleep, standby).
6 Lock computer, or switch user (if fast switching is enabled).
   
-1 Exit Quick Macros. In exe - exit the exe process (QM 2.2.0).
-2 Restart Quick Macros.
-3 Hide Quick Macros.
-4 Show Quick Macros.
-5 Reload current macro list file.
-6 End currently running macro, or specified thread (running function, macro or menu/toolbar item). Read more below.
-7 Softly end current thread. Read more below.

flags - one of values below. Depends on action. With other actions should be 0 or omitted. Default: 0.

action flags  
0 - 5 0 Applications are allowed to cancel the operation. For example, if an application shows a "Save?" message box, you can click Cancel to stop the shutdown.
0 - 5 1 Does not allow to cancel. When used with actions 0 - 3, forces all applications to terminate, which can cause them to lose data. This value also should be used if the computer is locked.
0 - 3 2 Forces to terminate only hung applications.
     
-6 0 QM 2.2.0. threadid is thread handle. See remarks.
-6 1 QM 2.2.0. threadid is thread id.
-6 2 QM 2.2.0. threadid is thread unique id.
     
-7 1 End thread immediately. See remarks.

 

The following three parts can be used with action 1 and 2:

 

computer - the name of the computer to shut down. Default: "" - local computer. To shut down a remote computer, your account must have administrator rights on the remote computer.

wait - number of seconds to wait. A shutdown dialog box is displayed. Default: 0 (no dialog box).

message - text to display in the shutdown dialog. Default: "".

 

command - QM command line. Used with action -2 (restart QM). For example, it can be "V" to restart visible.

threadname - QM item name (in quotes, or string variable) or id. Used with action -6 (end threads). See remarks.

threadid (QM 2.2.0) - thread handle, id or unique id (depends on flags). Used with action -6 (end threads). See remarks.

 

Remarks

This command is asynchronous. It tells QM to perform the specified action but does not wait until the action is finished. With many actions, it should be the last command in the macro.

 

Use action -6 to end currently running macro or other thread. If threadname and threadid are not used (omitted, 0 or ""), ends currently running macro (not current thread). If only threadname used, ends all threads (running instances) of it. If threadid used, ends only that instance (threadname, if used, also must match). If the specified thread (or a macro) is not running, error is not generated. This action cannot end special threads. It also cannot close toolbars (use clo instead). This action should not be used to end current thread (instead use ret, end, shutdown -7, etc).

 

Thread handle is returned by mac. Thread handle, id and unique id can retrieved using EnumQmThreads or GetQmThreadInfo. Thread handle cannot be retrieved by GetCurrentThread or DuplicateHandle. A thread handle identifies thread only while it is running. Later (after > 3 seconds) the same value can be reused (assigned to a new thread). Thread id also can be reused. Unique thread id is not reused.

 

Use action -7 to end current thread when you don't know if it has windows. Differently than end, it closes all thread's windows, giving them chance to free allocated memory, etc. When shutdown returns, windows are already destroyed. If flags is 1, ends thread immediately after destroying windows. If 0 - gives 0.5 s (or wait ms, if used) to finish naturally. This action for example can be used in an universal function that doesn't know how to properly end current thread.

 

Depending on operating system, hardware and security settings, some features may not work.

 

Examples

shutdown 3 ;;shut down; allow to cancel
shutdown 2 1 ;;reboot; don't allow to cancel
shutdown 1 0 "" 30 "QM" ;;shut down after 30 s
shutdown -1 ;;exit QM
shutdown -6 ;;end currently running macro
shutdown -6 0 "Func" ;;end all threads (running instances) of function Func