bhffhzh 发表于 2017-3-5 00:06:22

批处理转换问题

@echo off
setlocal
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目录执行也不行。很是费解。报错如下。

lxwlxwayy 发表于 2017-3-5 08:45:41

Shutdown(6)

zpmc123 发表于 2017-3-5 10:00:21

回复 1# bhffhzh

本论坛有lixiaolong原创的bat转au3工具请查找一下很好用

bhffhzh 发表于 2017-3-5 11:03:44

转过来也不行。貌似
set inf=InstallHinfSection DefaultInstall
rundll32 setupapi,%inf% 1 %temp%/reboot.inf

这两行命令只能用批处理才能用。而转成了au3就用不了。

帆船 发表于 2017-3-5 11:42:41

RunWait(@ComSpec & " /c " & "cd/d %temp% && set inf=InstallHinfSection DefaultInstall && rundll32 setupapi,%inf% 1 %temp%/reboot.inf")
试试?

229989799 发表于 2017-3-5 12:00:21

本帖最后由 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).

;若设置了其它代码, 则待机或休眠将被忽略.

bhffhzh 发表于 2017-3-5 12:02:27

回复 5# 帆船


    同样报丢失条目的错误

bhffhzh 发表于 2017-3-5 20:33:45

再顶问问吧,

Duvet 发表于 2017-3-5 21:31:55


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")

bhffhzh 发表于 2017-3-5 21:43:18

回复 9# Duvet


       同样报丢失条目的错误

Duvet 发表于 2017-3-5 22:14:23

最後一行改為

Run(@ComSpec & " /c rundll32 setupapi,%inf% 1 %temp%\reboot.inf")

Huiseyu 发表于 2017-3-5 22:51:02

——rundos("shutdown -r -t 0"){:face (303):}

bhffhzh 发表于 2017-3-6 08:12:59

本帖最后由 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

1361739590 发表于 2017-3-6 10:38:14

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")

zhouzc88 发表于 2017-3-10 12:01:23

学习学习学习
页: [1] 2
查看完整版本: 批处理转换问题