Re: jak włączyć/wyłączyć kartę/interfejs sieciowy skryptem/pojedyńczym skrótem?

Autor: pan anatol <webmaster_at_tudorfloor.comCIACHCIACH.pl>
Data: Thu 21 Dec 2006 - 04:03:39 MET
Message-ID: <6ec065808d88d62f0eac71b5f9aeaa3a@news.home.net.pl>
Content-Type: text/plain; charset="iso-8859-2"

"pan anatol" <webmaster@tudorfloor.comCIACHCIACH.pl> napisał(a):
> witam
>
> chciałem sobie ułatwić życie i włączać/wyłączać kartę sieciową
> pojedynczym
> skrótem a nie przez klikanie w menedżerze urządzeń/połączeniach
> sieciowych
> próbowałem polecenia netsh ale nie do końca chce mi to działać...
> gdzieś znalazlem taką składnie:
> netsh int set interface name="Internet" admin=disabled
> ale wybija mi błąd. :(
> znalazlem jeszcze jeden programik od MS; DevCon
> http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272
> ale jego składnia mnie przeraża, pozatym można nim całkiem pięknie sie
> załatwić na cacy ;[
>
> thanks in advance

ok, po *dłuższym* szukaniu znalazłem skrypta który robi dokładnie to co
chcę:
mam nadzieje że sprzyda się innym tak jak i mnie dobrze służy :)

Rem ======== ToggleLanConnection.vbs ========

Const ssfCONTROLS = 3

sConnectionName = "Internet"

sEnableVerb = "&Włącz"
sDisableVerb = "&Wyłącz"

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

set oNetConnections = nothing
for each folderitem in oControlPanel.items
  if folderitem.name = "Połączenia sieciowe" then
    set oNetConnections = folderitem.getfolder: exit for
  end if
next

if oNetConnections is nothing then
  msgbox "Couldn't find 'Połączenia sieciowe' 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

Rem ==========================================================
Received on Thu Dec 21 04:05:12 2006

To archiwum zostało wygenerowane przez hypermail 2.1.8 : Thu 21 Dec 2006 - 04:42:04 MET