Use a script to call the system shutdown dialog box

Source: Internet
Author: User
Previously there was a dialog box showing how to call a system shutdown using command lines: http://blog.csdn.net/scz123/archive/2005/09/30/492991.aspx
Method: Start/run: rundll32.exe shell32.dll #60

However, the above method will have a problem, XP cannot use this method to shut down (thanks to the netizen Mu ye for discovering this problem ). The cause may be: Normally, the host dialog box is called by assumer.exe. commands cannot be triggered when rundll32 is directly used.

Even though you can use assumer.exe to call it, we can try to use a script to implement it. Implementation principle:

  1. Activate assumer.exe
  2. Press Alt + F4

Write the following vbs script (Save the following content as shutdown. vbs): dim ob1_mi, wsh
Dim colprocesses, objprocess
PID = 0
Set ob1_mi = GetObject ("winmgmts: {impersonationlevel = impersonate} //./root/cimv2 ")
Set colprocesses = ob1_mi. execquery ("select * From win32_process "&_
"Where namepolic'assumer.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 runtime environment is XP SP2
Other environments can also work normally. However, systems with multiple cmd.exe processes may not work normally, such as multi-user environments 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.