ODBC自动安装连接器
因为odbc通过手动连接需要一台一台的操作,实在太麻烦,不符合自动化的要求。于是就用autoit3写了个脚本安装器,自动连接到数据中
安装完后自动连接到服务器的sql数据库里
#RequireAdmin
#Region ;**** 参数创建于ACNWrapper_GUI ****
#PRE_Icon=F:\picture\picture20210120\启动盘图标\restart_blue_128px_1071784_easyicon.net.ico
#PRE_UseUpx=n
#PRE_Compile_Both=y
#PRE_Res_requestedExecutionLevel=None
#PRE_Res_File_Add=D:\360安全浏览器下载\AUtoit3\test\odbc\SETUP1.INI
#PRE_Res_File_Add=D:\360安全浏览器下载\AUtoit3\test\odbc\SETUP.INI
#EndRegion ;**** 参数创建于ACNWrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Crypt.au3>
#Include <File.au3>
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <Process.au3>
;创建窗口及控件@WindowsDir
;检查有没有ini文件,没有就放一个dircreate("d:\123") _MD5_process(_GetYM())
;_Magbox(@WindowsDir&"\pdfwindows.ini")
Local$filepath1=@WindowsDir&"\pdfwindows.ini"
_Creat_Ini($filepath1)
;安装窗口
_ShowAnotherWindows()
Func _Msgbox1($data)
MsgBox(0,"系统提示",$data)
EndFunc
Func _ShowAnotherWindows()
$sFile="D:\autoit3\icon\startIco.ico"
GUICreate("Mfnmfnquotation安装,版权: byJC",280,90)
GUISetState(@SW_SHOW);;GUICtrlCreateLabel
Local$Label1 = GUICtrlCreateLabel("注意:请用系统管理员权限运行(最好退出360)!", 15,10,303, 25)
GUICtrlSetColor($Label1,0xFF0000);0xff0000红
Local$Button1 = GUICtrlCreateButton("ODBC安装", 15, 40, 73,25)
Local$Button2 = GUICtrlCreateButton("ODBC删除", 105, 40,73, 25)
Local$Button3 = GUICtrlCreateButton("退出", 195, 40,73, 25)
GUISetIcon($sFile)
While1
$nMsg= GUIGetMsg()
Switch$nMsg
Case$GUI_EVENT_CLOSE
GUISetState(@SW_HIDE)
;MsgBox(0,"系统提示","请输入正确的序列号!")
;GUICreate("序列号窗口1,版权: byJC",290,120)
;GUISetState(@SW_SHOW)GUICtrlSetGUICtrlSetColor
;ExitLoop
Exit
Case$Button1;安装
$driver1="SETUP1.INI"
$driver2="SETUP.INI"
$driver3="c:\mfnquotation\SETUP.INI"
$driver4="c:\mfnquotation3\SETUP.INI"
_Creat_Ini2($driver3,$driver1,"c:\mfnquotation\")
_Creat_Ini2($driver4,$driver2,"c:\mfnquotation3\")
;FileCopy
_ODBC_Setup()
_msgbox1("安装ODBC完成!")
;MsgBox(0,"dd",$temp1)
Case $Button2;删除
_ODBC_Delete()
_msgbox1("删除成功!")
Case$Button3
exit
EndSwitch
WEnd
EndFunc
Func _ODBC_Setup()
;RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ShellFolders","AppData","REG_SZ","你要迁移的路径")
$driver_1=@WindowsDir&"\System32\SQLSRV32.dll"
RegWrite("HKEY_CURRENT_USER\SOFTWARE\ODBC\ODBC.INI\ndmfn10","Driver","REG_SZ",$driver_1)
............................
RegWrite("HKEY_CURRENT_USER\SOFTWARE\ODBC\ODBC.INI\ODBCData Sources","ndmfn10","REG_SZ","SQLServer")
EndFunc
Func _ODBC_Delete()
;RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ShellFolders","AppData","REG_SZ","你要迁移的路径")
;;RegDelete("HKEY_CURRENT_USER\Software\Test","TestKey")
;$driver_1=@WindowsDir&"\System32\SQLSRV32.dll"
RegDelete("HKEY_CURRENT_USER\SOFTWARE\ODBC\ODBC.INI\ndmfn10")
.......................
EndFunc
Func _Creat_Ini($file1);文件存不存在,不存在就生成
Dim$char1,$temp1
IfNot FileExists($file1) Then
;_FileCreate($file1)
_ShowMd5_control_1()
Else
;存在就比较
;要打开的文件
$char1=_file_data($file1)
;_msgbox1($char1)
$temp1=_MD5_process(_GetYM())
If$temp1<>$char1 Then
_ShowMd5_control_1()
Else
;显示开始开装PDF
endif
EndIf
EndFunc
Func_Creat_Ini2($file1,$file2,$file3);文件存不存在,不存在就生成
;Dim$char1,$temp1
IfNot FileExists($file1) Then
FileCopy($file2,$file3&"setup.ini",9)
;_ShowMd5_control_1()
;ren路径\文件名.扩展名文件名.扩展名
;Sleep(1000)
;$runDos= _RunDOS("ren "& $file1 & " setup.ini")
EndIf
EndFunc
Func _Creat_Ini1($file1);文件存不存在,不存在就生成
;Dim$char1,$temp1
IfNot FileExists($file1) Then
_FileCreate($file1)
;_ShowMd5_control_1()
EndIf
EndFunc
Func _file_data($path1);把数据读出来
Local$file = FileOpen($path1, 0)
Dim $chars,$char2
;检查打开的文件是否可为读
If$file = -1 Then
MsgBox(4096,"系统提示", "出错,请联系开发者JC!")
Exit
EndIf
;每次读取一个字符,直到文件结束(译注:读中文必须设置为远大于1的值!)(译注的译注(thesnow):ANSI编码中,一个中文为两个字符(char)/字节)
$chars= FileRead($path1)
Return$chars
#cs
While1
Local$chars = FileRead($path1)
If@error = -1 Then ExitLoop
If$chars<>"" Then
$char2=$char2&$chars
Return$char2
endif
;$i=$i+1
WEnd
#ce
FileClose($file)
EndFunc
Func _Write_date_to_txt($file1,$data1);把数据写进去
$file= FileOpen($file1, 10) ; 等同 2 + 8 (清除内容 + 目录不存在就创建)
If$file = -1 Then
MsgBox(4096,"系统提示", "出错,请联系开发者JC!")
Exit
Else
FileWrite($file1,$data1)
EndIf
FileClose($file)
EndFunc
Func _ShowMd5_control_1();创建序列号窗口及控件
$sFile="D:\autoit3\icon\startIco.ico"
;GUICreate("请输入序列号,版权: byJC", 380, 422, 192, 132)
GUICreate("序列号窗口,版权: byJC",290,120)
$Label1= GUICtrlCreateLabel("序列号:", 15, 30,-1, -1)
$input= GUICtrlCreateInput("", 80, 30, 200, -1)
$Button1= GUICtrlCreateButton("确定", 45, 70, 73, 25)
$Button2= GUICtrlCreateButton("退出", 166, 70, 73, 25)
GUISetState(@SW_SHOW)
GUISetIcon($sFile)
While1
$nMsg = GUIGetMsg()
Switch $nMsg
Case$GUI_EVENT_CLOSE
GUISetState(@SW_HIDE)
;MsgBox(0,"系统提示","请输入正确的序列号!")
;GUICreate("序列号窗口1,版权: byJC",290,120)
;GUISetState(@SW_SHOW)
;ExitLoop
Exit
Case $Button1
;;与输入框进行比较$sPassword=GUICtrlRead($input)
$temp1=_MD5_process(_GetYM())
$temp1=_CALG_RC4_txt(_GetYM())
If GUICtrlRead($input)=="" Then
MsgBox(0,"系统提示","请输入序列号!")
ElseIf GUICtrlRead($input)<>$temp1Then
MsgBox(0,"系统提示",$input& "2:" & $temp1 )
MsgBox(0,"系统提示","请输入正确的序列号!")
Else
;写出去
_Creat_Ini1($filepath1)
_Write_date_to_txt($filepath1,$temp1)
;MsgBox(0,"系统提示","输入成功,开始安装PDF打印!")
GUISetState(@SW_HIDE)
ExitLoop
EndIf
;MsgBox(0,"dd",$temp1)
Case$Button2
exit
EndSwitch
WEnd
;Sleep(3000)
EndFunc
Func _MD5_process($sPassword);加密
Dim$mdp
$mdp=StringToBinary($sPassword,4);4表示二进制数据为 UTF8编码
$mdp=_Crypt_HashData($mdp,$CALG_MD5)
$mdp=StringMid($mdp,9,16)
Return$mdp
EndFunc
Func_CALG_RC4_txt($data); 加密
Dim$bEecrypted
$sKey= "*******" ; 加密用的 key
$algorithm= $CALG_RC4 ; 初始化算法$CALG_RC4 是系统提供的算法
$bEecrypted= _Crypt_EncryptData($data, $sKey, $algorithm)
$bEecrypted=StringMid($bEecrypted,9,16)
Return$bEecrypted
EndFunc
Func _CALG_RC4_txt1($data);解密
Dim$bdecrypted
$sKey= "***********" ; 加密用的 key
$algorithm= $CALG_RC4 ; 初始化算法$CALG_RC4 是系统提供的算法
;解密
$bDecrypted= _Crypt_DecryptData($data, $sKey, $algorithm)
$bDecrypted=BinaryToString($bDecrypted)
Return$bDecrypted
EndFunc
微信:15312167779(系统交流学习)
邮箱:149824844@qq.com
更多我的学习技术文章:
https://boysky123.lofter.com
https://user.qzone.qq.com/149824844