Cirusnb

Set Checked / un-checked value according to Registry value

7 posts in this topic

#1 ·  Posted (edited)

Hi all, first post here ever, I'm working on a project, Helpdesk type tool.   I'm trying to set the State (Checked, Unchecked) of check boxes, and Or button, (a Toggle). this would be set by determining the Value of Certain Reg keys,    here is my phone below. $PC_select_data is the Computer Name so you could replace it with "@Computer".  

I looked and looked and couldn't find whats wrong. 

I'm new to Autoit somewhat. 

I may be complicating things by assigning Arrays for my controls, but I think this will work. 

the first part is fine, I get a Computer from a list (that I got from AD with Water's Awesome UDF)

please not I'm using onevent also, well. the UDF OnEventA that allows upto 4 ByVal or Ref's 

I get the Value $PC_selected_data

return the value to the Function

 I send a test Key with Regread, if I can't read it I launch sc.exe to run Remote Reg.

Then I read 5 values from the Remote Reg.   I assigned a Array of those Values and Also Assigned a Array of my CheckBoxes also.

Now my logic, if the Value of the REG key is "" (blank)   then UnCheck all the check boxes, else, Check them. Now, to make this more efficient, I put the Controls in an Array, of the Same Lenth. now here is the think, I run my script, it runs fine, finds the value, and Un-checks all of the check boxes, now if I go change one of the REG values, it does not Check them. because of the Logic for the For Loop.   I would have figured that If the first value of the Array $Run_as_MSIscheck =  somevalue that it would see that as a "ELSE" and Check the box. Since the For loop contains the If - then- Else, but I Understand that it only runs the first Block, IF the condition is True.  So I guess Am I totally off track? 

 

Func Check_PC_status($PC_select_Data)
local $pingPC
local $regtemp = ""
local $x = ""
local $Run_as_MSIcheck,$Run_as_CMDcheck,$Run_as_BATCheck,$Run_as_REGcheck
local $RUNas_chks[4] = [$MSI_runAs_chk,$CMD_runAs_chk,$BAT_runAs_chk,$REG_runAs_chk]
local $runAS_function_check[4] = [$Run_as_MSIcheck,$Run_as_CMDcheck,$Run_as_BATCheck,$Run_as_REGcheck]

;~ @error:  
;~ 1 = Host is offline
;~ 2 = Host is unreachable
;~ 3 = Bad destination
;~ 4 = Other errors

;Sends Ping to pc to see if its live or not.
    
$pingPC = ping($PC_select_Data,2000)
;if Ping has returned a good value, NOT 0.  check current status of the following lines in registry. checkes for RunAS for CMD/MSI/BAT and Remote REG keys. checks for SMS prompt control.  
if $pingPC Then  
                
;tries to read a key from the registry, and returns its value, if its blank,
$regtemp = RegRead("\\" & $PC_select_Data & "\HKLM\SOFTWARE\Microsoft\SMS\Client\Client Components\Remote Control", "Permission Required")
ConsoleWrite("Sending test Key, is set to: " & $regtemp & @CRLF) 

;~error: 3 = Bad destination
if @error = 3  or $regtemp = "" Then
    ConsoleWrite("Unable to determine status of remote registry!!!" & @CRLF & "Trying to start Remote Registry.... via Service Control Manager" & @CRLF )

RunWait(@SystemDir & '\sc.exe \\' & $PC_select_Data & ' start RemoteRegistry',"","")
    if Not @error then 
    ConsoleWrite("Remote Registry loaded" & @CRLF & @CRLF)
    EndIf
EndIf
        
            TCPStartup()
                $IPadd = TCPNameToIP ($PC_select_Data)
                ConsoleWrite($IPadd & @CRLF)
            TCPShutdown()
                
            ConsoleWrite("ping Success: " & $pingPC & "ms" & @CRLF)
            
            $Sccm_PROMPTcheck = RegRead("\\" & $PC_select_Data & "\HKLM\SOFTWARE\Microsoft\SMS\Client\Client Components\Remote Control", "Permission Required")
            $Run_as_MSIcheck =  RegRead("\\" & $PC_select_Data & "\HKEY_CLASSES_ROOT\Msi.Package\shell\runas\command", "")  ; MSI access Check
            $Run_as_CMDcheck =  RegRead("\\" & $PC_select_Data & "\HKEY_CLASSES_ROOT\cmdfile\shell\runas\command", "")  ; CMS access Check
            $Run_as_BATCheck =  RegRead("\\" & $PC_select_Data & "\HKEY_CLASSES_ROOT\batfile\shell\runas\command", "")  ; BAT access Check
            $Run_as_REGcheck =  RegRead("\\" & $PC_select_Data & "\HKEY_CLASSES_ROOT\regfile\shell\runas\command", "")  ; REG access Check
            
            ConsoleWrite("SMS Client status: " & $Sccm_Promptcheck & @CRLF & "MSI RunAS Status: " & $Run_as_MSIcheck & @CRLF & "CMD RunAs Status: " & $Run_as_CMDcheck & @CRLF & "BAT RunAs Status: " & $Run_as_BATCheck & @CRLF & "REG RunAs Status: " & $Run_as_REGcheck & @CRLF & @CRLF)
    
            
    
        for $x = 0 to UBound($runAS_function_check) -1
            ConsoleWrite("Count: " & $x & @CRLF)
            
            if $runAS_function_check[$x] = "" Then
                                
                $test1 = guictrlread($RUNas_chks[$x])
                ConsoleWrite("B4 " & $test1 & @CRLF)
                
                GUICtrlSetState($RUNas_chks[$x],$GUI_UNCHECKED)
            
                $test2 =  guictrlread($RUNas_chks[$x])
                ConsoleWrite("After " & $test2 & @CRLF)
            
            Else
                
                    GUICtrlSetState($RUNas_chks[$x],$GUI_CHECKED)
                        
        EndIf
            
            
        Next
    
    Else
        
    ConsoleWrite($PC_select_Data & " is Not reachable" & @CRLF & @CRLF)
    
    
    EndIf
    
    
Endfunc

any help is appreciated. 

Edited by Cirusnb

Share this post


Link to post
Share on other sites



It's a little confusing.  I don't see any checkboxes in your snippet above.  I see your arrays which you are filling with zeros.  

I think know where you're going with this, but the execution isn't quite right.  

When you are doing your RegReads to update the *check variables, are you expecting that the arrays are being updated?  It doesn't work that way.  

I'd recommend something like this (apologies if this isn't the direction you wanted to take and this just added confusion)
 

;...
;Create Enumerated Variables - Human Friendly Array Indexes ;)
Local Enum $Run_as_MSIcheck, $Run_as_CMDcheck, $Run_as_BATCheck, $Run_as_REGcheck
;Create Array
Local $RUNas_chks[4]
;...
;Read Registry Values into Array
$RUNas_chks[$Run_as_MSIcheck] =  RegRead("\\" & $PC_select_Data & "\HKEY_CLASSES_ROOT\Msi.Package\shell\runas\command", "")  ; MSI access Check
$RUNas_chks[$Run_as_CMDcheck] =  RegRead("\\" & $PC_select_Data & "\HKEY_CLASSES_ROOT\cmdfile\shell\runas\command", "")  ; CMS access Check
$RUNas_chks[$Run_as_BATCheck] =  RegRead("\\" & $PC_select_Data & "\HKEY_CLASSES_ROOT\batfile\shell\runas\command", "")  ; BAT access Check
$RUNas_chks[$Run_as_REGcheck] =  RegRead("\\" & $PC_select_Data & "\HKEY_CLASSES_ROOT\regfile\shell\runas\command", "")  ; REG access Check
;...etc.

 

1 person likes this

Share this post


Link to post
Share on other sites

Like this?
 

Global $hForm = GUICreate("PC Status", 340, 90)
GUICtrlCreateLabel("PC: ", 24, 16, 32, 17)
Global $cSMS = GUICtrlCreateCheckbox("SMS", 16, 48, 46, 17)
Global $cMSI = GUICtrlCreateCheckbox("MSI", 64, 48, 46, 17)
Global $cCMD = GUICtrlCreateCheckbox("CMD", 112, 48, 46, 17)
Global $cBAT = GUICtrlCreateCheckbox("BAT", 160, 48, 46, 17)
Global $cREG = GUICtrlCreateCheckbox("REG", 208, 48, 46, 17)
Global $PC = GUICtrlCreateInput(@IPAddress1, 56, 16, 185, 21)
Global $CheckPC = GUICtrlCreateButton("Check", 256, 16, 73, 49)
Global $cStatus = GUICtrlCreateLabel("", 8, 72, 324, 17, BitOR(0x1, 0x0200))
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $CheckPC
            _CheckPC_Status(GUICtrlRead($PC))
    EndSwitch
    Sleep(10)
WEnd

Func _CheckPC_Status($sPC_Name)
    If StringStripWS($sPC_Name, 9) = "" Then Return SetError(1, 0, 0)
    Local $Sccm_PROMPTcheck, $sMSIcheck, $sCMDcheck, $sBATCheck, $sREGcheck, $sIPAddress, $regtemp, $iPID, $sOutput
    Local $pingPC = Ping($sPC_Name, 2000)
    If $pingPC Then
        $regtemp = RegRead("\\" & $sPC_Name & "\HKLM\SOFTWARE\Microsoft\SMS\Client\Client Components\Remote Control", "Permission Required")
        If @error = 3 Or $regtemp = "" Then
            ConsoleWrite("!Unable to determine status of remote registry!!!" & @CRLF & "-Trying to start Remote Registry.... via Service Control Manager" & @CRLF)
            $iPID = Run('"' & @SystemDir & '\sc.exe" ' & "\\" & $sPC_Name & ' start RemoteRegistry', "", @SW_HIDE, 8)
            ProcessWaitClose($iPID)
            $sOutput = StdoutRead($iPID)
            If StringInStr($sOutput, "FAILED") Then
                GUICtrlSetData($cStatus, "Can't load Remote Registry !")
                ConsoleWrite("! Can't load Remote Registry !" & @CRLF)
                Return SetError(2, 0, 0)
            Else
                GUICtrlSetData($cStatus, "Remote Registry loaded")
                ConsoleWrite("+Remote Registry loaded" & @CRLF)
            EndIf
        EndIf
        TCPStartup()
        $sIPAddress = TCPNameToIP($sPC_Name)
        ConsoleWrite("!IP: " & $sIPAddress & @CRLF)
        TCPShutdown()
        ConsoleWrite("-Ping Success: " & $pingPC & "ms" & @CRLF)
        $Sccm_PROMPTcheck = RegRead("\\" & $sPC_Name & "\HKLM\SOFTWARE\Microsoft\SMS\Client\Client Components\Remote Control", "Permission Required")
        $sMSIcheck = RegRead("\\" & $sPC_Name & "\HKEY_CLASSES_ROOT\Msi.Package\shell\runas\command", "")
        $sCMDcheck = RegRead("\\" & $sPC_Name & "\HKEY_CLASSES_ROOT\cmdfile\shell\runas\command", "")
        $sBATCheck = RegRead("\\" & $sPC_Name & "\HKEY_CLASSES_ROOT\batfile\shell\runas\command", "")
        $sREGcheck = RegRead("\\" & $sPC_Name & "\HKEY_CLASSES_ROOT\regfile\shell\runas\command", "")
        RegWrite("\\" & $sPC_Name & "\HKEY_CLASSES_ROOT\regfile\shell\runas\command", "", "REG_DWORD", 1)
        _Check($Sccm_PROMPTcheck, $cSMS)
        _Check($sMSIcheck, $cMSI)
        _Check($sCMDcheck, $cCMD)
        _Check($sBATCheck, $cBAT)
        _Check($sREGcheck, $cREG)
        ConsoleWrite("+SMS Client status: " & $Sccm_PROMPTcheck & @CRLF & "+MSI RunAS Status: " & $sMSIcheck & @CRLF & "+CMD RunAs Status: " & $sCMDcheck & @CRLF & "+BAT RunAs Status: " & $sBATCheck & @CRLF & "+REG RunAs Status: " & $sREGcheck & @CRLF & @CRLF)
        GUICtrlSetData($cStatus, "PC Status check done!")
    Else
        ConsoleWrite($sPC_Name & " is Not reachable" & @CRLF & @CRLF)
        SetError(1, 0, 0)
    EndIf
EndFunc   ;==>_CheckPC_Status

Func _Check($Data, $Control)
    If StringStripWS($Data, 8) <> "" Then
        GUICtrlSetState($Control, 1)
    Else
        GUICtrlSetState($Control, 4)
    EndIf
EndFunc   ;==>_Check

 


Regards,
 

Share this post


Link to post
Share on other sites
On 5/19/2016 at 10:47 PM, Trong said:

awesome, thank you, I"m using ONevent tho. I really appreciate what you did the error checking for the Service Control.  I'll update my code and see if I can implement the check feature using Onevent (I am using 

 also, I"m also running AutoITstudio  for the GUI in a separate file.  Sorry for not including the GUI.  

I'll keep you posted :) thanks again. 

On 5/19/2016 at 10:47 PM, Trong said:
Global $hForm = GUICreate("PC Status", 340, 90)
GUICtrlCreateLabel("PC: ", 24, 16, 32, 17)
Global $cSMS = GUICtrlCreateCheckbox("SMS", 16, 48, 46, 17)
Global $cMSI = GUICtrlCreateCheckbox("MSI", 64, 48, 46, 17)
Global $cCMD = GUICtrlCreateCheckbox("CMD", 112, 48, 46, 17)
Global $cBAT = GUICtrlCreateCheckbox("BAT", 160, 48, 46, 17)
Global $cREG = GUICtrlCreateCheckbox("REG", 208, 48, 46, 17)
Global $PC = GUICtrlCreateInput(@IPAddress1, 56, 16, 185, 21)
Global $CheckPC = GUICtrlCreateButton("Check", 256, 16, 73, 49)
Global $cStatus = GUICtrlCreateLabel("", 8, 72, 324, 17, BitOR(0x1, 0x0200))
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $CheckPC
            _CheckPC_Status(GUICtrlRead($PC))
    EndSwitch
    Sleep(10)
WEnd

Func _CheckPC_Status($sPC_Name)
    If StringStripWS($sPC_Name, 9) = "" Then Return SetError(1, 0, 0)
    Local $Sccm_PROMPTcheck, $sMSIcheck, $sCMDcheck, $sBATCheck, $sREGcheck, $sIPAddress, $regtemp, $iPID, $sOutput
    Local $pingPC = Ping($sPC_Name, 2000)
    If $pingPC Then
        $regtemp = RegRead("\\" & $sPC_Name & "\HKLM\SOFTWARE\Microsoft\SMS\Client\Client Components\Remote Control", "Permission Required")
        If @error = 3 Or $regtemp = "" Then
            ConsoleWrite("!Unable to determine status of remote registry!!!" & @CRLF & "-Trying to start Remote Registry.... via Service Control Manager" & @CRLF)
            $iPID = Run('"' & @SystemDir & '\sc.exe" ' & "\\" & $sPC_Name & ' start RemoteRegistry', "", @SW_HIDE, 8)
            ProcessWaitClose($iPID)
            $sOutput = StdoutRead($iPID)
            If StringInStr($sOutput, "FAILED") Then
                GUICtrlSetData($cStatus, "Can't load Remote Registry !")
                ConsoleWrite("! Can't load Remote Registry !" & @CRLF)
                Return SetError(2, 0, 0)
            Else
                GUICtrlSetData($cStatus, "Remote Registry loaded")
                ConsoleWrite("+Remote Registry loaded" & @CRLF)
            EndIf
        EndIf
        TCPStartup()
        $sIPAddress = TCPNameToIP($sPC_Name)
        ConsoleWrite("!IP: " & $sIPAddress & @CRLF)
        TCPShutdown()
        ConsoleWrite("-Ping Success: " & $pingPC & "ms" & @CRLF)
        $Sccm_PROMPTcheck = RegRead("\\" & $sPC_Name & "\HKLM\SOFTWARE\Microsoft\SMS\Client\Client Components\Remote Control", "Permission Required")
        $sMSIcheck = RegRead("\\" & $sPC_Name & "\HKEY_CLASSES_ROOT\Msi.Package\shell\runas\command", "")
        $sCMDcheck = RegRead("\\" & $sPC_Name & "\HKEY_CLASSES_ROOT\cmdfile\shell\runas\command", "")
        $sBATCheck = RegRead("\\" & $sPC_Name & "\HKEY_CLASSES_ROOT\batfile\shell\runas\command", "")
        $sREGcheck = RegRead("\\" & $sPC_Name & "\HKEY_CLASSES_ROOT\regfile\shell\runas\command", "")
        RegWrite("\\" & $sPC_Name & "\HKEY_CLASSES_ROOT\regfile\shell\runas\command", "", "REG_DWORD", 1)
        _Check($Sccm_PROMPTcheck, $cSMS)
        _Check($sMSIcheck, $cMSI)
        _Check($sCMDcheck, $cCMD)
        _Check($sBATCheck, $cBAT)
        _Check($sREGcheck, $cREG)
        ConsoleWrite("+SMS Client status: " & $Sccm_PROMPTcheck & @CRLF & "+MSI RunAS Status: " & $sMSIcheck & @CRLF & "+CMD RunAs Status: " & $sCMDcheck & @CRLF & "+BAT RunAs Status: " & $sBATCheck & @CRLF & "+REG RunAs Status: " & $sREGcheck & @CRLF & @CRLF)
        GUICtrlSetData($cStatus, "PC Status check done!")
    Else
        ConsoleWrite($sPC_Name & " is Not reachable" & @CRLF & @CRLF)
        SetError(1, 0, 0)
    EndIf
EndFunc   ;==>_CheckPC_Status

Func _Check($Data, $Control)
    If StringStripWS($Data, 8) <> "" Then
        GUICtrlSetState($Control, 1)
    Else
        GUICtrlSetState($Control, 4)
    EndIf
EndFunc   ;==>_Check

 

 

Share this post


Link to post
Share on other sites
On 5/19/2016 at 10:47 PM, Trong said:

awesome, thank you, I"m using ONevent tho. I really appreciate what you did the error checking for the Service Control.  I'll update my code and see if I can implement the check feature using Onevent (I am using 

 also, I"m also running AutoITstudio  for the GUI in a separate file.  Sorry for not including the GUI.  

I'll keep you posted :) thanks again. 

On 5/19/2016 at 10:47 PM, Trong said:
Global $hForm = GUICreate("PC Status", 340, 90)
GUICtrlCreateLabel("PC: ", 24, 16, 32, 17)
Global $cSMS = GUICtrlCreateCheckbox("SMS", 16, 48, 46, 17)
Global $cMSI = GUICtrlCreateCheckbox("MSI", 64, 48, 46, 17)
Global $cCMD = GUICtrlCreateCheckbox("CMD", 112, 48, 46, 17)
Global $cBAT = GUICtrlCreateCheckbox("BAT", 160, 48, 46, 17)
Global $cREG = GUICtrlCreateCheckbox("REG", 208, 48, 46, 17)
Global $PC = GUICtrlCreateInput(@IPAddress1, 56, 16, 185, 21)
Global $CheckPC = GUICtrlCreateButton("Check", 256, 16, 73, 49)
Global $cStatus = GUICtrlCreateLabel("", 8, 72, 324, 17, BitOR(0x1, 0x0200))
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $CheckPC
            _CheckPC_Status(GUICtrlRead($PC))
    EndSwitch
    Sleep(10)
WEnd

Func _CheckPC_Status($sPC_Name)
    If StringStripWS($sPC_Name, 9) = "" Then Return SetError(1, 0, 0)
    Local $Sccm_PROMPTcheck, $sMSIcheck, $sCMDcheck, $sBATCheck, $sREGcheck, $sIPAddress, $regtemp, $iPID, $sOutput
    Local $pingPC = Ping($sPC_Name, 2000)
    If $pingPC Then
        $regtemp = RegRead("\\" & $sPC_Name & "\HKLM\SOFTWARE\Microsoft\SMS\Client\Client Components\Remote Control", "Permission Required")
        If @error = 3 Or $regtemp = "" Then
            ConsoleWrite("!Unable to determine status of remote registry!!!" & @CRLF & "-Trying to start Remote Registry.... via Service Control Manager" & @CRLF)
            $iPID = Run('"' & @SystemDir & '\sc.exe" ' & "\\" & $sPC_Name & ' start RemoteRegistry', "", @SW_HIDE, 8)
            ProcessWaitClose($iPID)
            $sOutput = StdoutRead($iPID)
            If StringInStr($sOutput, "FAILED") Then
                GUICtrlSetData($cStatus, "Can't load Remote Registry !")
                ConsoleWrite("! Can't load Remote Registry !" & @CRLF)
                Return SetError(2, 0, 0)
            Else
                GUICtrlSetData($cStatus, "Remote Registry loaded")
                ConsoleWrite("+Remote Registry loaded" & @CRLF)
            EndIf
        EndIf
        TCPStartup()
        $sIPAddress = TCPNameToIP($sPC_Name)
        ConsoleWrite("!IP: " & $sIPAddress & @CRLF)
        TCPShutdown()
        ConsoleWrite("-Ping Success: " & $pingPC & "ms" & @CRLF)
        $Sccm_PROMPTcheck = RegRead("\\" & $sPC_Name & "\HKLM\SOFTWARE\Microsoft\SMS\Client\Client Components\Remote Control", "Permission Required")
        $sMSIcheck = RegRead("\\" & $sPC_Name & "\HKEY_CLASSES_ROOT\Msi.Package\shell\runas\command", "")
        $sCMDcheck = RegRead("\\" & $sPC_Name & "\HKEY_CLASSES_ROOT\cmdfile\shell\runas\command", "")
        $sBATCheck = RegRead("\\" & $sPC_Name & "\HKEY_CLASSES_ROOT\batfile\shell\runas\command", "")
        $sREGcheck = RegRead("\\" & $sPC_Name & "\HKEY_CLASSES_ROOT\regfile\shell\runas\command", "")
        RegWrite("\\" & $sPC_Name & "\HKEY_CLASSES_ROOT\regfile\shell\runas\command", "", "REG_DWORD", 1)
        _Check($Sccm_PROMPTcheck, $cSMS)
        _Check($sMSIcheck, $cMSI)
        _Check($sCMDcheck, $cCMD)
        _Check($sBATCheck, $cBAT)
        _Check($sREGcheck, $cREG)
        ConsoleWrite("+SMS Client status: " & $Sccm_PROMPTcheck & @CRLF & "+MSI RunAS Status: " & $sMSIcheck & @CRLF & "+CMD RunAs Status: " & $sCMDcheck & @CRLF & "+BAT RunAs Status: " & $sBATCheck & @CRLF & "+REG RunAs Status: " & $sREGcheck & @CRLF & @CRLF)
        GUICtrlSetData($cStatus, "PC Status check done!")
    Else
        ConsoleWrite($sPC_Name & " is Not reachable" & @CRLF & @CRLF)
        SetError(1, 0, 0)
    EndIf
EndFunc   ;==>_CheckPC_Status

Func _Check($Data, $Control)
    If StringStripWS($Data, 8) <> "" Then
        GUICtrlSetState($Control, 1)
    Else
        GUICtrlSetState($Control, 4)
    EndIf
EndFunc   ;==>_Check

 

 

Share this post


Link to post
Share on other sites
On 5/18/2016 at 8:03 PM, spudw2k said:

It's a little confusing.  I don't see any checkboxes in your snippet above.  I see your arrays which you are filling with zeros.  

I think know where you're going with this, but the execution isn't quite right.  

When you are doing your RegReads to update the *check variables, are you expecting that the arrays are being updated?  It doesn't work that way.  

I'd recommend something like this (apologies if this isn't the direction you wanted to take and this just added confusion)
 

;...
;Create Enumerated Variables - Human Friendly Array Indexes ;)
Local Enum $Run_as_MSIcheck, $Run_as_CMDcheck, $Run_as_BATCheck, $Run_as_REGcheck
;Create Array
Local $RUNas_chks[4]
;...
;Read Registry Values into Array
$RUNas_chks[$Run_as_MSIcheck] =  RegRead("\\" & $PC_select_Data & "\HKEY_CLASSES_ROOT\Msi.Package\shell\runas\command", "")  ; MSI access Check
$RUNas_chks[$Run_as_CMDcheck] =  RegRead("\\" & $PC_select_Data & "\HKEY_CLASSES_ROOT\cmdfile\shell\runas\command", "")  ; CMS access Check
$RUNas_chks[$Run_as_BATCheck] =  RegRead("\\" & $PC_select_Data & "\HKEY_CLASSES_ROOT\batfile\shell\runas\command", "")  ; BAT access Check
$RUNas_chks[$Run_as_REGcheck] =  RegRead("\\" & $PC_select_Data & "\HKEY_CLASSES_ROOT\regfile\shell\runas\command", "")  ; REG access Check
;...etc.

 

I might use your Array idea, the GUI are in the separate file, I forgot to include those. 

Share this post


Link to post
Share on other sites

WORKS PERFECT MAN!   so simple now that I see it.   

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

  • Similar Content

    • Jibberish
      By Jibberish
      Hello,
      I have used this forum to get help many times. I thought it was time to (hopefully) help others.
      I created a script that reads a text file with a list of videos, displays the videos in a GUI with checkboxes next to the names, and displays the selected videos. This will become a part of a larger script I am creating to test a video player. The tough part for me was creating the GUI and Dynamic list of videos. I had a lot of trouble finding samples to help me, but finally found one  written by Melba23. The link is in the code, so he gets credit for helping! I also have not used arrays much and they are very picky about looping through the arrays without getting the dreaded error " Array variable has incorrect number of subscripts or subscript dimension range exceeded."  However diligence paid off!
      To run this code, take the video names commented below and create a videos.txt file in your script execution directory. You can put however many video names in this list. Thus the dynamic features of the code.
      Cheers!
      Jibberish
      #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <array.au3> #include <File.au3> #include <GUIConstantsEx.au3> Local $sMediaFile = @ScriptDir & "\videos.txt" ;~ Videos in videos.txt are: ;~ bbb_1080_60s.mp4 ;~ bbb_1080_60s_1.mp4 ;~ bbb_1080_60s_2.mp4 ;~ tos_4K_60s_HEVC.mp4 ;~ tos_4K_60s_HEVC_1.mp4 ;~ tos_4K_60s_HEVC_2.mp4 ;~ ;~ Additional videos can be added to this list. The functions are Dynamic. Dim $aMediaManifest Local $aArrayFile Local $aVideos Local $sVideoName Local $i ; MAIN ; Put the Video File Names into an Array _FileReadToArray($sMediaFile, $aArrayFile) Local $iVideoCount = UBound($aArrayFile) -1 ; Get the number of videos - 1 to prevent errors _ArrayDelete($aArrayFile, 0) ;Counter just gets in the way ; Move backwards through the array deleting the blank lines For $i = $iVideoCount - 1 To 0 Step -1 If $aArrayFile[$i] = "" Then _ArrayDelete($aArrayFile, $i) EndIf Next $aVideos = DisplayVideos($aArrayFile) $iVideoCount = UBound($aArrayFile) -1 _ArrayDisplay($aVideos) ; Display the checked videos ;~ End of MAIN ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; GUI to display Videos in checkboxes ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Func DisplayVideos($aArrayFile) Local $iTop = -1 Local $iLeft = -1 Local $iWidth Local $iHeight = $iVideoCount * 30 Local $iL = 10 Local $iT = 10 Local $iRow = 0 Local $aVideo Local $iA = 0, $iB = 0 Local $sFill = "" $iMMCount = UBound($aArrayFile) $iMMNewCount = $iMMCount - 1 Local $aGUICheckbox[$iMMCount] Local $aCheckedVideos[$iMMCount] ; Put the Video File Names into an Array $hGUI = GUICreate("Video Checkbox", $iLeft, $iTop, $iWidth, $iHeight) GUICtrlCreateLabel("Videos", 180, $iT) $iT = $iT + 30 ; This is a great example of using arrays to create GUI check boxes or radio buttons For $i = 0 To $iMMNewCount Step 1 $sMP4Text = $aArrayFile[$i] $aGUICheckbox[$i] = GUICtrlCreateCheckbox($sMP4Text, 30, $iT) $iT += 30 Next $idClose1 = GUICtrlCreateButton("Start", $iL, $iT) GUISetState(@SW_SHOW) ; This section reads the checkboxes and puts the video names in an array in their original position ; in case this is important (as it is to me) ; This was the toughest part to code, and I found no samples online until I saw Melba23's sample here: ; https://www.autoitscript.com/forum/topic/119843-dynamic-gui-problem/#comment-832672 ; I got this working with only a little modification. THANK YOU MELBA23 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idClose1 For $i = 0 To $iMMNewCount Step 1 Switch GUICtrlRead($aGUICheckbox[$i]) Case $GUI_CHECKED $aCheckedVideos[$i] = $aArrayFile[$i] Case $GUI_UNCHECKED EndSwitch Next ExitLoop EndSwitch WEnd GUIDelete($hGUI) Return $aCheckedVideos EndFunc ;==>DisplayVideos  
    • Jibberish
      By Jibberish
      Hi,
      I am maybe an intermediate AutoIt script writer, but have no experience creating GUIs.
      I have a script with two functions. One for Checkboxes and another with radio buttons. Each function creates it's own window.
      I'd like to use one window with both checkboxes and radio buttons.
      I pulled samples from AutoIt Help and other places and worked it into this: (RadioCheck still uses the example Case and MsgBoxes. I will clean this up soon)
      Func CheckOptions() ; Create a GUI with various controls. Local $hGUI = GUICreate("SGX4CP Options", 275, 250) ; Create a checkbox control. Local $iLoopCheckbox = GUICtrlCreateCheckbox("Loop", 10, 10, 185, 25) Local $iFullScreenCheckbox = GUICtrlCreateCheckbox("Fullscreen", 10, 40, 185, 25) Local $iRestartPlaybackCheckbox = GUICtrlCreateCheckbox("Restart Playback from Sleep", 10, 70, 185, 25) GUICtrlSetState($iRestartPlaybackCheckbox, $GUI_CHECKED) Local $iDisableSleepCheckbox = GUICtrlCreateCheckbox("Disable Sleep", 10, 100, 185, 25) Local $iLogCheckbox = GUICtrlCreateCheckbox("Show Log", 10, 130, 185, 25) GUICtrlSetState($iLogCheckbox, $GUI_CHECKED) Local $idClose = GUICtrlCreateButton("Next", 110, 220, 85, 25) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClose ExitLoop Case $iLoopCheckbox If _IsChecked($iLoopCheckbox) Then $bLoopChecked = True Else $bLoopChecked = False EndIf Case $iFullScreenCheckbox if _IsChecked($iFullScreenCheckbox) Then $bFullScreenChecked = True Else $bFullScreenChecked = False EndIf Case $iRestartPlaybackCheckbox if _IsChecked($iRestartPlaybackCheckbox) Then $bRestartPlaybackChecked = True Else $bRestartPlaybackChecked = False EndIf Case $iDisableSleepCheckbox if _IsChecked($iDisableSleepCheckbox) Then $bDisableSleepChecked = True Else $bDisableSleepChecked = False EndIf Case $iLogCheckbox if _IsChecked($iLogCheckbox) Then $bLogChecked = True Else $bLogChecked = False EndIf EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc Func RadioCheck() GUICreate("Select Test",300,180) ; will create a dialog box that when displayed is centered Local $idRadio1 = GUICtrlCreateRadio("Loop Forever", 10, 10) Local $idRadio2 = GUICtrlCreateRadio("Play each video 3 times", 10, 40) Local $idRadio3 = GUICtrlCreateRadio("Play each video separately", 10, 70) GUICtrlSetState($idRadio1, $GUI_CHECKED) Local $idClose = GUICtrlCreateButton("Start Test", 120,100) GUISetState(@SW_SHOW) Local $idMsg ; Loop until the user exits. While 1 $idMsg = GUIGetMsg() Select Case $idMsg = $GUI_EVENT_CLOSE ExitLoop Case $idMsg = $idRadio1 And BitAND(GUICtrlRead($idRadio1), $GUI_CHECKED) = $GUI_CHECKED MsgBox($MB_SYSTEMMODAL, 'Info:', 'The app will run forever, playing each video once, then looping back to the first video.') $bTestSelectForever = True Case $idMsg = $idRadio2 And BitAND(GUICtrlRead($idRadio2), $GUI_CHECKED) = $GUI_CHECKED MsgBox($MB_SYSTEMMODAL, 'Info:', 'Each video will loop 3 times then move to the next video.') $bTestSelect3Times = True Case $idMsg = $idRadio3 And BitAND(GUICtrlRead($idRadio2), $GUI_CHECKED) = $GUI_CHECKED MsgBox($MB_SYSTEMMODAL, 'Info:', 'Player opens, first video plays, player closes. Player opens, second video plays, player closes, etc.') $bTestSelectSingleVideo = True EndSelect WEnd EndFunc I would like to combine the checkbox "Loop" and the radio button $idRadio2. Radio2 requires Loop to be checked.
      I planned to remove the Loop checkbox and only enable it if Radio2 is selected.
      Can I combine these two functions into one with one window with both Checkboxes and Radio Buttons?
      Thanks
      Jibberish
    • amphoric
      By amphoric
      Good Morning,
      I hope someone can help, below is a stripped down version of my current .au3 file and there is a few bits I just cant for the life of me get to work;
      1. I would like the 'Allow Edit' checkbox once checked to allow the user to edit the contents of the 'AD Group Name' input box
      2. I would like the 'Other / Internal Use' radio button if checked to show the '$OtherInternalGroup' group of radio buttons
      My current code.....
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIShellEx.au3> #include <FileConstants.au3> #include <WinAPIFiles.au3> #include <WinAPI.au3> ; used for Lo/Hi word ; Declare Global variables for WM_COMMAND and '_GetAppName()' function. Global $__iComboWrite = 9999, $__iInputValue = 9999, $__iInputWrite = 9999 #Region ### START GUI section ### $Form1_1 = GUICreate("Packaging Wrapper", 435, 545, -1, -1) GUISetIcon("C.ico", -1) GUISetBkColor(0xFFFFFF) Global $ApplicationNameInput = GUICtrlCreateInput("", 24, 168, 385, 21) GUICtrlSetTip(-1, "EG: Corel_WinZip_21.0_0.1") $ADGroupNameInput = GUICtrlCreateInput("", 24, 224, 385, 21) $AllowEditChk = GUICtrlCreateCheckbox("Allow Edit", 344, 200, 65, 17, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_RIGHT)) GUICtrlSetBkColor(-1, 0xE3E3E3) $ApplicationTypeGroup = GUICtrlCreateGroup("", 24, 272, 185, 113) $CatalogueAppChk = GUICtrlCreateRadio("Catalogue Application", 32, 288, 137, 17) GUICtrlSetBkColor(-1, 0xE3E3E3) $NonCatalogueAppChk = GUICtrlCreateRadio("Non-Catalogue Application", 32, 320, 161, 17) GUICtrlSetBkColor(-1, 0xE3E3E3) $OtherAppChk = GUICtrlCreateRadio("Other / Internal Use", 32, 352, 137, 17) GUICtrlSetBkColor(-1, 0xE3E3E3) GUICtrlCreateGroup("", -99, -99, 1, 1) ; $OtherInternalGroup = GUICtrlCreateGroup("", 216, 272, 193, 113) $OSCoreApplicationChk = GUICtrlCreateRadio("OS Core Application", 224, 288, 129, 17) GUICtrlSetState(-1, $GUI_HIDE) GUICtrlSetBkColor(-1, 0xE3E3E3) $InternalOnlyChk = GUICtrlCreateRadio("Internal ONLY Application", 224, 320, 161, 17) GUICtrlSetState(-1, $GUI_HIDE) GUICtrlSetBkColor(-1, 0xE3E3E3) GUICtrlCreateGroup("", -99, -99, 1, 1) $OtherInternalLabel = GUICtrlCreateLabel("Other / Internal Use", 216, 256, 118, 17, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetState(-1, $GUI_HIDE) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xE3E3E3) $ConfirmGroup = GUICtrlCreateGroup("", 24, 392, 385, 89) $Confirm = GUICtrlCreateCheckbox("I confirm all details are correct, and I wish to proceed", 48, 456, 329, 17, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_CENTER)) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, 0xE3E3E3) $ConfirmDesc = GUICtrlCreateEdit("", 32, 408, 361, 41, 0, 0) GUICtrlSetData(-1, StringFormat("Please confirm that all entered information is correct, and the you wish to \r\nproceed with the creation of the " & Chr(39) & "Application Toolkit Wrapper" & Chr(39) & ".")) GUICtrlSetBkColor(-1, 0xE3E3E3) GUICtrlCreateGroup("", -99, -99, 1, 1) $ProceedBtn = GUICtrlCreateButton("Proceed", 128, 488, 75, 25) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x008000) $CancelBtn = GUICtrlCreateButton("Cancel", 240, 488, 75, 25) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFF0000) $CapitaLogo = GUICtrlCreatePic("Logo.jpg", 24, 8, 159, 33) $PackagingWrapperLabel = GUICtrlCreateLabel("Packaging Wrapper", 224, 8, 187, 28) GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x000000) $CreatedByLabel = GUICtrlCreateLabel("...", 16, 528, 405, 15, $SS_CENTER) GUICtrlSetFont(-1, 7, 400, 0, "MS Serif") $VerLabel = GUICtrlCreateLabel("Ver. 1.0 ALPHA", 328, 40, 79, 17) $Step1Label = GUICtrlCreateLabel("Please Enter The Following Information", 24, 80, 274, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x000080) GUICtrlSetBkColor(-1, 0xE3E3E3) $Graphic3 = GUICtrlCreateGraphic(16, 72, 404, 452, BitOR($GUI_SS_DEFAULT_GRAPHIC, $SS_SIMPLE)) GUICtrlSetColor(-1, 0xE3E3E3) GUICtrlSetBkColor(-1, 0xE3E3E3) $ApplicationNameDesc = GUICtrlCreateEdit("", 24, 128, 393, 33, 0, 0) GUICtrlSetData(-1, StringFormat("Must be in the following format: Manufacturer_AppName_AppVersion_Rev\r\nEG: Corel_WinZip_21.0_01")) GUICtrlSetBkColor(-1, 0xE3E3E3) $ADGroupNameLabel = GUICtrlCreateLabel("AD Group Name", 24, 200, 95, 17, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xE3E3E3) $ApplicationNameLabel = GUICtrlCreateLabel("Application Name", 24, 112, 103, 17, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xE3E3E3) $ApplicationTypeLabel = GUICtrlCreateLabel("Application Type", 24, 256, 99, 17, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xE3E3E3) GUISetState(@SW_SHOW) #EndRegion ### END GUI section ### ;GLOBAL VARIABLES Global $ApplicationName, $adstring1 Global $ADGroupName = $adstring1 Global $envSystemDrive = EnvGet("systemdrive") Global $PackagingDirectory = "Packaging\???_Apps" Global $FullDir = $envSystemDrive & "\" & $PackagingDirectory & "\" & $ApplicationName Global $currentDate = @MDAY &"-"& @MON &"-"& @YEAR Global $currentTime = @HOUR &":"& @MIN &":"& @SEC ; Register the WM_COMMAND to intercept when the value in the first input's value is changed. GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND') While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $CancelBtn Exit Case $ProceedBtn ;Check Application Name Validity $ApplicationNameInputValid = StringSplit(GUICtrlRead($ApplicationNameInput), "_") If $ApplicationNameInputValid[0]<> 4 Then ConsoleWrite("Application Name - NOT Valid" & @CRLF) $ApplicationNameInputValidYes = 0 MsgBox(0,"Are The Details Correct?", "Application Name NOT Valid.") GUICtrlSetState($ApplicationNameInput,$GUI_FOCUS) Elseif $ApplicationNameInputValid[0]= 4 Then ConsoleWrite("Application Name - Valid" & @CRLF) $ApplicationNameInputValidYes = 1 EndIf ;Is Confirm Checkbox 'Checked' if GUICtrlRead($Confirm) = $GUI_CHECKED Then ConsoleWrite("$Confirm - ticked" & @CRLF) $ConfirmYes = 1 Else $ConfirmYes = 0 ConsoleWrite("$Confirm - NOT ticked" & @CRLF) MsgBox(0,"Are The Details Correct?", "Please complete confirmation.") EndIf ;Is $CatalogueAppChk 'Checked' if GUICtrlRead($CatalogueAppChk) = $GUI_CHECKED Then ConsoleWrite("$CatalogueAppChk - ticked" & @CRLF) $CatalogueAppChkYes = 1 Else ConsoleWrite("$CatalogueAppChk - NOT ticked" & @CRLF) $CatalogueAppChkYes = 0 EndIf ;Is $NonCatalogueAppChk 'Checked' if GUICtrlRead($NonCatalogueAppChk) = $GUI_CHECKED Then ConsoleWrite("$NonCatalogueAppChk - ticked" & @CRLF) $NonCatalogueAppChkYes = 1 Else ConsoleWrite("$NonCatalogueAppChk - NOT ticked" & @CRLF) $NonCatalogueAppChkYes = 0 EndIf ;Is $OtherAppChk 'Checked' if GUICtrlRead($OtherAppChk) = $GUI_CHECKED Then ConsoleWrite("$OtherAppChk - ticked" & @CRLF) $OtherAppChkYes = 1 Else ConsoleWrite("$OtherAppChk - NOT ticked" & @CRLF) $OtherAppChkYes = 0 EndIf ConsoleWrite(@CRLF & "##### COMPLETED #####" & @CRLF) EndSwitch WEnd ;Check for 'Application Name' update Func _GetAppName() $adString = StringReplace(GUICtrlRead($ApplicationNameInput), "_", " ",2) $adstrings = StringSplit($adString, "_") Global $adString1 = $adstrings[1] Global $ApplicationName = GUICtrlRead($ApplicationNameInput) GUICtrlSetData($ADGroupNameInput, $adstring1) EndFunc ;WM_COMMAND Function used for Auto Input of fields Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $lParam Local $iHiWord = _WinAPI_HiWord($wParam) ; Control identification code. Local $iLoWord = _WinAPI_LoWord($wParam) ; Control identifier. Switch $iHiWord Case $EN_CHANGE ; When a change event is intercepted. Switch $iLoWord ; Retrieve the controlid. Case _GetAppName() ; If it matches the first input then call the custom function _GetInput. ConsoleWrite("Debug: value was changed." & @CRLF) _GetAppName() EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND I hope all this makes sense.
      Thanks in advance
    • jannikrendl
      By jannikrendl
      Hey guys,
      I would like to learn how the whole GUI stuff is working so I try to understand it step by step...
      First of all I created a GUI with a single button. My goal is to activate an infinite while loop as soon as the checkbox is checked and to deactive the infinite while loop as soon as I uncheck the checkbox, but I don't understand how... I read various threads but couldn't find a good example etc...
      Thanks in advance 
    • Terenz
      By Terenz
      Hello,
      I have searched everywhere but on the forum there isn't an example of a combobox with checkbox. I think is a very useful control but require subclassing. Several example in C++, one of this:
      CheckComboBox Control
      If somone has some time to check it out. If need i can provide the source code. Thanks