一些收藏的AHK代码块

AHK定义一个函数

Initstu()
{
Sleep 1000 ;休眠1秒
FileDelete, c:\itmanager_tmp\7z.exe ;删除指定文件
}

 

AHK判断语句

if(ituse_bz_stu = stu1)
{
MsgBox, , ,IT账号正常,无需创建 ,2
}
Else
{
}

 

AHK运行BAT命令

Run, Sysdm.cpl
run ,lusrmgr.msc
run ,c:\itmanager_tmp\windows_print\SafeQ Client-2.27\client-win-2.27\Install.exe

 

 

AHK下载一个网络文件

Run, Sysdm.cpl
run ,lusrmgr.msc
run ,c:\itmanager_tmp\windows_print\SafeQ Client-2.27\client-win-2.27\Install.exe

 

 

AHK判断文件是否存在

IfExist, c:\itmanager_tmp\autoactivation.exe
{
MsgBox, 0, ,文件存在,5
}Else{
MsgBox, 0, ,文件不存在 ,5
Return
}

 

 

AHK右下角弹窗提醒

TrayTip 系统激活中,程序可能会有所卡顿,并且屏幕闪烁弹窗,请耐心等待

 

AHK操作注册表

RegWrite, REG_SZ, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon , AutoAdminLogon, 0
RegWrite, REG_SZ, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon , DefaultUserName,
RegWrite, REG_SZ, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon , DefaultPassword,

 

AHK创建最上层提醒条

SplashTextOn,,, 自动配置中,暂停手动操作

 

AHK创建进度条

Progress,M h80,正在下载软件集合, 请等待下载完成
Progress, 1, 正在检查入职指引文件...,,
Gui +Disabled
Progress, 10 , 正在下载office...,,
Progress, 15 , 正在下载Chrome...,,
Progress, 32 , 正在下载PDF阅读器...,,
Progress, 88 , 正在下载7Z解压缩...,,
Progress, 100 , 下载完成...,,
Progress, Off
Gui -Disabled

 

收集bat命令返回值

cmdreturn(command){
shell := ComObjCreate("WScript.Shell")
exec := shell.Exec(ComSpec " /C " command)
return exec.StdOut.ReadAll()
}

 

AHK搜索注册表值

LoopRegAppinstall(nameKey){
initinstall := 2
loop, HKEY_LOCAL_MACHINE , SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, 2, 0
{
IfInString, A_LoopRegName, %nameKey%
{
initinstall := 1
return initinstall
goto LoopRegAppinstall
}
RegRead, Appinstall, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\%A_LoopRegName%, DisplayName
IfInString, Appinstall, %nameKey%
{
initinstall := 1
return initinstall
goto LoopRegAppinstall
}
}
loop, HKEY_LOCAL_MACHINE ,SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall, 2, 0
{
IfInString, A_LoopRegName, %nameKey%
{
initinstall := 1
return initinstall
goto LoopRegAppinstall
}
RegRead, Appinsta64, HKEY_LOCAL_MACHINE, SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\%A_LoopRegName%, DisplayName
IfInString, Appinsta64, %nameKey%
{
initinstall := 1
return initinstall
goto LoopRegAppinstall
}
}
LoopRegAppinstall:
return initinstall
}

 

判断电脑是否联网

If ConnectedToInternet()
Msgbox, 64, WinInet.dll, ONLINE!
else
Msgbox, 48, WinInet.dll, OFFLINE!
Return
ConnectedToInternet(flag=0x40) {
Return DllCall("Wininet.dll\InternetGetConnectedState", "Str", flag,"Int",0)

 

判断电脑是否连通某个网址

URL := "http://www.autohotkey.com"
If InternetCheckConnection(URL)
Msgbox, 64, WinInet.dll [%URL%], Connection Success!
else
Msgbox, 48, WinInet.dll [%URL%], Connection Failed!
Return
; The Function
InternetCheckConnection(Url="",FIFC=1) {
Return DllCall("Wininet.dll\InternetCheckConnectionW", Str,Url, Int,FIFC, Int,0)
}

 

AHK从URL地址上获取值到变量

aaa := URLDownloadToVar(http://it123.cc:8080/chfs/shared/itmanager/autotool/status.txt)
msgbox % aaa
URLDownloadToVar(url,ByRef variable=""){ ; function originally by Maestrith, I think
try ; keep script from breaking if API is down or not reacting
{
hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
hObject.Open("GET",url)
hObject.Send()
variable:=hObject.ResponseText
return variable
}
}
THE END