Jump to content

Display multiple WMI variables in GUI


PnoT
 Share

Recommended Posts

I'm building a GUI tech support tool for our users and I'm pretty new, compared to other, to AutoIT and would appreciate some help.

Here is what i have so far:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=h:\autoit3\autoit scripts\form1.kxf
$Form1_1 = GUICreate("MYIT Support Tool", 500, 497, 275, 216)
$Group1 = GUICtrlCreateGroup("Computer Status", 8, 8, 330, 481)
$Label1 = GUICtrlCreateLabel("IPs:", 26, 31, 26, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label10 = GUICtrlCreateLabel(@IPAddress1 & "  -  " & @IPAddress2 & "  -  " & @IPAddress3 & "  -  " & @IPAddress4, 60, 32, 260, 21)

;--- Ping results section---
$Label3 = GUICtrlCreateLabel("Ping Status", 24, 96, 69, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("Server", 32, 128, 41, 17)
$ping = ping("server3",250)
If @error = 0 Then
    GUICtrlCreateLabel("OK", 110, 128, 22, 21)
Else
    GUICtrlCreateLabel("FAILED", 110, 128, 22, 21)
EndIf
$Label4 = GUICtrlCreateLabel("Server2", 32, 152, 59, 17)
$ping2 = ping("lasadserv2",250)
If @error = 0 Then
    GUICtrlCreateLabel("OK", 110, 152, 22, 21)
Else
    GUICtrlCreateLabel("FAILED", 110, 152, 22, 21)
EndIf

;--- Computer Information Section---
$Label5 = GUICtrlCreateLabel("Information", 24, 216, 67, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label6 = GUICtrlCreateLabel("User:", 32, 256, 29, 17)
$lable11 = GUICtrlCreateLabel(@LogonDomain & "\" & @UserName, 130, 256, 200, 40)
$Label7 = GUICtrlCreateLabel("Computer Name:", 32, 288, 83, 17)
$lable12 = GUICtrlCreateLabel(@ComputerName, 130, 288, 200, 40)
$Label8 = GUICtrlCreateLabel("Domain Controller", 32, 320, 87, 17)
$lable13 = GUICtrlCreateLabel(@LogonServer, 130, 320, 200, 40)
$Label9 = GUICtrlCreateLabel("Home Folder:", 32, 352, 67, 17)
$lable14 = GUICtrlCreateLabel(@HomeShare, 130, 352, 200, 40)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

This is two screenshots of what i would like to see.

The way it is now:

Posted Image

How i would like it to look:

Posted Image

I would like to be able to use some of the output variables ($objItem.Description) and put those under where the "IPs" are instead of using @IPAddress1-4 but I can't figure out how to accomplish that when there are more than 1 adapter on a machine as it displays just the last adapter name in the loop.

Here is some code i found by one of the members and is what i'm trying to use in order to pull the information.

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$Output=""
$Output = $Output & "Computer: " & $strComputer  & @CRLF
$Output = $Output & "==========================================" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled != 0", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
      $Output = $Output & "Caption: " & $objItem.Caption & @CRLF
      $strDefaultIPGateway = $objItem.DefaultIPGateway(0)
      $Output = $Output & "DefaultIPGateway: " & $strDefaultIPGateway & @CRLF
      $Output = $Output & "Description: " & $objItem.Description & @CRLF
      $Output = $Output & "DNSDomain: " & $objItem.DNSDomain & @CRLF
      $Output = $Output & "DNSHostName: " & $objItem.DNSHostName & @CRLF
      $strIPAddress = $objItem.IPAddress(0)
      $Output = $Output & "IPAddress: " & $strIPAddress & @CRLF
      $Output = $Output & "IPEnabled: " & $objItem.IPEnabled & @CRLF
      $strIPSubnet = $objItem.IPSubnet(0)
      $Output = $Output & "IPSubnet: " & $strIPSubnet & @CRLF
      $Output = $Output & "MACAddress: " & $objItem.MACAddress & @CRLF
      if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
      $Output=""
   Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_NetworkAdapterConfiguration" )
Endif
Edited by PnoT
Link to comment
Share on other sites

That code does not display only the last adapter. It only displays adapters with IPEnabled. Remove the part of the query that says " WHERE IPEnabled != 0" and it will list all adapters, whether they are enabled or not.

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

This is alittle bloated for what you want, but may help. Ripped it from some code I use and threw a basic GUI in the format you showed above.

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>


$array = _NicToggle('Display')
_RenderGUI($array,"MYIT Support Tool")



Func _RenderGUI($array,$GuiName)
    Local $offset1 = 0

    $hGUI = GUICreate($GuiName, 500, 150)

    For $i = 1 to $array[0][0]
        GUICtrlCreateLabel($array[$i][1],26, 31+$offset1,200,17)
        GUICtrlCreateLabel($array[$i][3],246, 31+$offset1,70,17)
        GUICtrlCreateLabel($array[$i][5],346, 31+$offset1,90,17)



        $offset1 = $offset1+20
    Next

    GUICtrlCreateGroup('Network Connection ID',20,15,186,$offset1+20,$BS_Center)
    GUICtrlCreateGroup('IP',240,15,96,$offset1+20,$BS_Center)
    GUICtrlCreateGroup('Gateway',340,15,96,$offset1+20,$BS_Center)
    GUISetState(@SW_SHOW)

    While 1
        $msg = GUIGetMsg()

        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
        Sleep(10) ;Dont Eat my CPU
    WEnd

EndFunc

;===============================================================================
;
; Description:      Display/Enable/Dissable any Nics via MAC/IP/Name
;
; Syntax:           _NicToggle('DisAble','Local Area Connection 2')
;
; Parameter(s):     $action =   'Display':      Returns Array of all Nics
;                               'DisAble':      DisAbles specified Nic
;                               'Enable':       Enables specified Nic
;
;                   $NetName = If Enable/DisAble then Specify the Nic Name
;
; Requirement(s):   None
;
; Author(s):
;
;===============================================================================
Func _NicToggle($action = 'Display',$NetName = '0')
    Local $output[1][6] = [['0','ID','Status','IPAddress','MACAddress','Gateway']]
    Local $strComputer = "."
    Local $objNetwork = ObjCreate("WScript.Network")
    $strComputer = $objNetwork.ComputerName
    Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
    Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration")
    Local $IP, $o_WMIService, $a_CollectedConnections

    For $objItem In $colItems
        $IP = $objItem.IPAddress(0)
        $o_WMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2")
        $a_CollectedConnections = $o_WMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter", "WQL", 0x20 + 0x10)

        For $o_ConnectionItem In $a_CollectedConnections
            If $o_ConnectionItem.NetConnectionID <> "" And $o_ConnectionItem.MACAddress = $objItem.MACAddress Then

                $skip = 0
                For $i = 1 to $output[0][0]
                    If $o_ConnectionItem.NetConnectionID = $output[$i][1] Then
                        $skip = 1 ;Duplicate reported
                    EndIf
                Next

                ;MsgBox(0,'$skip ='&$skip ,$o_ConnectionItem.NetConnectionID)
                If $skip = 0 Then
                    ReDim $output[$output[0][0]+2][6]
                    $output[0][0] = $output[0][0]+1
                    $output[$output[0][0]][1] = $o_ConnectionItem.NetConnectionID
                    $output[$output[0][0]][2] = $o_ConnectionItem.NetConnectionStatus
                    $output[$output[0][0]][3] = $objItem.IPAddress(0)
                    $output[$output[0][0]][4] = $o_ConnectionItem.MACAddress
                    $output[$output[0][0]][5] = $objItem.DefaultIPGateway(0)
                EndIf
            EndIf
        Next
    Next

    If $action = 'DisAble' Then
        if $NetName = '0' Then
            MsgBox(0,'CRITICAL ERROR','Must provide a name to Disable')
        Else
            If @OSVersion = 'WIN_XP' Then ;Tested: XPx86
                RunWait(@ComSpec&' /c devcon.exe disable "'&String($NetName)&'"', "", @SW_HIDE)
            ElseIf @OSVersion = 'WIN_2008' and FileExists('X:\windows\system32') Then ;Tested: PE
                _Nic_NetCC($NetName, 0)
            ElseIf @OSVersion = 'WIN_2003' or @OSVersion = 'WIN_2008' or @OSVersion = 'WIN_VISTA' Then ;Tested: 2k3x64,
                _Nic_NetCC($NetName, 0)
            EndIf
        EndIf
    ElseIf $action = 'Enable' Then
        if $NetName = '0' Then
            MsgBox(0,'CRITICAL ERROR','Must provide a name to Enable')
        Else
            If @OSVersion = 'WIN_XP' Then ;Tested: XPx86
                RunWait(@ComSpec&' /c devcon.exe enable "'&String($NetName)&'"', "", @SW_HIDE)
            ElseIf @OSVersion = 'WIN_2008' and FileExists('X:\windows\system32') Then ;Tested: PE
                _Nic_NetCC($NetName, 1)
            ElseIf @OSVersion = 'WIN_2003' or @OSVersion = 'WIN_2008' or @OSVersion = 'WIN_VISTA' Then ;Tested: 2k3x64,
                _Nic_NetCC($NetName, 1)
            EndIf
        EndIf
    Else ;Display Output
        Return $output
    EndIf

EndFunc

Func _Nic_NetCC($oLanConnection, $iFlag);0 = Disable connection,  1 = Enable connection (default)

    If @OSTYPE <> "WIN32_NT" Then Return SetError(1, 0, 0)  ; Control OS type.

    If StringInStr("WIN_2000,WIN_XP,WIN_2003", @OSVersion) Then ;W2K/XP/W2K3
            $Res = _Nic_NetCCWin32($oLanConnection, $iFlag, 1)
    Else ;Vista/W2K8
        If $iFlag = 3 Then Return SetError(5, 0, 0)
        $Res = _Nic_NetCCWin32New($oLanConnection, $iFlag, 1)
    EndIf
    Return SetError(@error, @extended, $Res)
EndFunc

Func _Nic_NetCCWin32($oLanConnection, $iFlag = 1, $iFullName = 1); Only for W2K/XP/W2K3
    Local $objShell, $objFolder

    $objShell = ObjCreate("Shell.Application")
    If Not IsObj($objShell) Then Return SetError(2, 0, 0)

    $objFolder = $objShell.NameSpace(0x31)
    If Not IsObj($objFolder) Then Return SetError(3, 0, 0)

    ; Find the collection of the network connection name.
    For $LanItem In $objFolder.Items
        If StringLower($LanItem.Name) = StringLower($oLanConnection) Then
            $oLanConnection = $LanItem
            ExitLoop
        EndIf
    Next
    ; If no network connection name then return error.
    If Not IsObj($oLanConnection) Then Return SetError(3, 0, 0)

    $oEnableVerb = ""
    $oDisableVerb = ""

    ; Find the state of the network connection.
    For $Verb In $oLanConnection.Verbs
        If $Verb.Name = "En&able" Then
            $oEnableVerb = $Verb
            If Not IsObj($oEnableVerb) Then Return SetError(5, 0, 0)
            $State = 0
        EndIf
        If $Verb.Name = "Disa&ble" Then
            $oDisableVerb = $Verb
            If Not IsObj($oDisableVerb) Then Return SetError(5, 0, 0)
            $State = 1
        EndIf
        If $Verb.Name = "Re&pair" Then
            $oRepairVerb = $Verb
            If Not IsObj($oRepairVerb) Then Return SetError(5, 0, 0)
        EndIf
    Next

    ; Return State
    If $iFlag = 4 Then
        Return $State
    ; Repair Net Connection
    ElseIf $iFlag = 3 And $State = 1 Then
        $oRepairVerb.DoIt
    ; Toggle Net Connection
    ElseIf $iFlag = 2 Then
        If $State = 1 Then
            $oDisableVerb.DoIt
        Else
            $oEnableVerb.DoIt
        EndIf
    ; Enable Net Connection
    ElseIf $iFlag = 1 And $State = 0 Then
        $oEnableVerb.DoIt
    ; Disable Net Connection
    ElseIf $iFlag = 0 And $State = 1 Then
        $oDisableVerb.DoIt
    ; Else there is an error
    Else
        Return SetError(5, 0, 0)
    EndIf

    ; Loop to wait change state (for changing state of more than one connection).
    $begin = TimerInit()
    While 1
        $dif = Int(TimerDiff($begin) / 1000)
        If $dif > 10 Then ExitLoop
        ; Control the state of the NIC to exit before the end of waiting time.
        If $iFlag = 3 And _Nic_NetCCWin32($oLanConnection, 4) = 1 Then ExitLoop
        If $iFlag = 2 And $State = 1 And _Nic_NetCCWin32($oLanConnection, 4) = 0 Then ExitLoop
        If $iFlag = 2 And $State = 0 And _Nic_NetCCWin32($oLanConnection, 4) = 1 Then ExitLoop
        If $iFlag = 1 And _Nic_NetCCWin32($oLanConnection, 4) = 1 Then ExitLoop
        If $iFlag = 0 And _Nic_NetCCWin32($oLanConnection, 4) = 0 Then ExitLoop
        Sleep(100)
    WEnd

    ; Set the return value of the function.
    $Res = _Nic_NetCCWin32($oLanConnection, 4)
    If $iFlag = 4 And $Res = 1 Then
        Sleep(3000)
        Return 1
    ElseIf $iFlag = 1 And $Res = 0 Then
        Return 0
    ElseIf $iFlag = 0 And $Res = 1 Then
        Return 0
    Else
        Return 1
    EndIf
EndFunc

Func _Nic_NetCCWin32New($oLanConnection, $iFlag = 1, $iFullName = 1); Only for Vista/W2K8
    Local $objWMIService, $colItems, $iModState = 0

    $objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter", "WQL", 0x30)
    If Not IsObj($colItems) Then Return SetError(4, 0, 0)

    ; Change NIC state of $oLanConnection
    ; Check name of the connection
    For $objItem In $colItems
        If $objItem.NetConnectionID = $oLanConnection Then
            ; Check State.
            If $iFlag = 4 Then
                If $objItem.NetEnabled = True Then
                    Return 1
                Else
                    Return 0
                EndIf
            Else
                ; Change the State of Net Connection.
                ; Disable Net Connection
                If $iFlag = 0 And $objItem.NetEnabled = True Then
                    $objItem.Disable
                ; Enable Net Connection
                ElseIf $iFlag = 1 And $objItem.NetEnabled = False Then
                    $objItem.Enable
                ; Toggle Net Connection
                ElseIf $iFlag = 2 Then
                    If $objItem.NetEnabled = True Then
                        $objItem.Disable
                        $State = 1
                    Else
                        $objItem.Enable
                        $State = 0
                    EndIf
                EndIf
                ; One change be done.
                $iModState = 1
            EndIf
            ExitLoop
        EndIf
    Next
    ; If no connection then error.
    If $iModState = 0 Then Return SetError(3, 0, 0)


    ; Loop to wait state change.
    If $iFlag = 4 Then
        While $iFlag <> _Nic_NetCCWin32New($oLanConnection, 4)
            Sleep(250)
        WEnd
    Else
        Sleep(1000)
        If $iFlag = 2 Then
            If $State = 0 And _Nic_NetCCWin32New($oLanConnection, 4) = 1 Then
                Return 1
            ElseIf $State = 1 And _Nic_NetCCWin32New($oLanConnection, 4) = 0 Then
                Return 1
            Else
                Return 0
            EndIf
        ElseIf $iFlag = 1 And _Nic_NetCCWin32New($oLanConnection, 4) = 1 Then
            Return 1
        ElseIf $iFlag = 0 And _Nic_NetCCWin32New($oLanConnection, 4) = 0 Then
            Return 1
        Else
            Return 0
        EndIf
    EndIf
EndFunc

There is always a butthead in the crowd, no matter how hard one tries to keep them out.......Volly

Link to comment
Share on other sites

This is alittle bloated for what you want, but may help. Ripped it from some code I use and threw a basic GUI in the format you showed above.

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>


$array = _NicToggle('Display')
_RenderGUI($array,"MYIT Support Tool")



Func _RenderGUI($array,$GuiName)
    Local $offset1 = 0

    $hGUI = GUICreate($GuiName, 500, 150)

    For $i = 1 to $array[0][0]
        GUICtrlCreateLabel($array[$i][1],26, 31+$offset1,200,17)
        GUICtrlCreateLabel($array[$i][3],246, 31+$offset1,70,17)
        GUICtrlCreateLabel($array[$i][5],346, 31+$offset1,90,17)



        $offset1 = $offset1+20
    Next

    GUICtrlCreateGroup('Network Connection ID',20,15,186,$offset1+20,$BS_Center)
    GUICtrlCreateGroup('IP',240,15,96,$offset1+20,$BS_Center)
    GUICtrlCreateGroup('Gateway',340,15,96,$offset1+20,$BS_Center)
    GUISetState(@SW_SHOW)

    While 1
        $msg = GUIGetMsg()

        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
        Sleep(10) ;Dont Eat my CPU
    WEnd

EndFunc

;===============================================================================
;
; Description:      Display/Enable/Dissable any Nics via MAC/IP/Name
;
; Syntax:           _NicToggle('DisAble','Local Area Connection 2')
;
; Parameter(s):     $action =   'Display':      Returns Array of all Nics
;                               'DisAble':      DisAbles specified Nic
;                               'Enable':       Enables specified Nic
;
;                   $NetName = If Enable/DisAble then Specify the Nic Name
;
; Requirement(s):   None
;
; Author(s):
;
;===============================================================================
Func _NicToggle($action = 'Display',$NetName = '0')
    Local $output[1][6] = [['0','ID','Status','IPAddress','MACAddress','Gateway']]
    Local $strComputer = "."
    Local $objNetwork = ObjCreate("WScript.Network")
    $strComputer = $objNetwork.ComputerName
    Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
    Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration")
    Local $IP, $o_WMIService, $a_CollectedConnections

    For $objItem In $colItems
        $IP = $objItem.IPAddress(0)
        $o_WMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2")
        $a_CollectedConnections = $o_WMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter", "WQL", 0x20 + 0x10)

        For $o_ConnectionItem In $a_CollectedConnections
            If $o_ConnectionItem.NetConnectionID <> "" And $o_ConnectionItem.MACAddress = $objItem.MACAddress Then

                $skip = 0
                For $i = 1 to $output[0][0]
                    If $o_ConnectionItem.NetConnectionID = $output[$i][1] Then
                        $skip = 1 ;Duplicate reported
                    EndIf
                Next

                ;MsgBox(0,'$skip ='&$skip ,$o_ConnectionItem.NetConnectionID)
                If $skip = 0 Then
                    ReDim $output[$output[0][0]+2][6]
                    $output[0][0] = $output[0][0]+1
                    $output[$output[0][0]][1] = $o_ConnectionItem.NetConnectionID
                    $output[$output[0][0]][2] = $o_ConnectionItem.NetConnectionStatus
                    $output[$output[0][0]][3] = $objItem.IPAddress(0)
                    $output[$output[0][0]][4] = $o_ConnectionItem.MACAddress
                    $output[$output[0][0]][5] = $objItem.DefaultIPGateway(0)
                EndIf
            EndIf
        Next
    Next

    If $action = 'DisAble' Then
        if $NetName = '0' Then
            MsgBox(0,'CRITICAL ERROR','Must provide a name to Disable')
        Else
            If @OSVersion = 'WIN_XP' Then ;Tested: XPx86
                RunWait(@ComSpec&' /c devcon.exe disable "'&String($NetName)&'"', "", @SW_HIDE)
            ElseIf @OSVersion = 'WIN_2008' and FileExists('X:\windows\system32') Then ;Tested: PE
                _Nic_NetCC($NetName, 0)
            ElseIf @OSVersion = 'WIN_2003' or @OSVersion = 'WIN_2008' or @OSVersion = 'WIN_VISTA' Then ;Tested: 2k3x64,
                _Nic_NetCC($NetName, 0)
            EndIf
        EndIf
    ElseIf $action = 'Enable' Then
        if $NetName = '0' Then
            MsgBox(0,'CRITICAL ERROR','Must provide a name to Enable')
        Else
            If @OSVersion = 'WIN_XP' Then ;Tested: XPx86
                RunWait(@ComSpec&' /c devcon.exe enable "'&String($NetName)&'"', "", @SW_HIDE)
            ElseIf @OSVersion = 'WIN_2008' and FileExists('X:\windows\system32') Then ;Tested: PE
                _Nic_NetCC($NetName, 1)
            ElseIf @OSVersion = 'WIN_2003' or @OSVersion = 'WIN_2008' or @OSVersion = 'WIN_VISTA' Then ;Tested: 2k3x64,
                _Nic_NetCC($NetName, 1)
            EndIf
        EndIf
    Else ;Display Output
        Return $output
    EndIf

EndFunc

Func _Nic_NetCC($oLanConnection, $iFlag);0 = Disable connection,  1 = Enable connection (default)

    If @OSTYPE <> "WIN32_NT" Then Return SetError(1, 0, 0)  ; Control OS type.

    If StringInStr("WIN_2000,WIN_XP,WIN_2003", @OSVersion) Then ;W2K/XP/W2K3
            $Res = _Nic_NetCCWin32($oLanConnection, $iFlag, 1)
    Else ;Vista/W2K8
        If $iFlag = 3 Then Return SetError(5, 0, 0)
        $Res = _Nic_NetCCWin32New($oLanConnection, $iFlag, 1)
    EndIf
    Return SetError(@error, @extended, $Res)
EndFunc

Func _Nic_NetCCWin32($oLanConnection, $iFlag = 1, $iFullName = 1); Only for W2K/XP/W2K3
    Local $objShell, $objFolder

    $objShell = ObjCreate("Shell.Application")
    If Not IsObj($objShell) Then Return SetError(2, 0, 0)

    $objFolder = $objShell.NameSpace(0x31)
    If Not IsObj($objFolder) Then Return SetError(3, 0, 0)

    ; Find the collection of the network connection name.
    For $LanItem In $objFolder.Items
        If StringLower($LanItem.Name) = StringLower($oLanConnection) Then
            $oLanConnection = $LanItem
            ExitLoop
        EndIf
    Next
    ; If no network connection name then return error.
    If Not IsObj($oLanConnection) Then Return SetError(3, 0, 0)

    $oEnableVerb = ""
    $oDisableVerb = ""

    ; Find the state of the network connection.
    For $Verb In $oLanConnection.Verbs
        If $Verb.Name = "En&able" Then
            $oEnableVerb = $Verb
            If Not IsObj($oEnableVerb) Then Return SetError(5, 0, 0)
            $State = 0
        EndIf
        If $Verb.Name = "Disa&ble" Then
            $oDisableVerb = $Verb
            If Not IsObj($oDisableVerb) Then Return SetError(5, 0, 0)
            $State = 1
        EndIf
        If $Verb.Name = "Re&pair" Then
            $oRepairVerb = $Verb
            If Not IsObj($oRepairVerb) Then Return SetError(5, 0, 0)
        EndIf
    Next

    ; Return State
    If $iFlag = 4 Then
        Return $State
    ; Repair Net Connection
    ElseIf $iFlag = 3 And $State = 1 Then
        $oRepairVerb.DoIt
    ; Toggle Net Connection
    ElseIf $iFlag = 2 Then
        If $State = 1 Then
            $oDisableVerb.DoIt
        Else
            $oEnableVerb.DoIt
        EndIf
    ; Enable Net Connection
    ElseIf $iFlag = 1 And $State = 0 Then
        $oEnableVerb.DoIt
    ; Disable Net Connection
    ElseIf $iFlag = 0 And $State = 1 Then
        $oDisableVerb.DoIt
    ; Else there is an error
    Else
        Return SetError(5, 0, 0)
    EndIf

    ; Loop to wait change state (for changing state of more than one connection).
    $begin = TimerInit()
    While 1
        $dif = Int(TimerDiff($begin) / 1000)
        If $dif > 10 Then ExitLoop
        ; Control the state of the NIC to exit before the end of waiting time.
        If $iFlag = 3 And _Nic_NetCCWin32($oLanConnection, 4) = 1 Then ExitLoop
        If $iFlag = 2 And $State = 1 And _Nic_NetCCWin32($oLanConnection, 4) = 0 Then ExitLoop
        If $iFlag = 2 And $State = 0 And _Nic_NetCCWin32($oLanConnection, 4) = 1 Then ExitLoop
        If $iFlag = 1 And _Nic_NetCCWin32($oLanConnection, 4) = 1 Then ExitLoop
        If $iFlag = 0 And _Nic_NetCCWin32($oLanConnection, 4) = 0 Then ExitLoop
        Sleep(100)
    WEnd

    ; Set the return value of the function.
    $Res = _Nic_NetCCWin32($oLanConnection, 4)
    If $iFlag = 4 And $Res = 1 Then
        Sleep(3000)
        Return 1
    ElseIf $iFlag = 1 And $Res = 0 Then
        Return 0
    ElseIf $iFlag = 0 And $Res = 1 Then
        Return 0
    Else
        Return 1
    EndIf
EndFunc

Func _Nic_NetCCWin32New($oLanConnection, $iFlag = 1, $iFullName = 1); Only for Vista/W2K8
    Local $objWMIService, $colItems, $iModState = 0

    $objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter", "WQL", 0x30)
    If Not IsObj($colItems) Then Return SetError(4, 0, 0)

    ; Change NIC state of $oLanConnection
    ; Check name of the connection
    For $objItem In $colItems
        If $objItem.NetConnectionID = $oLanConnection Then
            ; Check State.
            If $iFlag = 4 Then
                If $objItem.NetEnabled = True Then
                    Return 1
                Else
                    Return 0
                EndIf
            Else
                ; Change the State of Net Connection.
                ; Disable Net Connection
                If $iFlag = 0 And $objItem.NetEnabled = True Then
                    $objItem.Disable
                ; Enable Net Connection
                ElseIf $iFlag = 1 And $objItem.NetEnabled = False Then
                    $objItem.Enable
                ; Toggle Net Connection
                ElseIf $iFlag = 2 Then
                    If $objItem.NetEnabled = True Then
                        $objItem.Disable
                        $State = 1
                    Else
                        $objItem.Enable
                        $State = 0
                    EndIf
                EndIf
                ; One change be done.
                $iModState = 1
            EndIf
            ExitLoop
        EndIf
    Next
    ; If no connection then error.
    If $iModState = 0 Then Return SetError(3, 0, 0)


    ; Loop to wait state change.
    If $iFlag = 4 Then
        While $iFlag <> _Nic_NetCCWin32New($oLanConnection, 4)
            Sleep(250)
        WEnd
    Else
        Sleep(1000)
        If $iFlag = 2 Then
            If $State = 0 And _Nic_NetCCWin32New($oLanConnection, 4) = 1 Then
                Return 1
            ElseIf $State = 1 And _Nic_NetCCWin32New($oLanConnection, 4) = 0 Then
                Return 1
            Else
                Return 0
            EndIf
        ElseIf $iFlag = 1 And _Nic_NetCCWin32New($oLanConnection, 4) = 1 Then
            Return 1
        ElseIf $iFlag = 0 And _Nic_NetCCWin32New($oLanConnection, 4) = 0 Then
            Return 1
        Else
            Return 0
        EndIf
    EndIf
EndFunc

Wow, you completely nailed this for me!! I've not only got exactly what i wanted but you've also taught me how to setup the array and pull the info that i need. I was missing that part and couldn't quite wrap my head around it.

Maybe you can shed some light on a new delima :D

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $SL
                _SLFIX()
            Case $MD
                _DriveMap()
            Case $DA
                ;;not used yet
            Case $Exit
                Exit
        EndSwitch
    WEnd

EndFunc   ;==>_RenderGUI

I have the script check for mapped drives and if they are correct (drive is mapped properly) then i put a small green check mark next to the drive mapping to indicate all is good. If the mapping is not correct I can hit a button I've created called "Map Drives" and it calls the _DriveMap() function above. My only problem is I would love to have the gui go back and check the mappings again and put a checkmark on them after the _DriveMap() function is finished.

How is that accomplished exactly?

Link to comment
Share on other sites

Pnot, I would need to see your full code to make an appropriate suggestion. In most cases I would make a Function that updates the checks Mapped drives and updates the GUI accordingly. Then have this function as the last part of _DriveMap().

There is always a butthead in the crowd, no matter how hard one tries to keep them out.......Volly

Link to comment
Share on other sites

Pnot, I would need to see your full code to make an appropriate suggestion. In most cases I would make a Function that updates the checks Mapped drives and updates the GUI accordingly. Then have this function as the last part of _DriveMap().

Here is what I have so far:

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <services.au3>

$array = _NicToggle('Display')
_RenderGUI($array, "MYIT Support Tool")


Func _RenderGUI($array, $GuiName)
    Local $offset1 = 0

    $hGUI = GUICreate($GuiName, 459, 477)

    For $i = 1 To $array[0][0]
        GUICtrlCreateLabel($array[$i][1], 26, 31 + $offset1, 200, 17)
        GUICtrlCreateLabel($array[$i][3], 246, 31 + $offset1, 70, 17)
        GUICtrlCreateLabel($array[$i][5], 346, 31 + $offset1, 90, 17)



        $offset1 = $offset1 + 20
    Next

    $H = DriveMapGet("H:")
    $P = DriveMapGet("P:")
    $S = DriveMapGet("S:")

    GUICtrlCreateGroup("Network Connection ID", 20, 15, 186, 105)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    GUICtrlCreateGroup("IP", 240, 15, 96, 105)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    GUICtrlCreateGroup("Gateway", 340, 15, 96, 105)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    GUICtrlCreateGroup("Current Drive Mappings and Ping Check", 20, 124, 418, 100, $BS_CENTER)
    GUICtrlCreateLabel("Server", 281, 149, 61, 20)
    GUICtrlCreateLabel("Server2", 281, 174, 61, 20)
    GUICtrlCreateLabel("", 152, 144, 31, 17)
    GUICtrlSetFont(-1, 9, 800, 4, "Symbol")
    GUICtrlSetColor(-1, 0x001F40)
    GUICtrlCreateLabel("", 152, 168, 28, 17)
    GUICtrlSetFont(-1, 9, 800, 4, "Symbol")
    GUICtrlSetColor(-1, 0x001F40)
    GUICtrlCreateLabel("H:", 32, 149, 15, 17)
    GUICtrlCreateLabel("P:", 32, 174, 14, 17)
    GUICtrlCreateLabel("S:", 32, 199, 14, 17)
    GUICtrlCreateLabel($H, 48, 149, 180, 17)
    GUICtrlCreateLabel($P, 48, 174, 180, 17)
    GUICtrlCreateLabel($S, 48, 199, 180, 17)
    GUICtrlCreateLabel("", 227, 149, 41, 17) ; this is a placeholder for when i get H: drive AD polling integrated
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    GUICtrlCreateGroup("Computer Information", 20, 232, 417, 121)
    GUICtrlCreateLabel("Computer Name:", 24, 256, 83, 17)
    GUICtrlCreateLabel("User:", 24, 280, 29, 17)
    GUICtrlCreateLabel("Home Folder:", 24, 304, 67, 17)
    GUICtrlCreateLabel("Domain Controller:", 24, 328, 90, 17)
    GUICtrlCreateLabel(@ComputerName, 120, 256, 125, 17)
    GUICtrlCreateLabel(@LogonDomain & "\" & @UserName, 120, 280, 125, 17)
    GUICtrlCreateLabel(@HomeShare, 120, 304, 125, 17)
    GUICtrlCreateLabel(@LogonServer, 120, 328, 125, 17)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    GUICtrlCreateGroup("Tools", 20, 364, 417, 81)
    $MD = GUICtrlCreateButton("Map Drives", 24, 392, 75, 25, $WS_GROUP)
    $SF = GUICtrlCreateButton("Spark Fix", 104, 392, 75, 25, $WS_GROUP)
    $SL = GUICtrlCreateButton("SL Fix", 184, 392, 75, 25, $WS_GROUP)
    $DA = GUICtrlCreateButton("DA Fix", 264, 392, 75, 25, $WS_GROUP)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Exit = GUICtrlCreateButton("EXIT", 360, 448, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)

    GUISetState()
    Sleep(1000)
    If $P = "\\share1$" Then
        $PC = GUICtrlCreateLabel(Chr(214), 227, 174, 41, 17) ;the "checkmark"
        GUICtrlSetFont(-1, 9, 700, 4, "Symbol")
        GUICtrlSetColor(-1, 0x008000)
    EndIf
    GUISetState()
    Sleep(1000)
    If $S = "\\share2$" Then
        $PS = GUICtrlCreateLabel(Chr(214), 227, 199, 41, 17) ;the "checkmark"
        GUICtrlSetFont(-1, 9, 700, 4, "Symbol")
        GUICtrlSetColor(-1, 0x008000)
    EndIf
    GUISetState()
    Sleep(1000)
    $ping = Ping("server", 250)
    If @error = 0 Then
        GUICtrlCreateLabel(Chr(214), 368, 149, 41, 17) ;the "checkmark"
        GUICtrlSetFont(-1, 9, 700, 4, "Symbol")
        GUICtrlSetColor(-1, 0x008000)
    Else
        GUICtrlCreateLabel("FAILED", 368, 149, 41, 17)
    EndIf

    GUISetState()
    Sleep(1000)
    $ping2 = Ping("server2", 250)
    If @error = 0 Then
        GUICtrlCreateLabel(Chr(214), 368, 174, 48, 17) ;the "checkmark"
        GUICtrlSetFont(-1, 9, 700, 4, "Symbol")
        GUICtrlSetColor(-1, 0x008000)
    Else
        GUICtrlCreateLabel("FAILED", 368, 174, 48, 17)
    EndIf

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $SL
                ;;;_SLFIX()
            Case $MD
                _DriveMap()
            Case $DA
                ;;
            Case $Exit
                Exit
        EndSwitch
    WEnd

EndFunc   ;==>_RenderGUI
;===============================================================================
;
; Description:      Display/Enable/Dissable any Nics via MAC/IP/Name
;
; Syntax:           _NicToggle('DisAble','Local Area Connection 2')
;
; Parameter(s):     $action =   'Display':      Returns Array of all Nics
;                               'DisAble':      DisAbles specified Nic
;                               'Enable':       Enables specified Nic
;
;                   $NetName = If Enable/DisAble then Specify the Nic Name
;
; Requirement(s):   None
;
; Author(s):
;
;===============================================================================
Func _NicToggle($action = 'Display', $NetName = '0')
    Local $output[1][6] = [['0', 'ID', 'Status', 'IPAddress', 'MACAddress', 'Gateway']]
    Local $strComputer = "."
    Local $objNetwork = ObjCreate("WScript.Network")
    $strComputer = $objNetwork.ComputerName
    Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
    Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration")
    Local $IP, $o_WMIService, $a_CollectedConnections

    For $objItem In $colItems
        $IP = $objItem.IPAddress(0)
        $o_WMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2")
        $a_CollectedConnections = $o_WMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter", "WQL", 0x20 + 0x10)

        For $o_ConnectionItem In $a_CollectedConnections
            If $o_ConnectionItem.NetConnectionID <> "" And $o_ConnectionItem.MACAddress = $objItem.MACAddress Then

                $skip = 0
                For $i = 1 To $output[0][0]
                    If $o_ConnectionItem.NetConnectionID = $output[$i][1] Then
                        $skip = 1 ;Duplicate reported
                    EndIf
                Next

                ;MsgBox(0,'$skip ='&$skip ,$o_ConnectionItem.NetConnectionID)
                If $skip = 0 Then
                    ReDim $output[$output[0][0] + 2][6]
                    $output[0][0] = $output[0][0] + 1
                    $output[$output[0][0]][1] = $o_ConnectionItem.NetConnectionID
                    $output[$output[0][0]][2] = $o_ConnectionItem.NetConnectionStatus
                    $output[$output[0][0]][3] = $objItem.IPAddress(0)
                    $output[$output[0][0]][4] = $o_ConnectionItem.MACAddress
                    $output[$output[0][0]][5] = $objItem.DefaultIPGateway(0)
                EndIf
            EndIf
        Next
    Next

    If $action = 'DisAble' Then
        If $NetName = '0' Then
            MsgBox(0, 'CRITICAL ERROR', 'Must provide a name to Disable')
        Else
            If @OSVersion = 'WIN_XP' Then ;Tested: XPx86
                RunWait(@ComSpec & ' /c devcon.exe disable "' & String($NetName) & '"', "", @SW_HIDE)
            ElseIf @OSVersion = 'WIN_2008' And FileExists('X:\windows\system32') Then ;Tested: PE
                _Nic_NetCC($NetName, 0)
            ElseIf @OSVersion = 'WIN_2003' Or @OSVersion = 'WIN_2008' Or @OSVersion = 'WIN_VISTA' Then ;Tested: 2k3x64,
                _Nic_NetCC($NetName, 0)
            EndIf
        EndIf
    ElseIf $action = 'Enable' Then
        If $NetName = '0' Then
            MsgBox(0, 'CRITICAL ERROR', 'Must provide a name to Enable')
        Else
            If @OSVersion = 'WIN_XP' Then ;Tested: XPx86
                RunWait(@ComSpec & ' /c devcon.exe enable "' & String($NetName) & '"', "", @SW_HIDE)
            ElseIf @OSVersion = 'WIN_2008' And FileExists('X:\windows\system32') Then ;Tested: PE
                _Nic_NetCC($NetName, 1)
            ElseIf @OSVersion = 'WIN_2003' Or @OSVersion = 'WIN_2008' Or @OSVersion = 'WIN_VISTA' Then ;Tested: 2k3x64,
                _Nic_NetCC($NetName, 1)
            EndIf
        EndIf
    Else ;Display Output
        Return $output
    EndIf

EndFunc   ;==>_NicToggle

Func _Nic_NetCC($oLanConnection, $iFlag);0 = Disable connection,  1 = Enable connection (default)

    If @OSType <> "WIN32_NT" Then Return SetError(1, 0, 0) ; Control OS type.

    If StringInStr("WIN_2000,WIN_XP,WIN_2003", @OSVersion) Then ;W2K/XP/W2K3
        $Res = _Nic_NetCCWin32($oLanConnection, $iFlag, 1)
    Else ;Vista/W2K8
        If $iFlag = 3 Then Return SetError(5, 0, 0)
        $Res = _Nic_NetCCWin32New($oLanConnection, $iFlag, 1)
    EndIf
    Return SetError(@error, @extended, $Res)
EndFunc   ;==>_Nic_NetCC

Func _Nic_NetCCWin32($oLanConnection, $iFlag = 1, $iFullName = 1); Only for W2K/XP/W2K3
    Local $objShell, $objFolder

    $objShell = ObjCreate("Shell.Application")
    If Not IsObj($objShell) Then Return SetError(2, 0, 0)

    $objFolder = $objShell.NameSpace(0x31)
    If Not IsObj($objFolder) Then Return SetError(3, 0, 0)

    ; Find the collection of the network connection name.
    For $LanItem In $objFolder.Items
        If StringLower($LanItem.Name) = StringLower($oLanConnection) Then
            $oLanConnection = $LanItem
            ExitLoop
        EndIf
    Next
    ; If no network connection name then return error.
    If Not IsObj($oLanConnection) Then Return SetError(3, 0, 0)

    $oEnableVerb = ""
    $oDisableVerb = ""

    ; Find the state of the network connection.
    For $Verb In $oLanConnection.Verbs
        If $Verb.Name = "En&able" Then
            $oEnableVerb = $Verb
            If Not IsObj($oEnableVerb) Then Return SetError(5, 0, 0)
            $State = 0
        EndIf
        If $Verb.Name = "Disa&ble" Then
            $oDisableVerb = $Verb
            If Not IsObj($oDisableVerb) Then Return SetError(5, 0, 0)
            $State = 1
        EndIf
        If $Verb.Name = "Re&pair" Then
            $oRepairVerb = $Verb
            If Not IsObj($oRepairVerb) Then Return SetError(5, 0, 0)
        EndIf
    Next

    ; Return State
    If $iFlag = 4 Then
        Return $State
        ; Repair Net Connection
    ElseIf $iFlag = 3 And $State = 1 Then
        $oRepairVerb.DoIt
        ; Toggle Net Connection
    ElseIf $iFlag = 2 Then
        If $State = 1 Then
            $oDisableVerb.DoIt
        Else
            $oEnableVerb.DoIt
        EndIf
        ; Enable Net Connection
    ElseIf $iFlag = 1 And $State = 0 Then
        $oEnableVerb.DoIt
        ; Disable Net Connection
    ElseIf $iFlag = 0 And $State = 1 Then
        $oDisableVerb.DoIt
        ; Else there is an error
    Else
        Return SetError(5, 0, 0)
    EndIf

    ; Loop to wait change state (for changing state of more than one connection).
    $begin = TimerInit()
    While 1
        $dif = Int(TimerDiff($begin) / 1000)
        If $dif > 10 Then ExitLoop
        ; Control the state of the NIC to exit before the end of waiting time.
        If $iFlag = 3 And _Nic_NetCCWin32($oLanConnection, 4) = 1 Then ExitLoop
        If $iFlag = 2 And $State = 1 And _Nic_NetCCWin32($oLanConnection, 4) = 0 Then ExitLoop
        If $iFlag = 2 And $State = 0 And _Nic_NetCCWin32($oLanConnection, 4) = 1 Then ExitLoop
        If $iFlag = 1 And _Nic_NetCCWin32($oLanConnection, 4) = 1 Then ExitLoop
        If $iFlag = 0 And _Nic_NetCCWin32($oLanConnection, 4) = 0 Then ExitLoop
        Sleep(100)
    WEnd

    ; Set the return value of the function.
    $Res = _Nic_NetCCWin32($oLanConnection, 4)
    If $iFlag = 4 And $Res = 1 Then
        Sleep(3000)
        Return 1
    ElseIf $iFlag = 1 And $Res = 0 Then
        Return 0
    ElseIf $iFlag = 0 And $Res = 1 Then
        Return 0
    Else
        Return 1
    EndIf
EndFunc   ;==>_Nic_NetCCWin32

Func _Nic_NetCCWin32New($oLanConnection, $iFlag = 1, $iFullName = 1); Only for Vista/W2K8
    Local $objWMIService, $colItems, $iModState = 0

    $objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter", "WQL", 0x30)
    If Not IsObj($colItems) Then Return SetError(4, 0, 0)

    ; Change NIC state of $oLanConnection
    ; Check name of the connection
    For $objItem In $colItems
        If $objItem.NetConnectionID = $oLanConnection Then
            ; Check State.
            If $iFlag = 4 Then
                If $objItem.NetEnabled = True Then
                    Return 1
                Else
                    Return 0
                EndIf
            Else
                ; Change the State of Net Connection.
                ; Disable Net Connection
                If $iFlag = 0 And $objItem.NetEnabled = True Then
                    $objItem.Disable
                    ; Enable Net Connection
                ElseIf $iFlag = 1 And $objItem.NetEnabled = False Then
                    $objItem.Enable
                    ; Toggle Net Connection
                ElseIf $iFlag = 2 Then
                    If $objItem.NetEnabled = True Then
                        $objItem.Disable
                        $State = 1
                    Else
                        $objItem.Enable
                        $State = 0
                    EndIf
                EndIf
                ; One change be done.
                $iModState = 1
            EndIf
            ExitLoop
        EndIf
    Next
    ; If no connection then error.
    If $iModState = 0 Then Return SetError(3, 0, 0)


    ; Loop to wait state change.
    If $iFlag = 4 Then
        While $iFlag <> _Nic_NetCCWin32New($oLanConnection, 4)
            Sleep(250)
        WEnd
    Else
        Sleep(1000)
        If $iFlag = 2 Then
            If $State = 0 And _Nic_NetCCWin32New($oLanConnection, 4) = 1 Then
                Return 1
            ElseIf $State = 1 And _Nic_NetCCWin32New($oLanConnection, 4) = 0 Then
                Return 1
            Else
                Return 0
            EndIf
        ElseIf $iFlag = 1 And _Nic_NetCCWin32New($oLanConnection, 4) = 1 Then
            Return 1
        ElseIf $iFlag = 0 And _Nic_NetCCWin32New($oLanConnection, 4) = 0 Then
            Return 1
        Else
            Return 0
        EndIf
    EndIf
EndFunc   ;==>_Nic_NetCCWin32New

Func _DriveMap()
    DriveMapDel("P:")
    DriveMapDel("S:")
    DriveMapAdd("S:", "\\share1$", 1)
    DriveMapAdd("P:", "\\share2$", 1)
EndFunc   ;==>_DriveMap

I could probably clean up the ping, drive mapping check, and the "checkmark" actions but I'll have to do some research on it first. I also need to tap into AD in order to check a users home folder instead of going by what the @homeshare is but that's for a later date.

Edited by PnoT
Link to comment
Share on other sites

I believe all you need to do is add this to the bottom of the _DriveMap Func. You will also need to set $P and $PC as Globals.

If $P = "\\share1$" Then
    $PC = GUICtrlCreateLabel(Chr(214), 227, 174, 41, 17) ;the "checkmark"
    GUICtrlSetFont(-1, 9, 700, 4, "Symbol")
    GUICtrlSetColor(-1, 0x008000)
EndIf
GUISetState()

EDIT: mu bad, was in a hurry...

$P = DriveMapGet("P:")
If $P = "\\share1$" Then GUICtrlSetState($PC,Chr(214))
Edited by ofLight

There is always a butthead in the crowd, no matter how hard one tries to keep them out.......Volly

Link to comment
Share on other sites

I believe all you need to do is add this to the bottom of the _DriveMap Func. You will also need to set $P and $PC as Globals.

If $P = "\\share1$" Then
    $PC = GUICtrlCreateLabel(Chr(214), 227, 174, 41, 17) ;the "checkmark"
    GUICtrlSetFont(-1, 9, 700, 4, "Symbol")
    GUICtrlSetColor(-1, 0x008000)
EndIf
GUISetState()

EDIT: mu bad, was in a hurry...

$P = DriveMapGet("P:")
If $P = "\\share1$" Then GUICtrlSetState($PC,Chr(214))

Here is what i have now and it's not working for me:

Global $H = DriveMapGet("H:")
Global $P = DriveMapGet("P:")
Global $S = DriveMapGet("S:")
Global $PC = GUICtrlCreateLabel(Chr(214), 227, 174, 41, 17) ;the "checkmark"
Global $PS = GUICtrlCreateLabel(Chr(214), 227, 199, 41, 17) ;the "checkmark"

Func _DriveMap()
    DriveMapDel("P:")
    DriveMapDel("S:")
    DriveMapAdd("S:", "\\share1$", 1)
    DriveMapAdd("P:", "\\share2$", 1)
        If $P = "\\share2$" Then
    GUICtrlSetState($PC,Chr(214))
    EndIf
EndFunc   ;==>_DriveMap
Edited by PnoT
Link to comment
Share on other sites

Here is what i have now and it's not working for me:

No shit. You're doing the DriveMapGet before the DriveMapAdd. Think about that for a moment.
Link to comment
Share on other sites

Func _DriveMap()
    DriveMapDel("P:")
    DriveMapDel("S:")
    DriveMapAdd("S:", "\\share1$", 1)
    DriveMapAdd("P:", "\\share2$", 1)
    $S = DriveMapGet("S:")  
    $P = DriveMapGet("P:")
    If $S = "\\share1$" Then GUICtrlSetState($PS,Chr(214))
    If $P = "\\share2$" Then GUICtrlSetState($PC,Chr(214))
EndFunc   ;==>_DriveMap

There is always a butthead in the crowd, no matter how hard one tries to keep them out.......Volly

Link to comment
Share on other sites

Func _DriveMap()
    DriveMapDel("P:")
    DriveMapDel("S:")
    DriveMapAdd("S:", "\\share1$", 1)
    DriveMapAdd("P:", "\\share2$", 1)
    $S = DriveMapGet("S:")  
    $P = DriveMapGet("P:")
    If $S = "\\share1$" Then GUICtrlSetState($PS,Chr(214))
    If $P = "\\share2$" Then GUICtrlSetState($PC,Chr(214))
EndFunc   ;==>_DriveMap

I wound up creating my own function and happy to report it's working like a champ! In doing so it freed up some code elsewhere in my script so a win/win.

func _Checkmark($left, $top, $width, $height)
    GUICtrlCreateLabel(Chr(214), $left, $top, $width, $height)
    GUICtrlSetFont(-1, 9, 700, 4, "Symbol")
    GUICtrlSetColor(-1, 0x008000)
EndFunc

Func _DriveMap()
    DriveMapDel("P:")
    DriveMapDel("S:")
    DriveMapAdd("S:", "\\share1$", 1)
    DriveMapAdd("P:", "\\share2$", 1)
    $S = DriveMapGet("S:")
    $P = DriveMapGet("P:")
    If $P = "\\share2$" then
        GUICtrlCreateLabel($P, 48, 174, 180, 17)
        sleep(1000)
        _Checkmark(227,174,41,17)
    EndIf
    sleep(1000)
    If $S = "\\share1$" Then
        GUICtrlCreateLabel($S, 48, 199, 180, 17)
        sleep(1000)
        _Checkmark(227,199,41,17)
    EndIf
EndFunc   ;==>_DriveMap

Thank you for your invaluable help on the core of this project. :D

Edited by PnoT
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...