Use batch processing to restart the computer

Source: Internet
Author: User
Guidance:

Today, I saw suichuanxian posted a post in the newsgroup.OXfUmTgWFHA.2256@TK2MSFTNGP14.phx.gbl), The original post is as follows: Q: How can I simulate a carriage return event in batch processing? That is to say, I want to use batch processing to replace people.
Press ENTER or space key? Because when some of my programs are closed, the system prompts whether or not to end.
After "yes", the program is closed,SystemOtherwise, the system will not be able to complete the restart.
The restart action. Thank you, prawns.
A: use NotePad to save the following content as a bat file, for example, reboot. bat. When you run it, it will automatically restart
.

@ Echo off
Setlocal
CD/d % Temp %
Echo [version]> Reboot. inf
Set INF = installhinfsection defaultinstall
Echo Signature = $ Chicago $> Reboot. inf
Echo [defainstall install]> Reboot. inf
Rundll32 setupapi, % INF % 1% TEMP % eboot. inf
Del reboot. inf
Haha, seeing this post reminds me of the times when I used inf to unlock Regedit. Let's talk about it later.ScriptThe principle is good. In fact, the key sentence used here is rundll32.exe setupapi. dll, installhinfsection defaultinstall 1% TEMP % eboot. INF. The format here is rundll32.exe setupapi. dll, installhinfsectionFor usage of Windows rundll and rundll32 interface, seeHttp://support.microsoft.com/kb/164787/zh-cnBefore, I wrote an example of how to use rundll32.Http://gnaw0725.blogdriver.com/gnaw0725/259894.htmlSetupapi loads the installhinfsection function here. For other export parts of this API, you can easily find them using exclusive or compilation tools. (BTW: In WINXP and later versions, the setupapi operation will generate a setupapi. log, which will record the devices, servicepack, and Hotfix installed in the current environment. For details, seeHttp://www.microsoft.com/whdc/driver/install/setupapilog.mspx) <Section> Use it with INF.InstallhinfsectionFor other features installed by INF, see INF file processing functionsHttp://msdn.microsoft.com/library/default.asp? Url =/library/en-US/install/hh/install/SetupAPI_95233d19-2970-409d-8b44-de661cbf68ae.xml.asp<Mode> Is a combination value. Its combination sequence is as follows:

Value Description
0 System provides INF
128 Set the default path of the installation file to the current INF path. This is a typical setting.
+ 0 Do not restart the computer
+ 1 Restart the computer in all cases
+ 2 If you need to restart, always ask the user
+ 3 Restart the computer if necessary without the user's permission
+ 4 If you need to restart the computer, submit a user license before it starts.

<Path> Specify the path of the INF file. The absolute path is used here. This method applies to almost all client operating systems, but <Mode> Generally, it is not recommended to assign a value of 1. The value should be 128 + 1 = 129. Otherwise, the execution may fail in some environments and will not be restarted. Now that we can restart the system, we can also use vbs to do it. It is enough to use only one sentence for Createobject ("wscript. shell "). sendkeys "^ {ESC} ur", but this is generally not recommended, because the WINXP login method has a welcome screen, or a non-Welcome Screen login, it is useless for the latter to write like this, write Createobject ("wscript. shell "). sendkeys "^ {ESC} U {down }~ "The trick here is sendkeys. For details about sendkeys usage, referHttp://msdn.microsoft.com/library/chs/default.asp? Url =/library/CHS/cpref/html/frlrfsystemwindowsformssendkeysclasssendtopic. asp. I have written a similar example before.Http://gnaw0725.blogdriver.com/gnaw0725/358142.htmlHowever, because Windows registers the key value for the memory of the last shutdown status, the order of the keys may not be the same, unless you customize the script for a specific environment, generally, it is recommended that strcomputer = "."
Set ob1_miservice = GetObject ("winmgmts :"_
& "{Impersonationlevel = impersonate, (shutdown )}! "&_
Strcomputer & "ootcimv2 ")

Set coloperatingsystems = obw.miservice. execquery _
("Select * From win32_operatingsystem ")

For each objoperatingsystem in coloperatingsystems
Objoperatingsystem. Reboot ()
Next

This article is transferred from
Http://gnaw0725.blogbus.com/logs/4888543.html

Related Article

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.