怎么检测网络连接的名称?
本帖最后由 redapple2008 于 2009-8-29 07:58 编辑怎么检测网络连接的名称? 如何在程序中获得网络连接的名称,如:本地连接、本地连接1、本地连接2 $var = Ping("www.autoitx.com")
If $var Then
TrayTip("访问Autoit软件专题站正常","本机已接入互联网,Ping返回值=" & $var,10,1)
Sleep(1200)
Else
Msgbox(16,"网络链接失败","请首先链接互联网,错误代码=" & @error)
Exit
EndIf @echo off
@Setlocal ENABLEDELAYEDEXPANSION
@set reg_path_id=
@set reg_path=
@set nic_id=
@set nic_name=
@for /f "usebackq tokens=7 delims=\" %%i in (`reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards"`) do (
set reg_path_id=%%i
set "reg_path=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\!reg_path_id!"
for /f "usebackq tokens=3" %%j in (`"reg query "!reg_path!" | find /i "ServiceName""`) do (
set NIC_id=%%j
for /f "usebackq skip=2 tokens=3" %%k in (`reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters\Interfaces\!nic_id!" /v NTEContextList`) do (if not "%%k" == "\0" (Goto :nic_name))
))
Goto :EOF
:nic_name
@if exist %temp%\reg.temp (del /q %temp%\reg.temp >nul)
@reg export "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\%nic_id%\Connection" %temp%\reg.temp >nul
for /f "usebackq tokens=2 delims==" %%l in (`find /i "Name" %temp%\reg.temp`) do (
set nic_name=%%l
set nic_name=!nic_name:"=!
)
@if exist %temp%\reg.temp (del /q %temp%\reg.temp >nul)
echo 您的网卡连接名称为:%nic_name%
pause>nul 如同上面批处理运行的结果。 MprConfigInterfaceEnum
http://msdn.microsoft.com/en-us/library/aa375862(VS.85).aspx MprConfigInterfaceEnum
http://msdn.microsoft.com/en-us/library/aa375862(VS.85).aspx
pusofalse 发表于 2009-8-29 00:08 http://www.autoitx.com/images/common/back.gif
C++看不懂呀! 希望有人能更改批处理为我所用。 WMI的Win32_NetworkAdapter,NetConnectionID应该也可以。 #include <Array.au3>
CONST $tagMPRINTERFACE0 = "wchar Name;ptr Interface;int Enabled;int IfType;int State;dword UnreachabilityReasons;dword LastError"
$aInterface = _MprConfigInterfaceEnum()
_Arraydisplay($aInterface)
Func _MprConfigInterfaceEnum($sSystem = @ComputerName)
Local $hMprCfg, $aResult = [], $tMPR, $pMPR
$hMprCfg = _MprConfigServerConnect($sSystem)
If $hMprCfg = 0 Then Return SetError(@error, 0, $aResult)
$iResult = DllCall("Mprapi.dll", "long", "MprConfigInterfaceEnum", _
"long", $hMprCfg, "dword", 0, "ptr*", 0, "dword", -1, _
"dword*", 0, "dword*", 0, "dword*", 0)
$pMPR = $iResult
$aResult = $iResult
Redim $aResult[$iResult + 1]
For $i = 1 to $iResult
$tMPR = DllStructCreate($tagMPRINTERFACE0, $iResult)
$aResult[$i] = DllStructGetData($tMPR, "Name")
$aResult[$i] = _MprConfigGetFriendlyName($hMprCfg, $aResult[$i])
$aResult[$i] = DllStructGetData($tMPR, "Enabled")
$aResult[$i] = DllStructGetData($tMPR, "IfType")
$iResult += DllStructGetSize($tMPR)
Next
_MprConfigBufferFree($pMPR)
_MprConfigServerDisconnect($hMprCfg)
Return SetError($iResult, 0, $aResult)
EndFunc ;==>_MprConfigInterfaceEnum
Func _MprConfigServerConnect($sSystem = @ComputerName)
Local $hMprCfg
If $sSystem = "" Then $sSystem = @ComputerName
$hMprCfg = DllCall("Mprapi.dll", "long", "MprConfigServerConnect", _
"wstr", @ComputerName, "long*", 0)
Return SetError($hMprCfg, 0, $hMprCfg)
EndFunc ;==>_MprConfigServerConnect
Func _MprConfigBufferFree($pBuffer)
Local $iResult
$iResult = DllCall("Mprapi.dll", "long", "MprConfigBufferFree", "ptr", $pBuffer)
Return $iResult = 0
EndFunc ;==>_MprConfigBufferFree
Func _MprConfigServerDisconnect($hMprCfg)
DllCall("Mprapi.dll", "none", "MprConfigServerDisconnect", "long", $hMprCfg)
EndFunc ;==>_MprConfigServerDisconnect
Func _MprConfigGetFriendlyName($hMprCfg, $sGUID)
Local $iResult
$iResult = DllCall("Mprapi.dll", "long", "MprConfigGetFriendlyName", _
"long", $hMprCfg, "wstr", $sGUID, "wstr", "", "int", 128)
Return $iResult
EndFunc ;==>_MprConfigGetFriendlyName
#include
CONST $tagMPRINTERFACE0 = "wchar Name;ptr Interface;int Enabled;int IfType;int State;dword UnreachabilityReasons;dword LastError"
$aInterface = _MprConfigInterfaceEnum()
_Arraydisp ...
pusofalse 发表于 2009-8-29 03:23 http://www.autoitx.com/images/common/back.gif
测试正确.谢谢了. 正在研究中....................... 提不出来本地连接的变量. Re 13#:
说话不要说到一半好吧。你在11#说测试正确,又在13#说提取不到?那代码到底可不可以啊?另外,本地连接的变量是怎样的?不是要提取“本地连接”、“本地连接2”吗? Re 13#:
说话不要说到一半好吧。你在11#说测试正确,又在13#说提取不到?那代码到底可不可以啊?另外,本地连接的变量是怎样的?不是要提取“本地连接”、“本地连接2”吗?
pusofalse 发表于 2009-8-30 23:41 http://www.autoitx.com/images/common/back.gif
是要提取“本地连接”、“本地连接2”吗?
页:
[1]