Use script to call the system's Shutdown dialog box to implement code _vbs

Source: Internet
Author: User
There used to be a shutdown dialog box that describes how to invoke the system using the command line:
Specific method: Start/Run:
Copy Code code as follows:

rundll32.exe Shell32.dll #60

However, the above method will have a problem, XP can not normally use this method for shutdown (thanks to netizens mu ye found the problem). The problem may be that, under normal circumstances, the Shutdown dialog box has a Explorer.exe call, and the command cannot be triggered directly using the Rundll32 call.

Now that we can use the Explorer.exe call, we can try to implement it using a script. Implementation principle:

Activate Explorer.exe
Press Alt+f4
Write the VBS script as follows (save the following as Shutdown.vbs):
Copy Code code 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 script running environment is: XP SP2
Other environments may also work correctly, but for systems with multiple Explorer.exe processes, it may not work properly, as in a multiuser environment with remote Terminal Services.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.