回复 11# pingguo002
找到解決方法
給你一個 列出 區網所有 MSSQL 主機的 語法
至於 這台主機裡面是否有你要的資料庫 這個部分 還得自己在修改
#include <Array.au3>
$aCompList2 = _netwerklist(0x4)
TCPStartup()
DIM $aCompList3[UBound($aCompList2)][2]
FOR $i=1 TO UBound($aCompList2)-1 Step 1
$aCompList3[$i][0]=$aCompList2[$i]
$aCompList3[$i][1]=TCPNameToIP($aCompList2[$i])
Next
TCPShutdown()
_ArrayDisplay($aCompList3)
Func _netwerklist($iSrvType = -1, $sDomain = '')
Local $uBufPtr = DllStructCreate("ptr;int;int"), $res[1] = [0], $i
Local $uRecord = DllStructCreate("dword;ptr"), $iRecLen = DllStructGetSize($uRecord)
Local $uString = DllStructCreate("char[16]")
Local $uDomain = DllStructCreate("byte[32]"), $pDomain = 0
If Not ($sDomain = '' Or $sDomain = '*') Then
DllStructSetData($uDomain, 1, StringToBinary($sDomain, 2))
$pDomain = DllStructGetPtr($uDomain)
EndIf
Local $ret = DllCall("netapi32.dll", "int", "NetServerEnum", _
"ptr", 0, "int", 100, _
"ptr", DllStructGetPtr($uBufPtr, 1), "int", -1, _
"ptr", DllStructGetPtr($uBufPtr, 2), _
"ptr", DllStructGetPtr($uBufPtr, 3), _
"int", $iSrvType, "ptr", $pDomain, "int", 0)
If $ret[0] Then Return SetError(1, $ret[0], '')
Local $res[DllStructGetData($uBufPtr, 3) + 1] = [DllStructGetData($uBufPtr, 3)]
For $i = 1 To DllStructGetData($uBufPtr, 3)
Local $uRecord = DllStructCreate("dword;ptr", DllStructGetData($uBufPtr, 1) + ($i - 1) * $iRecLen)
Local $sNBName = DllStructCreate("byte[32]", DllStructGetData($uRecord, 2))
DllStructSetData($uString, 1, BinaryToString(DllStructGetData($sNBName, 1), 2))
$res[$i] = DllStructGetData($uString, 1)
Next
$ret = DllCall("netapi32.dll", "int", "NetApiBufferFree", "ptr", DllStructGetData($uBufPtr, 1))
Return $res
EndFunc ;==>_netwerklist
|