Jump to content

get all dial up connection names


Recommended Posts

Hi all,

I would like to make a script that will be able to reconnect in case of disconnection, but in order to do so, I need to retrieve all dial up connection names, so how can this be done?

Another question is about reconnecting, I'm familiar with rasdial tool, but in order to reconnect with rasdial, user must input his username and password of his dial up connection, so can this be avoided? Is it possible to make silent connection without using rasdial?

Thank you.

Link to comment
Share on other sites

Sven wrote this. It wasn't working for me so I tried to fix it. It's almost there but the ".Items" part on line 100 is wrong.

#include-once
Opt("MustDeclareVars", 1)
Global $ret

$ret = _ConnectionAction("AT&T Connection Service", "Status", "Network Connections")
MsgBox(0, "", "@error:"&@error&@CR&"@extended:"&@extended&@CR&"$ret:"&$ret)
;==================================================================================================
;
; Func Name:    _ConnectionAction
; Purpose:      Performs an action on a Network Connections folder item
; Syntax:
;               #include svenConnections.au3
;               _ConnectionAction(strConnectionName, intAction)
; Parameters:
;               strConnectionName = The name of the connection as it appears under the 
;                   control panel applet containing the machine's available connections.
;               strAction = One of the following ...
;                   "Dis&connect" - if passed, this function disconnects the connection
;                   "C&onnect" - if passed, this function connects the connection
;                   "Disa&ble" - if passed, the connection is disabled.
;                   "En&able" - if passed, the connection is enabled.
;                   "Status" - if passed, the Status of the connection is returned ("Disabled, Firewalled", "Connected, Firewalled", ...)
;                   "Stat&us" - if passed, the Status dialog is opened.
;                   "Create &Shortcut" - if passed, the Create Shortcut dialog is opened.
;                   "Create &Copy" - if passed, a copy of the connection folder item will be created.
;                   "P&roperties" - if passed, the Properties dialog for the connection is opened.
;                   "Type" - if passed, the type of connection is returned ("Dial-up", or "LAN...").
;                   "Set as De&fault Connection" - the connection is set as the default.
;                   "&Delete" - if passed, the connection folder item is deleted.
;                   "Device Name" - if this is passed, the function returns the name of the device.
;                   "Phone # or Host Address" - if passed, this information is returned.
;                   "Rena&me" - if passed, an attempt is made to rename the connection.
;                   Any other verb known to be available for the connection; be sure to include
;                       an ampersand before any letter that is an assigned keyboard navigation key 
;                       (for details on this issue, look under Control Panel > Display Properties >
;                       Appearance tab > Effects button > Hide underlined letters...)
;               strNetworkConnectionsFoldername - the control panel applet containing the machine's 
;                   available connections (default = "Network Connections" or 
;                   "Network and Dial-up Connections" depending on the value of @OSVersion)
; Returns:
;               Success - 1; @error = 0
;               Failure - 0; @error set as follows ...
;                   1 - The passed verb is not currently available for the connection.
;                   2 - Unable to find the connection under Control Panel.
;                   3 - Unable to create the Control Panel folder object.
;                   4 - Unable to create the Control Panel folder object.
;                   5 - The function was called on a system that is not a modern versions of Windows.
; Notes:
;               See also: http://blog.mvpcn.net/icuc88/articles/244.aspx
; AutoIt:       v3.2.12.0
; Authors:      Sven, Squirrely1
;==================================================================================================
Func _ConnectionAction($s_ConnectionName, $s_Action, $s_NetConnFolder = "")
    Local Const $ssfCONTROLS = 3;Virtual folder containing icons for the Control Panel applications. (value = 3)
    Local $oShell, $oCtrlPanel, $oNetConnFolder
    Local $oFolderItem, $oConnection, $oVerb
    Local $atError = True
    ;
    If @OSTYPE = "WIN32_WINDOWS" Then; Windows type = 95/98/Me
        Return SetError(5, 0, 0)
    EndIf
    ;
    ; Set the name of the default Network Connections folder if needed ...
    If $s_NetConnFolder = "" Then
        If @OSVersion = "WIN_2000" Then
            $s_NetConnFolder = "Network and Dial-up Connections"
        Else
            $s_NetConnFolder = "Network Connections"; Windows XP
        EndIf
    EndIf
    ;
    ; Get the Control Panel as an object if possible ...
    $oShell = ObjCreate("Shell.Application")
    $oCtrlPanel = $oShell.Namespace($ssfCONTROLS)
    If Not IsObj($oCtrlPanel) Then
        Return SetError(4, 0, 0)
    EndIf
    ;
    ; Get the Network Connections folder as an object if possible ...
    For $oFolderItem In $oCtrlPanel.Items
        If String($oFolderItem.Name) = $s_NetConnFolder Then
            $oNetConnFolder = $oFolderItem
            ExitLoop
        EndIf
    Next
    If Not IsObj($oNetConnFolder) Then
        $oShell = 0
        $oCtrlPanel = 0
        $oFolderItem = 0
        Return SetError(3, 0, 0)
    EndIf
    ;
    ; Get the connection as an object if possible ...
    For $oFolderItem In $oNetConnFolder
        If StringLower($oFolderItem.Name) = StringLower($s_ConnectionName) Then
            $oConnection = $oFolderItem
            ExitLoop
        EndIf
    Next
    $oConnection = $oNetConnFolder.Item($s_NetConnFolder)
    If Not IsObj($oConnection) Then
        $oShell = 0
        $oCtrlPanel = 0
        $oNetConnFolder = 0
        $oFolderItem = 0
        Return SetError(2, 0, 0)
    EndIf
    ;
    ;   Invoke the passed verb if it exists in the collection of verbs ...
    Select
        Case $s_Action = "Status"
            Return $oConnection.Status
;           $oCollection = $oConnection.Properties
        Case $s_Action = "Type"
;           $oCollection = $oConnection.Properties
        Case $s_Action = "Device Name"
;           $oCollection = $oConnection.Properties
        Case $s_Action = "Phone # or Host Address"
;           $oCollection = $oConnection.Properties
        Case Not StringInStr($s_Action, "&")
;           $oCollection = $oConnection.Properties
        Case Else
;           $oCollection = $oConnection.Verbs
            For $oVerb In $oConnection.Verbs
                If $oVerb.Name = $s_Action Then
                    $oVerb.DoIt
                    $atError = False
                    ExitLoop
                EndIf
            Next
            $oVerb = 0
    EndSelect
    ;
    ; Release objects ...
    $oShell = 0
    $oCtrlPanel = 0
    $oNetConnFolder = 0
    $oFolderItem = 0
    $oConnection = 0
    $oVerb = 0
    ;
    ; Set returns ...
    If $atError Then
        Return SetError(1, 0, 0)
    Else
        Return SetError(0, 0, 1)
    EndIf
EndFunc
Edited by Squirrely1

Das Häschen benutzt Radar

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...