|
本帖最后由 chasedream 于 2012-12-1 19:38 编辑 $var = IniReadSectionNames(@ScriptDir & "\config.ini")
If @error Then
MsgBox(4096, "", "错误, 读取INI文件失败.")
Else
For $i = 1 To $var[0]
MsgBox(4096, "", "字段名:" & $var[$i])
$var1 = IniReadSection(@ScriptDir & "\config.ini", $var[$i])
If @error Then
MsgBox(4096, "", "错误, 读取INI文件失败.")
Else
For $a = 1 To $var1[0][0]
MsgBox(4096, "", "关键字: " & $var1[$a][0] & @CRLF & "值: " & $var1[$a][1])
Next
EndIf
Next
EndIf
config.ini
[磁盘0]
服务端=192.168.1.245
服务器盘符=g
客户机盘符=g
[磁盘1]
服务端=192.168.1.246
服务器盘符=h
客户机盘符=h
根据需要可能还会添加
[磁盘2]
服务端=192.168.1.247
服务器盘符=m
客户机盘符=m
我要获取=后面的值,研究了一个晚上,不知道怎么用。
我想把获取的$var1[$a][1])
赋给 $sip , $cdisk $sdisk
结果:
$sip = 192.168.1.245
$cdisk = g
$sdisk = g
终于搞定了,附完整的代码,希望大家指点指点。Opt("TrayIconHide", 1)
$G_SZVERSION = "顺网虚拟磁盘客户端"
If WinExists($G_SZVERSION) Then Exit
AutoItWinSetTitle($G_SZVERSION)
Dim $sdisk, $cdisk, $sip, $cip, $ip, $richsrv, $host
$var = IniReadSectionNames(@ScriptDir & "\config.ini")
If @error Then
MsgBox(4096, "", "错误, 读取INI文件失败.")
Else
For $i = 1 To $var[0]
$var1 = IniReadSection(@ScriptDir & "\config.ini", $var[$i])
If @error Then
MsgBox(4096, "", "错误, 读取INI文件失败.")
Else
For $a = 1 To $var1[0][0]
If $var1[$a][0] = "服务端" Then
$sip = $var1[$a][1]
ElseIf $var1[$a][0] = "服务器盘符" Then
$sdisk = $var1[$a][1]
Else
If $var1[$a][0] = "客户机盘符" Then
$cdisk = $var1[$a][1]
EndIf
EndIf
Next
_connect()
Sleep(2000)
EndIf
Next
EndIf
Func _connect()
$richsrv = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Richdisk", "Server")
If $sip = "" Then $sip = $richsrv
$ip = StringSplit($sip, ".")
$host = StringSplit(@IPAddress1, ".")
$sdisk = StringUpper($sdisk)
$cdisk = StringUpper($cdisk)
FileInstall("NetDisk.dll", @SystemDir & "\NetDisk.dll")
Global Const $INVALID_HANDLE_VALUE = Ptr(-1)
Local $result = DllCall(@SystemDir & "\NetDisk.dll", "long", "NetDiskInit")
If $result[0] <> 1 Then
MsgBox(16, "提示:", "未安装虚拟磁盘驱动")
Exit
EndIf
$result = DllCall("KERNEL32.DLL", "long", "CreateFile", "str", "\\.\ControlDevice", "long", -1073741824, "long", 0, "ptr", 0, "long", 3, "long", 128, "long", 0)
$hDrvHandle = $result[0]
If $hDrvHandle = $INVALID_HANDLE_VALUE Or $hDrvHandle = 0 Then
MsgBox(16, "提示:", "加载失败")
Exit
EndIf
Local $szin, $szout
$szin = DllStructCreate("byte[54]")
$szout = DllStructCreate("byte[4]")
$szinoff = DllStructCreate("byte[4]")
DllStructSetData($szin, 1, $host[1], 1);客户端IP
DllStructSetData($szin, 1, $host[2], 2)
DllStructSetData($szin, 1, $host[3], 3)
DllStructSetData($szin, 1, $host[4], 4)
DllStructSetData($szin, 1, 30, 6)
DllStructSetData($szin, 1, 140, 7)
DllStructSetData($szin, 1, 127, 8)
DllStructSetData($szin, 1, 24, 9)
DllStructSetData($szin, 1, 234, 10)
DllStructSetData($szin, 1, Asc($cdisk), 11);客户端盘符
DllStructSetData($szin, 1, $ip[1], 12);服务端IP
DllStructSetData($szin, 1, $ip[2], 13)
DllStructSetData($szin, 1, $ip[3], 14)
DllStructSetData($szin, 1, $ip[4], 15)
DllStructSetData($szin, 1, Asc($sdisk), 16);服务端盘符
DllStructSetData($szin, 1, 252, 53)
DllStructSetData($szin, 1, 38, 54)
;连接虚拟磁盘
DllCall("Kernel32.dll", "long", "DeviceIoControl", "long", $hDrvHandle, "long", 2244608, "ptr", DllStructGetPtr($szin), "long", 54, "ptr", DllStructGetPtr($szout), "long", 4, "int*", 0, "ptr", 0)
EndFunc
|
|