Shutdown Windows, QM, macro, etc

Syntax

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

 

Parameters

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.
   
-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 QM file.
-6

End currently running macro, or specified thread. Read more below.

-7 Softly end current thread. Read more below.

Actions -2, -3, -4 and -5 not available in exe. RT error if used.

 

flags - see 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 1-8 Read in Remarks.
-7 1 End thread immediately. Read more in Remarks.

 

These three parameters are used with action 1 and 2:

 

computer - computer name. Default: "" - this computer.

wait_ - time (seconds) to wait. A shutdown dialog box or other notification 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 or id. Used with action -6 (end threads). Read more in Remarks.

threadid (QM 2.2.0) - thread handle, id or unique id (depends on flags). Used with action -6 (end threads). Read more in 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 a thread. Read more.

QM 2.3.3. You can instead use function EndThread. It works like shutdown -6.

 

flags:

0 QM 2.2.0. threadid is thread handle. Read more below.
1 QM 2.2.0. threadid is thread id.
2 QM 2.2.0. threadid is thread unique id.
4 QM 2.3.2. If a function has "End thread" trigger for the thread, run it.
8 QM 2.3.2. Synchronous. Wait until the thread is ended.

 

If threadname and threadid are not used (omitted, 0 or ""), ends the currently running macro. If only threadname used, ends all threads (all running instances of the function). If threadid used, ends only that instance (threadname, if used, also must match). Not error if the thread is not running. Cannot end special threads. Cannot close toolbars (use clo instead). Don't use this to end current thread; instead use ret, end, shutdown -7, etc.

 

To get thread handle, id or unique id, use mac, EnumQmThreads or GetQmThreadInfo. Don't use 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.

 

If sub-function, threadname can be like "ParentName:SubName".

 

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 a 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