找回密码
 加入
搜索
查看: 5016|回复: 2

ISCSI连接器

[复制链接]
发表于 2008-5-3 14:19:44 | 显示全部楼层 |阅读模式
<p>#NoTrayIcon<br />#Region ;**** Directives created by AutoIt3Wrapper_GUI ****<br />#AutoIt3Wrapper_outfile=.&#92;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&lt;Array.au3&gt;<br />#include &lt;GUIConstants.au3&gt;<br />#include &lt;File.au3&gt;<br />dim <a href="mailto:$logfile=@ScriptDir" target="_blank">$logfile=@ScriptDir</a> &amp;&quot;&#92;myiscsi.log&quot;<br />dim const <a href="mailto:$inifilename=@ScriptDir" target="_blank">$inifilename=@ScriptDir</a> &amp;&quot;&#92;iscsi.ini&quot;<br />dim const <a href="http://www.au3.net.cn/'mailto:$iscsistatus=@TempDir&amp;&quot;/iscsistatus.ini'" target="_blank">$iscsistatus=@TempDir&amp;&quot;&#92;iscsistatus.ini</a>&quot;<br />dim const $Version = &quot;ISCSI连接器0.2(Myself)&quot;<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 />&nbsp;MsgBox(4096+16,&quot;警告&quot;,&quot;程序已在运行,请不要重复执行!!!&quot;,5)<br />&nbsp;Exit<br />Else<br />&nbsp;AutoItWinSetTitle($Version)<br />EndIf<br />;检查调用格式<br />if $cmdline[0]&lt;&gt;1 Then<br />&nbsp;&nbsp; msgbox(48,&quot;警告&quot;,&quot;错误的调用格式&quot;)<br />&nbsp;&nbsp; Exit<br />EndIf<br />;判断iscsi磁盘是否已经存在<br />$curvolume=IniRead($iscsistatus,&quot;config&quot;,&quot;volume&quot;,&quot;&quot;)<br />MyIscsiRun($curvolume)</p><p>FileDelete($iscsistatus)<br />;监测所有需要的文件是否存在<br />if not (FileExists(@SystemDir&amp;&quot;&#92;sc.exe&quot;) and FileExists(@SystemDir&amp;&quot;&#92;diskpart.exe&quot;)) Then<br />&nbsp;&nbsp; msgbox(48,&quot;警告&quot;,&quot;系统文件不全,程序退出!!!&quot;)<br />&nbsp;&nbsp; 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(&quot;状态:&quot;, 8, 34, 40, 17)<br />$Label1 = GUICtrlCreateLabel(&quot;Myself专用&quot;, 295, 34,400, 17)<br />$C_status = GUICtrlCreateLabel(&quot;&quot;, 40, 34, 240, 17)<br />$Progress1 = GUICtrlCreateProgress(8, 8, 345, 17)<br />GUISetState(@SW_SHOW)<br />GUICtrlSetData ($Progress1,1)<br />GUICtrlSetData ($C_status,&quot;开始连接游戏服务器&quot;)</p><p>MyIscsiINST()<br />;生成当前分区列表(0)<br />$prevolume= DriveGetDrive( &quot;all&quot; )<br />$iscsiip=IniRead($inifilename,&quot;config&quot;,&quot;ip&quot;,&quot;192.168.0.252&quot;)<br />$iscsiport=IniRead($inifilename,&quot;config&quot;,&quot;port&quot;,&quot;33260&quot;)<br />$iscsiiqn=IniRead($inifilename,&quot;config&quot;,&quot;iqn&quot;,&quot;iqn.2005-02.com.ricecake.iscsi:00&quot;)<br />MyIscsiConnect($iscsiip,$iscsiport,$iscsiiqn)</p><p>;查找新的ISCSI盘符<br />$curvolume=MyIscsiFind($prevolume)<br />;盘符处理<br />$iscsivolume=IniRead($inifilename,&quot;config&quot;,&quot;volume&quot;,&quot;&quot;)<br />GUICtrlSetData ($Progress1,70)<br />GUICtrlSetData ($C_status,&quot;正在分配盘符,请等待。。。&quot;)<br />$curvolume=MyIscsiAssign($curvolume,$iscsivolume)<br />;iscsi盘符纪录到状态文件中,防止2次加载错误<br />IniWrite($iscsistatus,&quot;config&quot;,&quot;volume&quot;,$curvolume)<br />MyIscsiHide($curvolume)<br />MyIscsiRun($curvolume)</p><p>;安装模块<br />Func MyIscsiINST()<br />Local const $checkinstall=&quot;C:&#92;WINDOWS&#92;system32&#92;iscsicli.exe&quot;<br />Local const <a href="mailto:$install=@ScriptDir" target="_blank">$install=@ScriptDir</a> &amp;&quot;&#92;iscsi.exe&quot;<br />if not FileExists($checkinstall) Then<br />&nbsp;&nbsp; GUICtrlSetData ($C_status,&quot;未发现ISCSI客户端&quot;)<br />&nbsp;&nbsp; if FileExists($install) Then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GUICtrlSetData ($C_status,&quot;真在安装ISCSI客户端,请等待。。。&quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ShellExecuteWait($install,&quot; /q /norestart&quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FileDelete(@DesktopDir&amp;&quot;&#92;Microsoft iSCSI Initiator.lnk&quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GUICtrlSetData ($C_status,&quot;安装ISCSI客户端成功&quot;)<br />&nbsp;&nbsp; else&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GUICtrlSetData ($C_status,&quot;未找到ISCSI客户端!!!&quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; msgbox(48,&quot;警告&quot;,&quot;未找到ISCSI客户端!!!&quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit<br />&nbsp;&nbsp; EndIf<br />Else<br />&nbsp;GUICtrlSetData ($C_status,&quot;发现ISCSI客户端&quot;)<br />EndIf<br />EndFunc</p><p>Func MyIscsiConnect($iscsiip,$iscsiport,$iscsiiqn)<br />;判断iscsi服务器是否在线<br />GUICtrlSetData ($C_status,&quot;检测服务器状态&quot;)<br />$iret =ping($iscsiip,1000)<br />If @error Then<br />&nbsp;&nbsp; GUICtrlSetData ($C_status,&quot;未发现游戏服务器&quot;)<br />&nbsp;&nbsp; msgbox(48,&quot;警告&quot;,&quot;游戏服务器已关闭,请联系网管!&quot;)<br />&nbsp;&nbsp; Exit<br />EndIf<br />;清除垃圾注册表数据<br />RegDelete(&quot;HKEY_LOCAL_MACHINE&#92;SYSTEM&#92;CurrentControlSet&#92;Control&#92;Class&#92;&#123;4D36E97B-E325-11CE-BFC1-08002BE10318&#125;&#92;0000&#92;PersistentTargets&quot;)<br />RegDelete(&quot;HKEY_LOCAL_MACHINE&#92;SOFTWARE&#92;Microsoft&#92;Windows NT&#92;CurrentVersion&#92;iSCSI&#92;Discovery&#92;Send Targets&quot;)<br />RegWrite(&quot;HKEY_LOCAL_MACHINE&#92;SOFTWARE&#92;Microsoft&#92;Windows NT&#92;CurrentVersion&#92;iSCSI&#92;Discovery&#92;Send Targets&quot;)<br />RegDelete(&quot;HKEY_LOCAL_MACHINE&#92;SOFTWARE&#92;Microsoft&#92;Windows NT&#92;CurrentVersion&#92;iSCSI&#92;Discovery&#92;Static Targets&quot;)<br />RegWrite(&quot;HKEY_LOCAL_MACHINE&#92;SOFTWARE&#92;Microsoft&#92;Windows NT&#92;CurrentVersion&#92;iSCSI&#92;Discovery&#92;Static Targets&quot;)<br />;开始连接iscsi服务器<br />GUICtrlSetData ($C_status,&quot;正在打开相关服务&quot;)<br />ShellExecuteWait(&quot;sc&quot;,&quot; config msiscsi start= demand&quot;,&quot;&quot;,&quot;&quot;,@SW_HIDE)<br />ShellExecuteWait(&quot;sc&quot;,&quot; config dmserver start= demand&quot;,&quot;&quot;,&quot;&quot;,@SW_HIDE)<br />ShellExecuteWait(&quot;sc&quot;,&quot; start dmserver&quot;,&quot;&quot;,&quot;&quot;,@SW_HIDE)<br />ShellExecuteWait(&quot;sc&quot;,&quot; start msiscsi&quot;,&quot;&quot;,&quot;&quot;,@SW_HIDE)<br />ShellExecuteWait(&quot;sc&quot;,&quot; config msiscsi start= disabled&quot;,&quot;&quot;,&quot;&quot;,@SW_HIDE)<br />ShellExecuteWait(&quot;sc&quot;,&quot; config dmserver start= disabled&quot;,&quot;&quot;,&quot;&quot;,@SW_HIDE)<br />GUICtrlSetData ($C_status,&quot;正在指定ISCSI服务器参数&quot;)<br />ShellExecuteWait(&quot;iscsicli&quot;,&quot; AddTargetPortal &quot;&amp;$iscsiip&amp;&quot; &quot;&amp;$iscsiport,&quot;&quot;,&quot;&quot;,@SW_HIDE)<br />GUICtrlSetData ($C_status,&quot;正在登陆ISCSI服务器&quot;)<br />ShellExecuteWait(&quot;iscsicli&quot;,&quot; LoginTarget &quot;&amp;$iscsiiqn&amp;&quot; T * * * * * * * * * * * * * * * 0&quot;,&quot;&quot;,&quot;&quot;,@SW_HIDE)<br />EndFunc</p><p>;动态运行虚拟盘程序<br />Func MyIscsiRun($curvolume)<br />Local&nbsp; $szDrive, $szDir, $szFName, $szExt<br />if FileExists($curvolume&amp;&quot;&#92;&quot;&amp;IniRead($inifilename,&quot;config&quot;,&quot;check&quot;,&quot;netgame&quot;)) Then<br />&nbsp;_PathSplit($cmdline[1], $szDrive, $szDir, $szFName, $szExt)<br />&nbsp;$curvolume=_PathMake ($curvolume, $szDir, $szFName, $szExt)<br />&nbsp;_PathSplit($curvolume, $szDrive, $szDir, $szFName, $szExt)<br />&nbsp;If (Not FileExists($curvolume)) or (Not FileExists($szDrive &amp; $szDir))&nbsp; then<br />&nbsp;&nbsp;MsgBox(48, &quot;警告&quot;, &quot;没有找到程序&quot; &amp; $curvolume &amp; &quot;,请与管理员联系!&quot;)<br />&nbsp;&nbsp;Exit<br />&nbsp;Endif<br />&nbsp;ShellExecute($curvolume,&quot;&quot;,$szDrive &amp; $szDir)<br />&nbsp;Exit<br />EndIf<br />EndFunc</p><p>;查找虚拟磁盘盘符<br />Func MyIscsiFind($src)<br />local $curvolume,$i<br />;生成当前分区列表(1),判断分区是否增加<br />for $i=0 to 60 <br />&nbsp;&nbsp; $curvolume = DriveGetDrive( &quot;all&quot; )<br />&nbsp;&nbsp; if $src[0]&lt;&gt;$curvolume[0] Then<br />&nbsp;&nbsp;&nbsp; $i=9999<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exitloop<br />&nbsp;&nbsp; EndIf<br />&nbsp;&nbsp; sleep(500)<br />next<br />if $i&lt;&gt;9999 Then<br />&nbsp;GUICtrlSetData ($C_status,&quot;连接超时,ISCSI服务器连接失败&quot;)<br />&nbsp;msgbox(48,&quot;警告&quot;,&quot;对不起,服务器连接失败&quot;)<br />&nbsp;Exit<br />EndIf</p><p>for $i=1 to $curvolume[0]<br />&nbsp;$iret = _ArraySearch ($prevolume,$curvolume[$i],0,0,0,True)<br />&nbsp;&nbsp;&nbsp; if $iret=-1 Then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $curvolume=$curvolume[$i]<br />&nbsp;&nbsp;&nbsp; $i=9999<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ExitLoop<br />&nbsp;&nbsp; EndIf<br />Next<br />if $i&lt;&gt;9999 Then<br />&nbsp;msgbox(48,&quot;警告&quot;,&quot;查找iscsi分区错误&quot;)<br />&nbsp;Exit<br />EndIf<br />return $curvolume<br />EndFunc</p><p>;指派虚拟盘盘符<br />Func MyIscsiAssign($src,$dst)<br />local $i<br />;合法性检查(简单)<br />if $src=&quot;&quot; or $dst=&quot;&quot; or $src=$dst Then<br />&nbsp;return $src<br />EndIf<br />;刷新盘符<br />FileExists($curvolume&amp;&quot;&#92;&quot;)<br />FileDelete(&quot;c:&#92;windows&#92;system32&#92;iscsi.txt&quot;)<br />FileWriteLine(&quot;c:&#92;windows&#92;system32&#92;iscsi.txt&quot;,&quot;select volume &quot;&amp;$src)<br />FileWriteLine(&quot;c:&#92;windows&#92;system32&#92;iscsi.txt&quot;,&quot;assign letter=&quot;&amp;$dst)<br />For $i=1 to 30<br />&nbsp;ShellExecuteWait(&quot;diskpart&quot;,&quot; /s c:&#92;windows&#92;system32&#92;iscsi.txt&quot;,&quot;&quot;,&quot;&quot;,@SW_HIDE)<br />&nbsp;if FileExists($dst) Then<br />&nbsp;&nbsp;if FileExists($dst&amp;&quot;&#92;&quot;&amp;IniRead($inifilename,&quot;config&quot;,&quot;check&quot;,&quot;netgame&quot;)) Then<br />&nbsp;&nbsp;&nbsp;return $dst<br />&nbsp;&nbsp;Else<br />&nbsp;&nbsp;&nbsp;return $src<br />&nbsp;&nbsp;EndIf<br />&nbsp;EndIf<br />&nbsp;sleep(1000)<br />Next<br />return $src<br />EndFunc</p><p>;隐藏指定驱动器<br />Func MyIscsiHide($volume)<br />local $reg1,$reg2<br />if IniRead($inifilename,&quot;config&quot;,&quot;hide&quot;,&quot;1&quot;)=0 Then<br />&nbsp;Return 0<br />EndIf<br />$volume=BitShift(1,0-(Asc(StringLeft($volume,1))-ASC(&quot;A&quot;)))<br />$REG1=RegRead(&quot;HKEY_LOCAL_MACHINE&#92;SOFTWARE&#92;Microsoft&#92;Windows&#92;CurrentVersion&#92;policies&#92;Explorer&quot;,&quot;NoDrives&quot;)<br />$REG2=RegRead(&quot;HKEY_LOCAL_MACHINE&#92;SOFTWARE&#92;Microsoft&#92;Windows&#92;CurrentVersion&#92;policies&#92;Explorer&quot;,&quot;NoViewOnDrive&quot;)<br />$REG1=BitOR($REG1,$volume)<br />$REG2=BitOR($REG2,$volume)<br />RegWrite(&quot;HKEY_LOCAL_MACHINE&#92;SOFTWARE&#92;Microsoft&#92;Windows&#92;CurrentVersion&#92;policies&#92;Explorer&quot;,&quot;NoDrives&quot;,&quot;REG_DWORD&quot;,$REG1)<br />RegWrite(&quot;HKEY_LOCAL_MACHINE&#92;SOFTWARE&#92;Microsoft&#92;Windows&#92;CurrentVersion&#92;policies&#92;Explorer&quot;,&quot;NoViewOnDrive&quot;,&quot;REG_DWORD&quot;,$REG2)<br />;强制刷新注册表<br />if not FileExists(@SystemDir&amp;&quot;&#92;GroupPolicy&#92;gpt.ini&quot;) then<br />&nbsp;DirCreate(@SystemDir&amp;&quot;&#92;GroupPolicy&quot;)<br />&nbsp;IniWrite(@SystemDir&amp;&quot;&#92;GroupPolicy&#92;gpt.ini&quot;,&quot;General&quot;,&quot;gPCUserExtensionNames&quot;,&quot;[&#123;35378EAC-683F-11D2-A89A-00C04FBBCFA2&#125;&#123;0F6B957E-509E-11D1-A7CC-0000F87571E3&#125;]&quot;)<br />&nbsp;IniWrite(@SystemDir&amp;&quot;&#92;GroupPolicy&#92;gpt.ini&quot;,&quot;General&quot;,&quot;Version&quot;,&quot;65536&quot;)<br />EndIf<br />if not FileExists(@SystemDir&amp;&quot;&#92;GroupPolicy&#92;User&#92;Registry.pol&quot;) Then<br />&nbsp;DirCreate(@SystemDir&amp;&quot;&#92;GroupPolicy&#92;User&quot;)<br />&nbsp;FileInstall(&quot;Registry.pol&quot;,@SystemDir&amp;&quot;&#92;GroupPolicy&#92;User&#92;Registry.pol&quot;,1)<br />EndIf<br />ShellExecuteWait(@SystemDir&amp;&quot;&#92;gpupdate.exe&quot;,&quot;/force&quot;,&quot;&quot;,&quot;&quot;,@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>
发表于 2008-7-1 23:48:23 | 显示全部楼层
不行呀····不行呀····不行呀····不行呀····不行呀····不行呀····不行呀····不行呀····不行呀····
发表于 2012-12-7 09:17:31 | 显示全部楼层
钱不够了,怎么下载呢?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-12-24 01:32 , Processed in 0.080668 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表