找回密码
 加入
搜索
查看: 4977|回复: 15

[AU3基础] 批处理转换问题

 火.. [复制链接]
发表于 2017-3-5 00:06:22 | 显示全部楼层 |阅读模式
@echo off
setlocal
cd/d %temp%
echo [version] > reboot.inf
set inf=InstallHinfSection DefaultInstall
echo signature=$chicago$ >> reboot.inf
echo [defaultinstall] >> 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目录执行也不行。很是费解。报错如下。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2017-3-5 08:45:41 | 显示全部楼层
Shutdown(6)
发表于 2017-3-5 10:00:21 | 显示全部楼层
回复 1# bhffhzh

本论坛有lixiaolong原创的bat转au3工具请查找一下很好用
 楼主| 发表于 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")
试试?
发表于 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).

;若设置了其它代码, 则待机或休眠将被忽略.
 楼主| 发表于 2017-3-5 12:02:27 | 显示全部楼层
回复 5# 帆船


    同样报丢失条目的错误
 楼主| 发表于 2017-3-5 20:33:45 | 显示全部楼层
再顶问问吧,
发表于 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")
 楼主| 发表于 2017-3-5 21:43:18 | 显示全部楼层
回复 9# Duvet


       同样报丢失条目的错误
发表于 2017-3-5 22:14:23 | 显示全部楼层
最後一行改為

Run(@ComSpec & " /c rundll32 setupapi,%inf% 1 %temp%\reboot.inf")
发表于 2017-3-5 22:51:02 | 显示全部楼层
——rundos("shutdown -r -t 0")
 楼主| 发表于 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
发表于 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")
发表于 2017-3-10 12:01:23 | 显示全部楼层
学习学习学习
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-27 00:07 , Processed in 0.083832 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表