Jump to content

Switch ICS


Recommended Posts

Hi,

i want to write a script that can switch ics on and off for my internet connection.

I searched but cant find a dll or an Objekt for doing this. :D

I tried to find a reg key with regmon. I set the filter to explorer.exe but i get a mass of reads and writes.

Does somone know how to do this?

Edited by Matrix112
Link to comment
Share on other sites

  • Moderators

I can't test it, but this should work:

_EnableDisableICS("YourConnectionName", True) ; true enables, false disables

Func _EnableDisableICS($sConnectionName, $bEnable)
    
    Local $bFound = False
    
    $oNetSharingManager = ObjCreate("HNetCfg.HNetShare.1")
    If Not IsObj($oNetSharingManager) Then
        MsgBox(48, "Error", "Unable to get the HNetCfg.HnetShare.1 object.")
        Exit
    EndIf
    
    If Not $oNetSharingManager.SharingInstalled Then
        MsgBox(48, "Error", "Sharing is not available on this platform.")
        Exit
    EndIf
    
    $oConnectionCollection = $oNetSharingManager.EnumEveryConnection
    For $oItem In $oConnectionCollection
        $EveryConnection = $oNetSharingManager.INetSharingConfigurationForINetConnection ($oItem)
        $objNCProps = $oNetSharingManager.NetConnectionProps ($oItem)
        
        If $objNCProps.name = $sConnectionName Then
            $bFound = True
            MsgBox(0, "Info", "Setting ICS to " & $bEnable & " on connection: " & $objNCProps.name)
            If $bEnable Then
                $EveryConnection.EnableSharing (0)
            Else
                $EveryConnection.DisableSharing
            EndIf
        EndIf
    Next
    
    If Not $bFound Then
        MsgBox(48, "Error", 'Unable to find the connection "' & $sConnectionName & '"')
    EndIf
    
EndFunc   ;==>_EnableDisableICS

Edit: forgot to tidy

Edited by big_daddy
Link to comment
Share on other sites

Thx for help. :D

I tried it, but get following Autoit Error: The requested action with this object has failed.

I searched it in object viewer and found it. But i dont know what is wrong.

Edit: Ok i have now recreated internetconnection and it works, but after i get Error from Autoit.

$EveryConnection = $oNetSharingManager.INetSharingConfigurationForINetConnection ($oItem)

$EveryConnection = $oNetSharingManager.INetSharingConfigurationForINetConnection ($oItem)^ERROR

Error: The requested action with this object has failed.

Edited by Matrix112
Link to comment
Share on other sites

  • Moderators

Thx for help. :D

I tried it, but get following Autoit Error: The requested action with this object has failed.

I searched it in object viewer and found it. But i dont know what is wrong.

Edit: Ok i have now recreated internetconnection and it works, but after i get Error from Autoit.

$EveryConnection = $oNetSharingManager.INetSharingConfigurationForINetConnection ($oItem)

$EveryConnection = $oNetSharingManager.INetSharingConfigurationForINetConnection ($oItem)^ERROR

Error: The requested action with this object has failed.

I'm not going to pretend to understand all this script, I just converted it from vb. I tested it lastnight on my pc and it worked without error for me. Make sure you are running the latest beta, and see if that helps.
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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