<p>#NoTrayIcon<br />#Region ;**** Directives created by AutoIt3Wrapper_GUI ****<br />#AutoIt3Wrapper_outfile=.\myiscsi.exe<br />#AutoIt3Wrapper_UseAnsi=y<br />#AutoIt3Wrapper_Allow_Decompile=n<br />#AutoIt3Wrapper_Res_Comment=Myself<br />#AutoIt3Wrapper_Res_Description=Myself<br />#AutoIt3Wrapper_Res_Fileversion=1.0.0.2<br />#AutoIt3Wrapper_Run_AU3Check=n<br />#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****</p><p>#Include<Array.au3><br />#include <GUIConstants.au3><br />#include <File.au3><br />dim <a href="mailto:$logfile=@ScriptDir" target="_blank">$logfile=@ScriptDir</a> &"\myiscsi.log"<br />dim const <a href="mailto:$inifilename=@ScriptDir" target="_blank">$inifilename=@ScriptDir</a> &"\iscsi.ini"<br />dim const <a href="http://www.au3.net.cn/'mailto:$iscsistatus=@TempDir&"/iscsistatus.ini'" target="_blank">$iscsistatus=@TempDir&"\iscsistatus.ini</a>"<br />dim const $Version = "ISCSI连接器0.2(Myself)"<br />dim $iscsiip<br />dim $iscsiport<br />dim $iscsiiqn<br />dim $iscsivolume<br />dim $prevolume<br />dim $curvolume<br />dim $i<br />dim $iret<br />dim $m_status,$m_Progress1<br />dim $filedir,$szDrive, $szDir, $szFName, $szExt<br />dim $temp</p><p>;防止程序重复运行<br />If WinExists($Version) Then<br /> MsgBox(4096+16,"警告","程序已在运行,请不要重复执行!!!",5)<br /> Exit<br />Else<br /> AutoItWinSetTitle($Version)<br />EndIf<br />;检查调用格式<br />if $cmdline[0]<>1 Then<br /> msgbox(48,"警告","错误的调用格式")<br /> Exit<br />EndIf<br />;判断iscsi磁盘是否已经存在<br />$curvolume=IniRead($iscsistatus,"config","volume","")<br />MyIscsiRun($curvolume)</p><p>FileDelete($iscsistatus)<br />;监测所有需要的文件是否存在<br />if not (FileExists(@SystemDir&"\sc.exe") and FileExists(@SystemDir&"\diskpart.exe")) Then<br /> msgbox(48,"警告","系统文件不全,程序退出!!!")<br /> Exit<br />EndIf</p><p><br />;生成GUI<br />$Form1 = GUICreate($Version, 361, 53, 410, 213, BitOR($WS_CAPTION,$WS_BORDER,$WS_CLIPSIBLINGS))<br />$Label = GUICtrlCreateLabel("状态:", 8, 34, 40, 17)<br />$Label1 = GUICtrlCreateLabel("Myself专用", 295, 34,400, 17)<br />$C_status = GUICtrlCreateLabel("", 40, 34, 240, 17)<br />$Progress1 = GUICtrlCreateProgress(8, 8, 345, 17)<br />GUISetState(@SW_SHOW)<br />GUICtrlSetData ($Progress1,1)<br />GUICtrlSetData ($C_status,"开始连接游戏服务器")</p><p>MyIscsiINST()<br />;生成当前分区列表(0)<br />$prevolume= DriveGetDrive( "all" )<br />$iscsiip=IniRead($inifilename,"config","ip","192.168.0.252")<br />$iscsiport=IniRead($inifilename,"config","port","33260")<br />$iscsiiqn=IniRead($inifilename,"config","iqn","iqn.2005-02.com.ricecake.iscsi:00")<br />MyIscsiConnect($iscsiip,$iscsiport,$iscsiiqn)</p><p>;查找新的ISCSI盘符<br />$curvolume=MyIscsiFind($prevolume)<br />;盘符处理<br />$iscsivolume=IniRead($inifilename,"config","volume","")<br />GUICtrlSetData ($Progress1,70)<br />GUICtrlSetData ($C_status,"正在分配盘符,请等待。。。")<br />$curvolume=MyIscsiAssign($curvolume,$iscsivolume)<br />;iscsi盘符纪录到状态文件中,防止2次加载错误<br />IniWrite($iscsistatus,"config","volume",$curvolume)<br />MyIscsiHide($curvolume)<br />MyIscsiRun($curvolume)</p><p>;安装模块<br />Func MyIscsiINST()<br />Local const $checkinstall="C:\WINDOWS\system32\iscsicli.exe"<br />Local const <a href="mailto:$install=@ScriptDir" target="_blank">$install=@ScriptDir</a> &"\iscsi.exe"<br />if not FileExists($checkinstall) Then<br /> GUICtrlSetData ($C_status,"未发现ISCSI客户端")<br /> if FileExists($install) Then<br /> GUICtrlSetData ($C_status,"真在安装ISCSI客户端,请等待。。。")<br /> ShellExecuteWait($install," /q /norestart")<br /> FileDelete(@DesktopDir&"\Microsoft iSCSI Initiator.lnk")<br /> GUICtrlSetData ($C_status,"安装ISCSI客户端成功")<br /> else <br /> GUICtrlSetData ($C_status,"未找到ISCSI客户端!!!")<br /> msgbox(48,"警告","未找到ISCSI客户端!!!")<br /> Exit<br /> EndIf<br />Else<br /> GUICtrlSetData ($C_status,"发现ISCSI客户端")<br />EndIf<br />EndFunc</p><p>Func MyIscsiConnect($iscsiip,$iscsiport,$iscsiiqn)<br />;判断iscsi服务器是否在线<br />GUICtrlSetData ($C_status,"检测服务器状态")<br />$iret =ping($iscsiip,1000)<br />If @error Then<br /> GUICtrlSetData ($C_status,"未发现游戏服务器")<br /> msgbox(48,"警告","游戏服务器已关闭,请联系网管!")<br /> Exit<br />EndIf<br />;清除垃圾注册表数据<br />RegDelete("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E97B-E325-11CE-BFC1-08002BE10318}\0000\PersistentTargets")<br />RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\iSCSI\Discovery\Send Targets")<br />RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\iSCSI\Discovery\Send Targets")<br />RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\iSCSI\Discovery\Static Targets")<br />RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\iSCSI\Discovery\Static Targets")<br />;开始连接iscsi服务器<br />GUICtrlSetData ($C_status,"正在打开相关服务")<br />ShellExecuteWait("sc"," config msiscsi start= demand","","",@SW_HIDE)<br />ShellExecuteWait("sc"," config dmserver start= demand","","",@SW_HIDE)<br />ShellExecuteWait("sc"," start dmserver","","",@SW_HIDE)<br />ShellExecuteWait("sc"," start msiscsi","","",@SW_HIDE)<br />ShellExecuteWait("sc"," config msiscsi start= disabled","","",@SW_HIDE)<br />ShellExecuteWait("sc"," config dmserver start= disabled","","",@SW_HIDE)<br />GUICtrlSetData ($C_status,"正在指定ISCSI服务器参数")<br />ShellExecuteWait("iscsicli"," AddTargetPortal "&$iscsiip&" "&$iscsiport,"","",@SW_HIDE)<br />GUICtrlSetData ($C_status,"正在登陆ISCSI服务器")<br />ShellExecuteWait("iscsicli"," LoginTarget "&$iscsiiqn&" T * * * * * * * * * * * * * * * 0","","",@SW_HIDE)<br />EndFunc</p><p>;动态运行虚拟盘程序<br />Func MyIscsiRun($curvolume)<br />Local $szDrive, $szDir, $szFName, $szExt<br />if FileExists($curvolume&"\"&IniRead($inifilename,"config","check","netgame")) Then<br /> _PathSplit($cmdline[1], $szDrive, $szDir, $szFName, $szExt)<br /> $curvolume=_PathMake ($curvolume, $szDir, $szFName, $szExt)<br /> _PathSplit($curvolume, $szDrive, $szDir, $szFName, $szExt)<br /> If (Not FileExists($curvolume)) or (Not FileExists($szDrive & $szDir)) then<br /> MsgBox(48, "警告", "没有找到程序" & $curvolume & ",请与管理员联系!")<br /> Exit<br /> Endif<br /> ShellExecute($curvolume,"",$szDrive & $szDir)<br /> Exit<br />EndIf<br />EndFunc</p><p>;查找虚拟磁盘盘符<br />Func MyIscsiFind($src)<br />local $curvolume,$i<br />;生成当前分区列表(1),判断分区是否增加<br />for $i=0 to 60 <br /> $curvolume = DriveGetDrive( "all" )<br /> if $src[0]<>$curvolume[0] Then<br /> $i=9999<br /> exitloop<br /> EndIf<br /> sleep(500)<br />next<br />if $i<>9999 Then<br /> GUICtrlSetData ($C_status,"连接超时,ISCSI服务器连接失败")<br /> msgbox(48,"警告","对不起,服务器连接失败")<br /> Exit<br />EndIf</p><p>for $i=1 to $curvolume[0]<br /> $iret = _ArraySearch ($prevolume,$curvolume[$i],0,0,0,True)<br /> if $iret=-1 Then<br /> $curvolume=$curvolume[$i]<br /> $i=9999<br /> ExitLoop<br /> EndIf<br />Next<br />if $i<>9999 Then<br /> msgbox(48,"警告","查找iscsi分区错误")<br /> Exit<br />EndIf<br />return $curvolume<br />EndFunc</p><p>;指派虚拟盘盘符<br />Func MyIscsiAssign($src,$dst)<br />local $i<br />;合法性检查(简单)<br />if $src="" or $dst="" or $src=$dst Then<br /> return $src<br />EndIf<br />;刷新盘符<br />FileExists($curvolume&"\")<br />FileDelete("c:\windows\system32\iscsi.txt")<br />FileWriteLine("c:\windows\system32\iscsi.txt","select volume "&$src)<br />FileWriteLine("c:\windows\system32\iscsi.txt","assign letter="&$dst)<br />For $i=1 to 30<br /> ShellExecuteWait("diskpart"," /s c:\windows\system32\iscsi.txt","","",@SW_HIDE)<br /> if FileExists($dst) Then<br /> if FileExists($dst&"\"&IniRead($inifilename,"config","check","netgame")) Then<br /> return $dst<br /> Else<br /> return $src<br /> EndIf<br /> EndIf<br /> sleep(1000)<br />Next<br />return $src<br />EndFunc</p><p>;隐藏指定驱动器<br />Func MyIscsiHide($volume)<br />local $reg1,$reg2<br />if IniRead($inifilename,"config","hide","1")=0 Then<br /> Return 0<br />EndIf<br />$volume=BitShift(1,0-(Asc(StringLeft($volume,1))-ASC("A")))<br />$REG1=RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\Explorer","NoDrives")<br />$REG2=RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\Explorer","NoViewOnDrive")<br />$REG1=BitOR($REG1,$volume)<br />$REG2=BitOR($REG2,$volume)<br />RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\Explorer","NoDrives","REG_DWORD",$REG1)<br />RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\Explorer","NoViewOnDrive","REG_DWORD",$REG2)<br />;强制刷新注册表<br />if not FileExists(@SystemDir&"\GroupPolicy\gpt.ini") then<br /> DirCreate(@SystemDir&"\GroupPolicy")<br /> IniWrite(@SystemDir&"\GroupPolicy\gpt.ini","General","gPCUserExtensionNames","[{35378EAC-683F-11D2-A89A-00C04FBBCFA2}{0F6B957E-509E-11D1-A7CC-0000F87571E3}]")<br /> IniWrite(@SystemDir&"\GroupPolicy\gpt.ini","General","Version","65536")<br />EndIf<br />if not FileExists(@SystemDir&"\GroupPolicy\User\Registry.pol") Then<br /> DirCreate(@SystemDir&"\GroupPolicy\User")<br /> FileInstall("Registry.pol",@SystemDir&"\GroupPolicy\User\Registry.pol",1)<br />EndIf<br />ShellExecuteWait(@SystemDir&"\gpupdate.exe","/force","","",@SW_HIDE)<br />EndFunc</p><p>配置文件:ISCSI.INI</p><p>[config]</p><p>#服务器IP<br />ip=172.16.250.20</p><p>#服务器端口<br />port=33260</p><p>#连接用IQN<br />iqn=iqn.2005-02.com.ricecake.iscsi:00</p><p>#如不想指派则留空,指派比较影响速度(分配盘符)<br />volume=</p><p>#服务器上有的效验文件夹或文件不要带盘符(默认为netgame)<br />check=netgame</p><p>#是否自动隐藏ISCSI驱动器0=不隐藏(默认隐藏)<br />hide=1</p> |