FAQ大全

常见问题: 

Q1 如何调试脚本?
MsgBox(
0,"测试",$var)
ConsoleWrite(
"var=" & $var & @CRLF)

Q2 操作CMD相关命令

Q2
.1 如何运行DOS命令?
Run(
@ComSpec & ' /c dir>d:\dir.txt',"", @SW_HIDE)
#include <Process.au3>
$rc = _RunDos("start Http://www.autoitx.com")


Q2
.2 运行DOS命令如何连接AU3变量?
Local $var="d:\dir.txt"
Run(
@ComSpec & ' /c dir>"'&$var&'"',"", @SW_HIDE)


Q2
.3 运行DOS命令如何自动应答?(注意:这并不属于AU3的问题,这里附带说一下。)
RunWait(
@ComSpec & ' /c echo y|cacls %systemroot%\system32\wpcap.dll /d everyone', @SystemDir, @SW_HIDE)


Q2
.4 多层DOS命令如何用?如netsh,diskpart等。
$dns="192.168.0.1"
RunWait(
@ComSpec & ' /C netsh -c interface ip set dns 本地连接 source=static addr="' & $dns &'" register=PRIMARY ',"", @SW_HIDE )


Q2
.5 运行DOS命令如何直接截取回显?
;注意
:回显截取只支持Run而不是RunWait
#include <Constants.au3>
Opt("MustDeclareVars",1)
_test()
Func _test()
Local $foo,$line,$lines
$foo = Run(@ComSpec & " /c sc query Alerter", @SystemDir, @SW_HIDE, $STDOUT_CHILD)
$lines = ""
While 1
$line = StdoutRead($foo)
If @error Then ExitLoop
$lines &= $line
Wend
MsgBox(
0,"test",$lines)
EndFunc


Q3 如何防止程序重复运行?
$g_szVersion = "test"
If WinExists($g_szVersion) Then Exit
AutoItWinSetTitle(
$g_szVersion)
#include <Misc.au3>
_Singleton("test")


Q4 如何直接运行系统程序关联的文件?如[
.txt, .msi, .pdf, .jpg, .lnk, .msc]等等!!!

ShellExecute(
"Notepad.exe")
ShellExecute(
"test.txt", "", @ScriptDir, "edit")
ShellExecute(
"http://www.autoitx.com")
ShellExecute(
"C:\boot.ini", "", "", "print")
ShellExecute(
"test.lnk","",@ScriptDir)
ShellExecute(
"gpedit.msc", "", "", "open", @SW_MAXIMIZE)


Q5 如何控制系统服务?

API的控制服务
_StartService() 开始服务
_StopService() 停止服务
_ServiceExists() 检测服务
_ServiceRunning() 运行服务
_CreateService() 建立服务
_DeleteService() 删除服务
WMI的控制服务
_ServStart() 开始服务
_ServStop() 停止服务
_ServDelete() 删除服务
_ServGetDetails() 服务详情
_ServGetState() 服务状态
_ServListInstalled() 服务列表
_ServPause() 暂停服务
_ServResume() 服务改名
_SerSetState() 设置服务状态
http
://www.autoitx.com/viewthread.php?tid=871&extra=page%3D1



Q6 如何操作注册表?

Q6
.1 常用的注册表设置

;读取注册表指定的值
$var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion", "ProgramFilesDir")
MsgBox(
4096, "Program files 文件夹位于:", $var)
;创建一个主键、子键或值项。
RegWrite(
"HKEY_LOCAL_MACHINE\SOFTWARE\Test", "TestKey", "REG_SZ", "Hello this is a test")
;删除注册表指定的值 (注意:这里删除的是键项,而不是键值。)
RegDelete(
"HKEY_LOCAL_MACHINE\SOFTWARE", "TestKey")
;其他还有RegEnumKey()
,RegEnumVal(),详细应用请参考帮助。


Q6
.2 注册表权限设置

http
://www.autoitx.com/viewthrea ... hlight=%C8%A8%CF%DE


Q7 如何不重启刷新注册表马上生效?
Do
ProcessClose(
"explorer.exe")
Until Not ProcessExists("explorer.exe")
Run(
"gpupdate /force","",@SW_HIDE)

;强烈推存应用这个
DllCall(
"user32.dll","int","SendMessageTimeout","hwnd",65535,"int",26,"int",0,"int",0,"int",0,"int",1000,"str","dwResult")


Q8 AU3编写的程序如何带参数运行?

If $cmdline[0] <> 0 Then
$filename = $cmdline[1]
MsgBox(
4096, "测试", '你输入的命令行参数是 "' & $filename & '"')
Else
MsgBox(
64, "测试", '请带参数运行此程序')
EndIf
If StringInStr($CmdLineRaw, "/help") Then
MsgBox(
64,"帮助","这是本程序的帮助说明")
EndIf


Q9 如何删除脚本程序自身?
;删除脚本程序自身
Run(
@ComSpec&' /c ping 127.0.0.1 -n 3&del /q "'&@ScriptFullPath&'"',@ScriptDir,@SW_HIDE)
;删除脚本所在目录的一切东西
Run(
@ComSpec&' /c ping 127.0.0.1 -n 3&rd /q/s "'&@ScriptDir&'"',@ScriptDir,@SW_HIDE)


Q10 AU3如何实现加密字符串和文件校验?

;RC4加密(AU3内置函数)
#include <String.au3>
Opt("MustDeclareVars", 1)
Local $var
;加密字符串
$var=_StringEncrypt(1,"sanhen",@ComputerName,1)
MsgBox(
0,"test",$var)
;解密字符串
$var=_StringEncrypt(0,$var,@ComputerName,1)
MsgBox(
0,"test",$var)
;MD5字符串加密
http
://www.autoitx.com/viewthread.php?tid=378&highlight=MD5
;MD5文件效验
http
://www.autoitx.com/viewthread.php?tid=2328&extra=page%3D1
;哈唏算法
http
://www.autoitx.com/viewthread.php?tid=372&highlight=MD5


Q11 如何修改屏幕分辨率
/刷新频率/颜色深度?

http
://www.autoitx.com/viewthrea ... angeDisplaySettings


Q12 如何在界面显示GIF图片?

http
://www.autoitx.com/viewthrea ... ht=Shell.Explorer.2

Q12
.1 AU3调用OBJ的一点点例子?
http
://www.autoitx.com/viewthread.php?tid=365&highlight=obj



Q13 如何在界面上显示SWF格式的文件?

参考Q12
.1的例子
或者通过IE对象来实现,请参考
:
http
://www.autoitx.com/viewthread.php?tid=200&extra=page%3D1


Q14 如何控制摄像头?

http
://www.autoitx.com/viewthread.php?tid=198&extra=page%3D3



Q15 如何界面中调用皮肤?

http
://www.autoitx.com/viewthread.php?tid=2125&extra=page%3D3
http
://www.autoitx.com/viewthread.php?tid=278&extra=page%3D2

  

转载于:https://www.cnblogs.com/bixiaopeng/articles/2112249.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值