批处理转换问题
@echo offsetlocal
cd/d %temp%
echo > reboot.inf
set inf=InstallHinfSection DefaultInstall
echo signature=$chicago$ >> reboot.inf
echo >> reboot.inf
rundll32 setupapi,%inf% 1 %temp%/reboot.inf
del reboot.inf
这是一段重启机器的批处理,我是这样转换的,
FileOpen(@TempDir & "\reboot.inf", 2)
IniWriteSection(@TempDir & "\reboot.inf", "version", "signature=$chicago$")
IniWriteSection(@TempDir & "\reboot.inf", "defaultinstall", "")
RunWait(@ComSpec & " /c " & "set inf=InstallHinfSection DefaultInstall")
RunWait(@ComSpec & " /c " & "rundll32 setupapi,%inf% 1 %temp%/reboot.inf")
我直接将au3程序在temp目录执行也不行。很是费解。报错如下。
Shutdown(6) 回复 1# bhffhzh
本论坛有lixiaolong原创的bat转au3工具请查找一下很好用 转过来也不行。貌似
set inf=InstallHinfSection DefaultInstall
rundll32 setupapi,%inf% 1 %temp%/reboot.inf
这两行命令只能用批处理才能用。而转成了au3就用不了。 RunWait(@ComSpec & " /c " & "cd/d %temp% && set inf=InstallHinfSection DefaultInstall && rundll32 setupapi,%inf% 1 %temp%/reboot.inf")
试试? 本帖最后由 229989799 于 2017-3-5 12:01 编辑
Shutdown ( 2 );重启
;关机代码可以是下面的值:
; $SD_LOGOFF (0) = Logoff (注销)
; $SD_SHUTDOWN (1) = Shutdown (关机)
; $SD_REBOOT (2) = Reboot (重启)
;$SD_FORCE (4) = Force (强制关机)
;$SD_POWERDOWN (8) = Power down (关闭电源)
; $SD_FORCEHUNG (16) = Force if hung (系统挂起, 强制关机)
;$SD_STANDBY (32) = Standby (待机)
; $SD_HIBERNATE (64) = Hibernate (休眠)
;常量定义文件" AutoItConstants.au3
;所需的值应该由 BitOR() 组合. 例如关机并关闭电源, 则使用代码 BitOR($SD_SHUTDOWN, $SD_POWERDOWN).
;若设置了其它代码, 则待机或休眠将被忽略. 回复 5# 帆船
同样报丢失条目的错误 再顶问问吧,
FileChangeDir(@TempDir)
FileOpen("reboot.inf", 2)
IniWriteSection("reboot.inf", "version", "signature=$chicago$")
IniWriteSection("reboot.inf", "defaultinstall", "")
FileWrite("reboot.inf", @CRLF)
EnvSet("inf", "InstallHinfSection DefaultInstall")
Run("rundll32 setupapi,%inf% 1 reboot.inf")
回复 9# Duvet
同样报丢失条目的错误 最後一行改為
Run(@ComSpec & " /c rundll32 setupapi,%inf% 1 %temp%\reboot.inf")
——rundos("shutdown -r -t 0"){:face (303):} 本帖最后由 bhffhzh 于 2017-3-6 08:15 编辑
看来这貌似简单的问题真不好解决,
顺便共享一下更牛重启的api代码,此代码在前人基础上,加上了正常重启。Func ExitWindowsEx($flags)
DllCall("ntdll.dll", "int", "RtlAdjustPrivilege", "long", 0x13, "int", True, "int", False, "ptr", DllStructGetPtr(DllStructCreate("int 0"))) ;此处为夺权
DllCall("user32.dll", "int", "ExitWindowsEx", "int", $flags, "int", 0) ;正常重启 代码表示:关机1重启2
;DllCall("ntdll.dll", "int", "NtShutdownSystem", "int", $flags);强制重启代码表示:重启1关机2
EndFunc ;==>ExitWindowsEx FileOpen(@TempDir & "\reboot.inf", 2)
IniWriteSection(@TempDir & "\reboot.inf", "version", "signature=$chicago$")
IniWriteSection(@TempDir & "\reboot.inf", "defaultinstall", "")
EnvSet("inf", "InstallHinfSection DefaultInstall")
RunWait(@ComSpec & " /c " & "rundll32 setupapi,%inf% 1 %temp%/reboot.inf") 学习学习学习
页:
[1]
2