프로그래밍 방식으로 사용/사용 안 함 네트워크 인터페이스가?(Windows XP)

StackOverflow https://stackoverflow.com/questions/83756

  •  01-07-2019
  •  | 
  •  

문제

필요를 활성화/비활성화하는 완전히 네트워크 인터페이스에서는 스크립트는 Windows XP.내가 찾는 것이 솔루션이지만,모든 일반적인 방법으로(예를 들어 컨트롤 일부 명령줄 à la netsh,일부 창출)이 환영합 및 조정됩니다.감사합니다.

도움이 되었습니까?

해결책

를 사용하여 이 문서는 아직 인터페이스 사용량이 설정한 인터페이스[name=]IfName [[관리자=]비활성화|활성화 [연결=]연결|연결이 끊어 [newname=]NewName]

도 모든 것을 포함하여 외부 괄호:netsh 인터페이스트 인터페이스 name="이름"admin=장애인 연결=연결이 끊어 newname="이름"

또한 이 MS KB 페이지: http://support.microsoft.com/kb/262265/ 당신을 따를 수 있는 하나의 제공됩니다.비활성화에 대한 어댑터가 필요 결정하는 방법을 참조 하드웨어 장치.는 경우에 없을 것이 여러 어댑터 같은 이름을 가진 컴퓨터에서,당신은 수 있는 가능성의 설명에 대한 인터페이스(또는 PCI ID 잘 작동하).그 후,사용하 devcon(사용|사용 안함).Devcon 는 추가 콘솔에서 인터페이스는 장치에 대한 관리자입니다.

다른 팁

지금까지 내가 찾은 다음과 같은 Python 솔루션:

>>> import wmi; c=wmi.WMI()
>>> o=c.query("select * from Win32_NetworkAdapter where NetConnectionID='wifi'")[0]
>>> o.EnableDevice(1)
(-2147217407,)

번역되는,AFAIU,일반 WMI 오류 0x80041001.될 수 있는 권한이 있습니다.

할 수 있습니다.VBS 스크립트 인터넷에 있습니다.그것은 멋진 장점을 실제로 작동하는 컴퓨터에서 어디를 구할 수 없습니다 NETSH 이 목적입니다.

Const ssfCONTROLS = 3 

sConnectionName = "Local Area Connection" 

sEnableVerb = "En&able" 
sDisableVerb = "Disa&ble" 

set shellApp = createobject("shell.application") 
set oControlPanel = shellApp.Namespace(ssfCONTROLS) 

set oNetConnections = nothing 
for each folderitem in oControlPanel.items 
  if folderitem.name = "Network Connections" then 
        set oNetConnections = folderitem.getfolder: exit for 
end if 
next 

if oNetConnections is nothing then 
msgbox "Couldn't find 'Network Connections' folder" 
wscript.quit 
end if 

set oLanConnection = nothing 
for each folderitem in oNetConnections.items 
if lcase(folderitem.name) = lcase(sConnectionName) then 
set oLanConnection = folderitem: exit for 
end if 
next 

if oLanConnection is nothing then 
msgbox "Couldn't find '" & sConnectionName & "' item" 
wscript.quit 
end if 

bEnabled = true 
set oEnableVerb = nothing 
set oDisableVerb = nothing 
s = "Verbs: " & vbcrlf 
for each verb in oLanConnection.verbs 
s = s & vbcrlf & verb.name 
if verb.name = sEnableVerb then 
set oEnableVerb = verb 
bEnabled = false 
end if 
if verb.name = sDisableVerb then 
set oDisableVerb = verb 
end if 
next 

'debugging displays left just in case... 
' 
'msgbox s ': wscript.quit 
'msgbox "Enabled: " & bEnabled ': wscript.quit 

'not sure why, but invokeverb always seemed to work 
'for enable but not disable. 
' 
'saving a reference to the appropriate verb object 
'and calling the DoIt method always seems to work. 
' 
if bEnabled then 
' oLanConnection.invokeverb sDisableVerb 
oDisableVerb.DoIt 
else 
' oLanConnection.invokeverb sEnableVerb 
oEnableVerb.DoIt 
end if 

'adjust the sleep duration below as needed... 
' 
'if you let the oLanConnection go out of scope 
'and be destroyed too soon, the action of the verb 
'may not take... 
' 
wscript.sleep 1000

나는 찾을 수 없는 것이 어떤 기본적인 API 를 제어하기 위한 인터페이스에 MSDN 서 RAS API,하지 않다고 생각에 적용되는 비 전화 연결이 있습니다.당신이 제안하는대로 자신 netsh 옵션이 될 수 있습니다,아마도 그것은 또한 프로그래밍 인터페이스: http://msdn.microsoft.com/en-us/library/ms708353(VS.85).aspx

하려는 경우에는 순수한 Python,당신은 아마도 오픈 파이프의 집합과 소통하는 netsh 과정입니다.

이 VB.Net

Dim objectQuery As New ObjectQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionId IS NOT NULL")
         Dim searcher As New ManagementObjectSearcher(scope, objectQuery)
         Dim os As ManagementObject
         Dim moColl As ManagementObjectCollection = searcher.Get()
         Dim _list As String = ""
         For Each os In moColl
             Console.WriteLine(os("NetConnectionId"))
         Next os

는 것입니다 모든 인터페이스에서 당신이 컴퓨터입니다.다음을 할 수 있는 netsh 을 사용하지 않도록 설정합니다.

netsh 인터페이스트 인터페이스 장애인

devcon 도구를 제어할 수 있는 NIC,하지만 직접 인터페이스.그것은 명령줄 버전의 장치 관리자 어플리케이션도 있습니다..

devcon disable (id or portion of name)
devcon enable (id or portion of name)

를 사용해야 할 수 있습니다 WMI.이 역할을 수 있는 좋은 출발점:http://msdn.microsoft.com/en-us/library/aa394595.aspx

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top