Sign in to follow this  
Followers 0
Matrix112

Switch ICS

6 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
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.

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.

Share this post


Link to post
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
Sign in to follow this  
Followers 0