Jump to content

Recommended Posts

Posted

Hello, today i already asked for help ( http://www.autoitscript.com/forum/index.php?showtopic=104204 ) but it seemed like my topic got inactive or whatever.. well i did some searching and found a script whhich didnt work. As i didnt found any other solution (there rly isnt any script or batch file or little .exe file) i thought i would try to fix the script which i found.

The script i found seems to work fine on win200/xp with english os.

I got win7 (english) and need to port this script into win7.

orig. script:

; Disable and Enable a Network card using 'Shell.Application'
;
; See also: http://blog.mvpcn.net/icuc88/articles/244.aspx
;
; To do: Rewrite this into a UDF. Parameters: $oLanConnection and $bEnabled


$oLanConnection = "Local Area Connection"; Change this to the name of the adapter to be disabled !
$bEnable = true             ; Change this to 'false' to DISABLE the network adapter

if @OSType<>"WIN32_NT" then
    Msgbox(0,"","This script requires Windows 2000 or higher.")
    exit
endif


if @OSVersion="WIN_2000" then
    $strFolderName = "Network and Dial-up Connections"
else
    $strFolderName = "Network Connections"; Windows XP
endif

Select 
    Case StringInStr("0409,0809,0c09,1009,1409,1809,1c09,2009,2409,2809,2c09,3009,3409", @OSLang) ; English (United States)
       $strEnableVerb  = "En&able"
       $strDisableVerb = "Disa&ble"

; Add here the correct Verbs for your Operating System Language
EndSelect


;Virtual folder containing icons for the Control Panel applications. (value = 3)
Const $ssfCONTROLS = 3 

$ShellApp = ObjCreate("Shell.Application")
$oControlPanel = $shellApp.Namespace($ssfCONTROLS)


; Find 'Network connections' control panel item
$oNetConnections=""

For $FolderItem in $oControlPanel.Items
    If $FolderItem.Name = $strFolderName then
        $oNetConnections = $FolderItem.GetFolder
        Exitloop
    Endif
Next

      
If not IsObj($oNetConnections) Then
    MsgBox(0,"Error","Couldn't find " & $strFolderName & " folder." )
    Exit
EndIf
        

For $FolderItem In $oNetConnections.Items
    If StringLower($FolderItem.Name) = StringLower($oLanConnection) Then
        $oLanConnection = $FolderItem
        Exitloop
    EndIf
Next

If not IsObj($oLanConnection) Then
     MsgBox(0,"Error","Couldn't find " & $oLanConnection & " Item." )
     Exit
EndIf

$oEnableVerb=""
$oDisableVerb=""

For $Verb In $oLanConnection.Verbs
 If $Verb.Name = $strEnableVerb Then
   $oEnableVerb = $Verb
 EndIf
 If $Verb.Name = $strDisableVerb Then
   $oDisableVerb = $Verb
 EndIf
Next

If $bEnable then
 If IsObj($oEnableVerb) Then $oEnableVerb.DoIt  ; Enable network card
Endif

If not $bEnable then
 If IsObj($oDisableVerb) Then $oDisableVerb.DoIt; Disable network card
EndIf

Sleep(1000)

now what is wrong? The control panel of win2000/xp is different from win7 and i get the errors about "didnt found network folder" or "didnt found adapter".

I managed to check for the "network and sharing" folder.. but i dont know how to check in the "change adapter settings" folder (there is the adapter for enable/disable).

; Disable and Enable a Network card using 'Shell.Application'
;
; See also: http://blog.mvpcn.net/icuc88/articles/244.aspx
;
; To do: Rewrite this into a UDF. Parameters: $oLanConnection and $bEnabled


$oLanConnection = "VMware Network Adapter VMnet1"; Change this to the name of the adapter to be disabled !
$bEnable = true             ; Change this to 'false' to DISABLE the network adapter

if @OSType<>"WIN32_NT" then
    Msgbox(0,"","This script requires Windows 2000 or higher.")
    exit
endif

$change = "Change adapter settings"

if @OSVersion="WIN_2000" then
  ;  $strFolderName = "Network and Dial-up Connections"
    $strFolderName = "Network and Sharing Center"
else
   ; $strFolderName = "Network Connections"; Windows XP
    $strFolderName = "Network and Sharing Center"
endif

Select 
    Case StringInStr("0409,0809,0c09,1009,1409,1809,1c09,2009,2409,2809,2c09,3009,3409", @OSLang) ; English (United States)
       $strEnableVerb  = "En&able"
       $strDisableVerb = "Disa&ble"

; Add here the correct Verbs for your Operating System Language
EndSelect


;Virtual folder containing icons for the Control Panel applications. (value = 3)
Const $ssfCONTROLS = 3 

$ShellApp = ObjCreate("Shell.Application")
$oControlPanel = $shellApp.Namespace($ssfCONTROLS)


; Find 'Network connections' control panel item
$oNetConnections=""

For $FolderItem in $oControlPanel.Items
    If $FolderItem.Name = $strFolderName then
        $oNetConnections = $FolderItem.GetFolder
        Exitloop
    Endif
Next

      
If not IsObj($oNetConnections) Then
    MsgBox(0,"Error","Couldn't find " & $strFolderName & " folder." )
    Exit
EndIf


For $FolderItem in $oControlPanel.Items
    If $FolderItem.Name = $change then
        $oNetConnections = $FolderItem.GetFolder
        Exitloop
    Endif
Next
        

If not IsObj($oNetConnections) Then
    MsgBox(0,"Error","Couldn't find " & $change & " menu." )
    Exit
EndIf

For $FolderItem In $oNetConnections.Items
    If StringLower($FolderItem.Name) = StringLower($oLanConnection) Then
        $oLanConnection = $FolderItem
        Exitloop
    EndIf
Next

If not IsObj($oLanConnection) Then
     MsgBox(0,"Error","Couldn't find " & $oLanConnection & " Item." )
     Exit
EndIf

$oEnableVerb=""
$oDisableVerb=""

For $Verb In $oLanConnection.Verbs
 If $Verb.Name = $strEnableVerb Then
   $oEnableVerb = $Verb
 EndIf
 If $Verb.Name = $strDisableVerb Then
   $oDisableVerb = $Verb
 EndIf
Next

If $bEnable then
 If IsObj($oEnableVerb) Then $oEnableVerb.DoIt  ; Enable network card
Endif

If not $bEnable then
 If IsObj($oDisableVerb) Then $oDisableVerb.DoIt; Disable network card
EndIf

Sleep(1000)

please help me to port this for win7 (should be same as vista) cause there isnt any other solution for me :)

thanks

Posted

no one? :/

i asked a friend and he recommended me to use contro click.. however -> it still doesnt work :) also i´m not sure how to make it

; Disable and Enable a Network card using 'Shell.Application'
;
; See also: http://blog.mvpcn.net/icuc88/articles/244.aspx
;
; To do: Rewrite this into a UDF. Parameters: $oLanConnection and $bEnabled


$oLanConnection = "VMware Network Adapter VMnet1"; Change this to the name of the adapter to be disabled !
$bEnable = true             ; Change this to 'false' to DISABLE the network adapter

if @OSType<>"WIN32_NT" then
    Msgbox(0,"","This script requires Windows 2000 or higher.")
    exit
endif

$change = "Change adapter settings"

if @OSVersion="WIN_2000" then
  ;  $strFolderName = "Network and Dial-up Connections"
    $strFolderName = "Network and Sharing Center"
else
   ; $strFolderName = "Network Connections"; Windows XP
    $strFolderName = "Network and Sharing Center"
endif

Select 
    Case StringInStr("0409,0809,0c09,1009,1409,1809,1c09,2009,2409,2809,2c09,3009,3409", @OSLang) ; English (United States)
       $strEnableVerb  = "En&able"
       $strDisableVerb = "Disa&ble"

; Add here the correct Verbs for your Operating System Language
EndSelect


;Virtual folder containing icons for the Control Panel applications. (value = 3)
Const $ssfCONTROLS = 3 

$ShellApp = ObjCreate("Shell.Application")
$oControlPanel = $shellApp.Namespace($ssfCONTROLS)


; Find 'Network connections' control panel item
$oNetConnections=""

For $FolderItem in $oControlPanel.Items
    If $FolderItem.Name = $strFolderName then
        $oNetConnections = $FolderItem.GetFolder
        Exitloop
    Endif
Next

      
If not IsObj($oNetConnections) Then
    MsgBox(0,"Error","Couldn't find " & $strFolderName & " folder." )
    Exit
EndIf


For $FolderItem in $oControlPanel.Items
    If $FolderItem.Name = $change then
        $oNetConnections = $FolderItem.GetFolder
        Exitloop
    Endif
Next
        ControlClick("Network and Sharing Center", "", "[CLASS:DirectUIHWND; INSTANCE:3]")

If not IsObj($oNetConnections) Then
    MsgBox(0,"Error","Couldn't find " & $change & " menu." )
    Exit
EndIf

For $FolderItem In $oNetConnections.Items
    If StringLower($FolderItem.Name) = StringLower($oLanConnection) Then
        $oLanConnection = $FolderItem
        Exitloop
    EndIf
Next

If not IsObj($oLanConnection) Then
     MsgBox(0,"Error","Couldn't find " & $oLanConnection & " Item." )
     Exit
EndIf

$oEnableVerb=""
$oDisableVerb=""

For $Verb In $oLanConnection.Verbs
 If $Verb.Name = $strEnableVerb Then
   $oEnableVerb = $Verb
 EndIf
 If $Verb.Name = $strDisableVerb Then
   $oDisableVerb = $Verb
 EndIf
Next

If $bEnable then
 If IsObj($oEnableVerb) Then $oEnableVerb.DoIt  ; Enable network card
Endif

If not $bEnable then
 If IsObj($oDisableVerb) Then $oDisableVerb.DoIt; Disable network card
EndIf

Sleep(1000)
  • 4 weeks later...
Posted (edited)

dunno if devcon works in w7, but worth a try, take a look here:

http://en.kioskea.net/faq/sujet-1886-enable-disable-a-device-from-the-command-line

This is the folder containing network adapters, the same in xp to win7

'explorer /SEPARATE,::{7007ACC7-3202-11D1-AAD2-00805FC1270E}'

Edited by revertex
  • 4 years later...
Posted (edited)

I have a script and a manipulation to make it work on W7. Send me a mail at (alexis.richard  at   etu.u-bordeaux1  .  fr), i'll tell you what to do (don't expect for an answer in the week, mail me only if you're truly desperate...)

Edited by Jos
changed email
  • Developers
Posted (edited)

Do you think the OP will still be waiting on an answer after 4 years?

Changed to real Email address so it is less likely to be caught by a spambot.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

Sorry for the mistake. Also, i searched for such a script 4 years after him, maybe someone will want a full working one someday. (thanks for editing, i didn't think about it while writing)

Posted (edited)

I use this vbs script:

http://web.archive.org/web/20131017211745/http://www.bluemoonpcrepair.com/wp/?cat=51

The website is down, but the wayback machine has a cached copy.

The direct links to the exe and vbs files seem to work:

http://www.bluemoonpcrepair.com/software/scripts/WirelessDisableOnLAN.exe

http://www.bluemoonpcrepair.com/software/scripts/WirelessDisableOnLAN.vbs

Edited by GPinzone
Gerard J. Pinzonegpinzone AT yahoo.com

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...