Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use script to call the shutdown dialog box of the system

Shulou Source: shulou.com Published: 2022-06-03 06:06:00 11月16日 Update

This article mainly shows you "how to use script to call the shutdown dialog box of the system", the content is easy to understand, well-organized, hope to help you solve your doubts, the following let the editor lead you to study and learn the article "how to use script to call the shutdown dialog box of the system".

Specific method: start / run:

The copy code is as follows:

Rundll32.exe shell32.dll # 60

However, there will be a problem with the above method, which can not be used to shut down the computer normally under XP (thanks to netizens Mu Ye for finding this problem). The reason for the problem may be that under normal circumstances, the shutdown dialog box is called by explorer.exe, and the relevant command cannot be triggered when it is called directly with rundll32.

Now that we can use the explorer.exe call, we can try to do it using a script. The principle of implementation:

Activate explorer.exe

Press ALT+F4

Write the VBS script as follows (save the following as shutdown.vbs):

The copy code is as follows:

Dim objWMI,wsh

Dim colProcesses,objProcess

Pid=0

Set objWMI = GetObject ("winmgmts: {impersonationLevel=impersonate} /. / root/cimv2")

Set colProcesses = objWMI.ExecQuery ("SELECT * FROM Win32_Process" & _

"WHERE Name='explorer.exe'")

For Each objProcess In colProcesses

Pid = objProcess.ProcessId

Next

Set wsh = WScript.CreateObject ("WScript.Shell")

Wsh.AppActivate pid

Wsh.sendKeys "{F4}"

The above script running environment is: XP SP2

Other environments may also work, but systems with multiple explorer.exe processes may not work properly, such as in a multi-user environment with remote terminal services.

The above is all the contents of the article "how to use script to call the shutdown dialog box of the system". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Script dialog box system dialogue code content method environment article question study work help run reason principle command multiple situation easy to understand Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Apple Linux Redmi Xiaomi