正好我最近写了个工具,源码给你看看吧
#NoTrayIcon
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_icon=E:\Program Files\ChinaNetSn\res\ico\large1.ico
#AutoIt3Wrapper_outfile=F:\开机自动登入工具.exe
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_Comment=由玄亟天制作
#AutoIt3Wrapper_Res_Fileversion=2.5.0.0
#AutoIt3Wrapper_Res_LegalCopyright=版权所有@玄亟天
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
Dim $exepath,$username,$password,$hint_text,$exe_name
$exepath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\开机自动登入工具\闪讯","exepath");路径
$username = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\开机自动登入工具\闪讯","username");账号
$password = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\开机自动登入工具\闪讯","password");密码
$exe_name = StringMid($exepath,StringInStr($exepath,"\",1,-1)+1)
$workpath = StringLeft($exepath,StringInStr($exepath,"\",1,-1))
If $CmdLine[0] > 0 Then
If $CmdLine[1]="-run" Then _Run($exepath,$username,$password,$exe_name,$workpath)
Else
#Region ### START Koda GUI section ### Form=e:\program files\autoit3\我的脚本\闪讯账号管理系统窗口.kxf
$main = GUICreate("闪讯开机自动登入工具 by 玄亟天", 410, 242, -1, -1,-1,$WS_EX_ACCEPTFILES)
GUISetOnEvent($GUI_EVENT_CLOSE, "main")
GUICtrlCreateGroup("闪讯所在路径:", 8, 8, 393, 65)
$exepath_input = GUICtrlCreateInput("", 16, 32, 321, 21)
GUICtrlSetState(-1,$GUI_DROPACCEPTED)
$browse_button = GUICtrlCreateButton("浏览", 344, 30, 49, 25)
GUICtrlSetOnEvent($browse_button, "main")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$apply_button = GUICtrlCreateButton("应用设置", 304, 90, 81, 33)
GUICtrlSetOnEvent($apply_button, "main")
$delete_button = GUICtrlCreateButton("清除信息", 304, 135, 81, 33)
GUICtrlSetOnEvent($delete_button, "main")
$exit_button = GUICtrlCreateButton("退出", 304, 180, 81, 33)
GUICtrlSetOnEvent($exit_button, "main")
GUICtrlCreateLabel("账号:", 16, 88, 40, 17)
GUICtrlCreateLabel("密码:", 16, 120, 40, 17)
$username_input = GUICtrlCreateInput("", 56, 86, 217, 21)
$password_input = GUICtrlCreateInput("", 56, 118, 217, 21)
GUICtrlCreateGroup("提示", 8, 150, 280, 80)
$hint = GUICtrlCreateLabel("", 24, 165, 250, 50)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUICtrlSetData($exepath_input,$exepath)
GUICtrlSetData($username_input,$username)
GUICtrlSetData($password_input,$password)
If $exepath="" Or FileExists($exepath)=0 Then
$tmpexepath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\闪讯","DisplayIcon")
If $tmpexepath="" Then
$hint_text &= "没有找到闪讯程序或指定的路径无效,可能程序并未正确安装,请按“浏览”手动指定程序路径!"&@CRLF&@CRLF
Else
GUICtrlSetData($exepath_input,$tmpexepath)
EndIf
EndIf
;E:\Program Files\ChinaNetSn\bin\NetKeeper.exe
If $username="" Or $password="" Then $hint_text &= "未定义用户名或密码,可能是由于第一次运行此程序或系统经过了重装,请重新指定!"&@CRLF&@CRLF
GUICtrlSetData($hint,$hint_text)
$hint_text=""
While 1
Sleep(100)
WEnd
EndIf
Func main()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
Exit
Case $exit_button
Exit
Case $browse_button
$Fpath = FileOpenDialog("选择闪讯所在","C:\","EXE文件(*.exe)",1+2,"NetKeeper.exe",$main)
If Not @error Then GUICtrlSetData($exepath_input,$Fpath)
Case $delete_button
RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run","autosignin")
RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\开机自动登入工具")
GUICtrlSetData($exepath_input,"")
GUICtrlSetData($username_input,"")
GUICtrlSetData($password_input,"")
GUICtrlSetData($hint,"注册信息卸载成功,同时程序将不在开机时启动!")
Case $apply_button
$exepath_in = GUICtrlRead($exepath_input)
$username_in = GUICtrlRead($username_input)
$password_in = GUICtrlRead($password_input)
If $exepath_in="" Or $username_in="" Or $password_in="" Then
GUICtrlSetData($hint,"路径或账户或密码为空,应用失败!")
Else
$Autostart = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run","autosignin");开机启动
If $Autostart="" Or $Autostart<>@AutoItExe Then RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run","autosignin","REG_SZ",@AutoItExe&" -run")
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\开机自动登入工具\闪讯","exepath","REG_SZ",$exepath_in)
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\开机自动登入工具\闪讯","username","REG_SZ",$username_in)
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\开机自动登入工具\闪讯","password","REG_SZ",$password_in)
GUICtrlSetData($hint,"应用成功!同时成功写入启动项,程序将在系统启动时自动启动闪讯并登入!"&@CRLF&"注意:请在移动此工具后重新运行此工具并点击应用以便更新工具的开机启动路径!")
EndIf
EndSwitch
EndFunc
Func _Run($exepath,$username,$password,$exe_name,$workpath)
Global $wintitle = "[TITLE:闪讯; CLASS:#32770]",$Buttontitle = "[ID:1010; TEXT:连接; CLASS:Button]"
Global $Edittitle = "[ID:1001; CLASS:Edit]",$Edit2title = "[ID:1009; CLASS:Edit]"
Global $Button2title = "[ID:1013; TEXT:记住密码; CLASS:Button]",$Button3title = "[ID:1037; TEXT:开机时自动运行; CLASS:Button]"
Global $statusbar = "[ID:1019; CLASS:msctls_statusbar32]"
Global $on_off=0
While 1
If ProcessExists($exe_name)=0 Then
Run($exepath,$workpath)
If @error Then
$msg = MsgBox(4,"警告!","未发现闪讯,可能已被卸载或路径被改变,选择“否”重新手动运行此工具进行设置,选择“是”卸载此工具的注册表信息,这将导致此工具不在开机时启动")
If $msg=6 Then
RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run","autosignin")
RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\开机自动登入工具")
MsgBox(0,"","注册信息卸载成功!")
Exit
Else
Run(@AutoItExe)
EndIf
EndIf
WinWait($wintitle)
Do
Sleep(100)
Until ControlCommand($wintitle,"",$Buttontitle,"IsEnabled", "")=1
ElseIf ProcessExists($exe_name)<>0 And Ping("www.baidu.com")=0 And $on_off=1 Then
ProcessClose($exe_name)
$on_off=0
EndIf
Sleep(300)
If ControlCommand($wintitle,"",$Buttontitle,"IsVisible","")=1 And ControlCommand($wintitle,"",$Buttontitle,"IsEnabled", "")=1 Then
If ControlGetText($wintitle,"",$Edittitle)<>$username Or ControlGetText($wintitle,"",$Edit2title)<>$password Then
ControlSetText($wintitle,"",$Edittitle,$username)
ControlSetText($wintitle,"",$Edit2title,$password)
EndIf;判断用户名与密码,两者之一若不符则输入定义的用户名和密码
If ControlCommand($wintitle,"",$Button2title,"IsChecked","")=0 Then ControlCommand($wintitle,"",$Button2title,"Check","");判断记住密码勾选
If ControlCommand($wintitle,"",$Button3title,"IsChecked","")=1 Then ControlCommand($wintitle,"",$Button3title,"UnCheck","");判断开机时自动运行勾选
ControlClick($wintitle,"",$Buttontitle)
Sleep(300)
If ControlCommand($wintitle,"",$Buttontitle,"IsEnabled", "")=1 Then
ContinueLoop
Else
Do
Sleep(100)
Until ControlCommand($wintitle,"",$statusbar,"IsVisible","")=1
EndIf
$on_off=1
EndIf
Sleep(1000)
If ControlCommand($wintitle,"",$statusbar,"IsVisible","")=1 And BitAND(WinGetState($wintitle),16)<>16 Then WinSetState($wintitle,"",@SW_MINIMIZE)
If BitAND(WinGetState($wintitle),16)=16 And Ping("www.baidu.com")>0 Then Exit
WEnd
EndFunc
;Ping("www.baidu.com")=0
|