Jump to content

Recommended Posts

Posted

hello all,

im trying to make an app that allows a user to connect to a remote computer and edit ther regisroty settings.

ive read the help file but im still not sure of how to do this task.

i want the information of the hole registarty brought back in to a tree view GUI format and then after it is this tree view then an able to edit the settings.

OO i have full access to this other system.

thanks all.

Posted

yea i need help how to make the app

if i use the information from the help file i can get sominformation back with this bit of code.

$info = RegRead("\\john-pc\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion", "ProgramFilesDir")
MsgBox(0,0,$info)

but i just dont want that one entry i want the hole of the restory bringing back to a tree view gui.

hop you under stand what im getting at.

thanks

Posted

I want world peace.

Jokes aside, I'm under it.

Look for RegEnumKey() and RegEnumVal() functions. But you must know that registry (yes that's it, if you were wondering) is a big place.

♡♡♡

.

eMyvnE

Posted

thats the probelm i dont know the vales as on all systems the values are going to different all the time. some systems are win xp, vista, win 7 on and ME.

any more idears???

Posted

The following should give you a good head start. Its a script I'm working on as I need to search the registry too. Keep in mind this script will only function when a user account is logged in. So Its not exactly what you wanted, but you can modify to your hearts content to do what you need.

The other piece I'm not giving you is an INI file which you need to make this work, but look at the script and you should see what you need in the INI file.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=..\EW.ico
#AutoIt3Wrapper_outfile=regedit_search.exe
#AutoIt3Wrapper_UseUpx=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****


#include <Array.au3>
#include <GuiConstantsEx.au3>
#include <ClipBoard.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <INet.au3>


;   NOTE:
;The following variable will need to be updated if the path this script runs from changes
;
$iniFile = "C:\regsearch\settings.ini"                      ;ini file storing items for SendMail function and path variables


$searchFinClass = "#32770"                                  ;Class value of "finished searching registry" window
$searchFinTitle = "Registry Editor"                         ;Title of "finished searching registry" window
Dim $aPathsFound[10] = ["Beginning"]                        ;array of found values
$loopEnd = 8                                                ;value loop run to, set to 8 loop will run 9 tiumes, counter starts at 0
$loopCounter = 0                                            ;loop counter that keeps track of the number of times loop has ran
Local $boolFinSearchFound = False                           ;boolean used to determine if "finished searching registry" window is found
$regKeyFound = False                                        ;boolean used to determine if all reg keys have been found
$emailSubjectError = "Registry Found Script Error: "        ;variable with a commonly used string for the subject of error notifications
$drive = "C:"
$regSearchFolder = "\regsearch"
$scriptFolder = $drive & $regSearchFolder

;SendMail function variables
$emailSubject = ""
$emailBody0 = ""
$emailBody2 = ""
$emailBody4 = ""
$emailBody5 = ""

;read path information from sendmail.ini
$pathDrive = IniRead ( $iniFile, "Settings", "1", "Error" ) ;path drive letter
$pathRoot = IniRead ( $iniFile, "Settings", "2", "Error" ) ;path root folder location
$regEdit = IniRead ( $iniFile, "Settings", "3", "Error" ) ;Registry Editory and full path
$regSearch = IniRead ( $iniFile, "Settings", "4", "Error" ) ;registry key to search for
$pathFull = $pathDrive & $pathRoot

;Check if script was able to read from INI
If $pathDrive = "Error" or $pathRoot = "Error" or $regEdit = "Error" or $regSearch = "Error" Then
    $emailSubject = "Registry Search Script: INI Read Error"
    $emailBody0 = "The script could not read the settings.ini file, specifically the Path section."
    $emailBody2 = "If any of the below variables show as error, check to make sure the INI file exists and is being called and read by the script properly."
    $emailBody4 = "$pathDrive: " & $pathDrive & ". $pathRoot: " & $pathRoot & ". $regEdit: " & $regEdit & ". $regSearch: " & $regSearch
    $emailBody5 = "Location of Error: run Registry Editor program loop on server: " & @ComputerName
    SendMail ( $emailSubject, $emailBody0, $emailBody2, $emailBody4, $emailBody5 )
    Exit
EndIf




While 1                 ; Window close loop
    $WindowTitle = WinGetTitle ( "", "" )
    Select
        Case $WindowTitle <> ""
            $winTitleKill = WinList()
            For $i = 1 to $winTitleKill[0][0]
                ; Only display visble windows that have a title
                If $winTitleKill[$i][0] <> "" AND IsVisible ( $winTitleKill[$i][1] ) Then
                    ;Close each open window
                    WinKill ( $winTitleKill[$i][0] )
                EndIf
            Next
            ExitLoop
        Case Else
            ;No open Windows exist, continue with script
            ExitLoop
    EndSelect
WEnd

Sleep ( 5000 )

While 1         ;run Registry Editor program loop
    Select
        Case FileExists ( $regEdit )
            Sleep ( 2000 )
            Run ( $regEdit )
            Sleep ( 2000 )
            Send ( "{HOME}" )
            Sleep ( 500 )
            ExitLoop
        Case Else
            ;Registry Editor program could not be found
            $emailSubject = "Registry Search Script: Registry Editor program not Found"
            $emailBody0 = "The Registry Editor program should be located at: " & $regEdit
            $emailBody2 = "Edit the path and/or filename in the settings.ini file to fix this issue"
            $emailBody4 = ""
            $emailBody5 = "Location of Error: run Registry Editor program loop"
            SendMail ( $emailSubject, $emailBody0, $emailBody2, $emailBody4, $emailBody5 )
            Exit
    EndSelect
WEnd

Sleep ( 500 )

;Run loop from loop counter to loop end variable
Do
    If $loopCounter = 0 Then
        ;When $loopCounter = 0 the loop is running for the first time, so open the search dialogue,
        ; paste in the search string, and tab to the "Enter" button and send the enter key to search
        Send ( "{F3}" )
        Sleep ( 500 )
        Send ( $regSearch, 1 )
        Sleep ( 500 )
        Send ( "{TAB}" )
        Sleep ( 500 )
        Send ( "{TAB}" )
        Sleep ( 500 )
        Send ( "{TAB}" )
        Sleep ( 500 )
        Send ( "{TAB}" )
        Sleep ( 500 )
        Send ( "{ENTER}" )

        ;The following loop looks at the window title and determines if the string was found
        While 1
            $WindowTitle = WinGetTitle ( "", "" )           ;Store Window title in variable
            Select
                Case $WindowTitle = "Find"
                    ;Still searching for search string
                Case Else
                    ;No longer searching, value found, or the value wasn't found at all, so exit loop.
                    ;This will exit the If statement too and so the code under the Else will not execute.
                    ExitLoop
            EndSelect
        WEnd

    ;Else statement below belongs to the IF statement above and will only execute if the script
    ; found the search string after the first search
    Else
        Send ( "{F3}" )
        While 1
            $WindowTitle = WinGetTitle ( "", "" )           ;Store Window title in variable
            Select
                Case $WindowTitle = "Find"
                    ;Still searching for search string
                Case Else
                    ;No longer searching, value found, exit loop which will also exit the IF statement
                    ExitLoop
            EndSelect
        WEnd
    EndIf

    Sleep ( 2000 )

    ;Call the winClass function to determine if the finished searching the registry popup has appeared
    $boolFinSearchFound = winClass ( $searchFinClass, $searchFinTitle )

    ;This loop will take two different actions depending on if the registry search has finished or not
    While 1
        Select
            ;Finished searching the registry popup has NOT been found
            Case $boolFinSearchFound = False
                ;Copy key to clipboard
                Sleep ( 1500 )
                Send ( "{TAB}" )
                Sleep ( 1000 )
                Send ( "!e" )
                Sleep ( 1500 )
                Send ( "c" )
                Sleep ( 500 )
                $WindowTitle = WinGetTitle ( "", "" )           ;Store Window title in variable
                _ClipBoard_Open ( $WindowTitle )                ;Open the clipboard so it cannot be changed
                $keyPath = ClipGet()                            ;put clipboard contents into variable
                _ClipBoard_Close ()                             ;Clipboard contents is stored in variable, close clipboard
                Sleep ( 2000 )
                ExitLoop
            ;Finished searching the registry popup HAS been found
            Case $boolFinSearchFound = True
                ;The class of the finished searching registry popup was found, set loop end to stop loop
                $loopEnd = $loopCounter
                $loopEnd += 1
                Sleep ( 500 )
                Send ( "{ENTER}" )
                Sleep ( 500 )
                Send ( "{HOME}" )
                Sleep ( 500 )
                $regKeyFound = True
                ExitLoop
        EndSelect
    WEnd
    $keyPathFull = $keyPath & "\" & $regSearch      ;Concatnate the search string to the found path
    $aPathsFound[$loopCounter] = $keyPathFull       ;add the key path copied from the registry to the array
    $loopCounter += 1                               ;add one to the counter
Until $loopCounter = $loopEnd

While 1
    $WindowTitle = WinGetTitle ( "", "" )               ;Store Window title in variable
    Select
        Case $WindowTitle = "Registry Editor"
            WinActivate ( $WindowTitle )
            WinClose ( $WindowTitle )                           ;Close registry if open
            ExitLoop
    EndSelect
WEnd

While 1
    Select
        Case $regKeyFound = True
            ;Proxy registry key found, send out email
            $emailSubject = "Server: '" & @ComputerName & "' has Proxy Currently Turned on"
            $emailBody0 = "Registry key used for setting IE proxy has been found. Please turn off this setting."
            $emailBody2 = "Server: " & @ComputerName & " needs to have the proxy turned off."
            $emailBody4 = "Go into Internet Options, Connections tab, LAN settings, and uncheck box for proxy setting."
            SendMail ( $emailSubject, $emailBody0, $emailBody2, $emailBody4, "" )
            ExitLoop
    EndSelect
WEnd

Func winClass ( $winClass, $winTitle )
    Local $aWindows, $i, $text, $winClassTemp = "", $winTitleTemp = ""
    $aWindows = _WinAPI_EnumWindows()

    Sleep ( 2000 )
    ;Check through the handles to find the class associated with the finished searching the registry popup
    For $i = 1 To $aWindows[0][0]
        ;variables with class value and window title from current array position
        $winClassTemp = $aWindows[$i][1]
        $winTitleTemp = WinGetTitle($aWindows[$i][0])
        ;convert to string
        ;$winClassTemp = StringFormat ( )
        ;If statement to check if the class from the current array position is equal to class value passed to this function
        If $winClassTemp = $winClass and $winTitleTemp = $winTitle Then
            ;class values match so exit the loop which should exit the function
            $boolFinSearchFound = True
            ExitLoop
        Else
            $boolFinSearchFound = False

        EndIf
    Next
    Return $boolFinSearchFound
EndFunc

;Sendmail Function
Func SendMail ( $emailSubject, $emailBody0, $emailBody2, $emailBody4, $emailBody5 )
    $s_FromAddress = IniRead ( $iniFile, "Mail", "1", "Error" )
    $s_ToAddress =   IniRead ( $iniFile, "Mail", "2", "Error" )
    $s_SmtpServer =  IniRead ( $iniFile, "Mail", "3", "Error" )
    $s_FromName = "Registry Script Notifications - DO NOT REPLY"
    $s_Subject = "DO NOT REPLY -- " & $emailSubject
    Dim $as_Body[7]
    $as_Body[0] = $emailBody0
    $as_Body[1] = ""
    $as_Body[2] = $emailBody2
    $as_Body[3] = ""
    $as_Body[4] = $emailBody4
    $as_Body[5] = ""
    $as_Body[6] = $emailBody5
    _INetSmtpMail ( $s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body )
EndFunc

;Window Visible Function, used for Window Close Loop
Func IsVisible ( $handle )
    If BitAnd ( WinGetState ( $handle), 2 ) Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc

I gave up trying to search a remote registry because I found that the item I'm searching for, the proxy information for IE, only shows up when a user is logged in. So I'm just going to have an account log in and run this script instead.

Good luck

Posted

ok guys i got this to part work here what i got

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>

$pc = "\\john-pc"

$Form1 = GUICreate("Form1", 625, 443, 192, 124)
$Edit1 = GUICtrlCreateEdit("", 28, 199, 569, 201, BitOR($ES_READONLY,$ES_WANTRETURN,$WS_VSCROLL,$WS_BORDER))
GUICtrlSetData(-1, "")
$Button1 = GUICtrlCreateButton("Close", 64, 128, 75, 25)
GUISetState(@SW_SHOW)

for $i = 1 to 100
    $info = RegEnumKey($pc&"\HKLM\software\microsoft\windows\currentversion\uninstall\", $i)
    ;$info2 = RegEnumVal($pc&"\HKLM\software\microsoft\windows\currentversion\uninstall\"&$info , $i)
    if @error <> 0 then ExitLoop
    ;MsgBox(4096,0,$info2)
    GUICtrlSetData($Edit1, $i &" "& $info, 1)
    GUICtrlSetData($Edit1, @CRLF, 1)
Next


While 1

    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $Button1
            Exit

    EndSwitch

WEnd

but i want ti to only show the apps that are installed only the programs names EG office 2007, AVG 9 ect but not {884856456456123_pojihuu}_1 classes

Posted

umm can you network your computers? If so regedit can can connect to a network registry as one of its built in features. Go Microsoft!

Posted

@madmorgan

For searching the registry, look at this thread. There are examples above the updated function post. It does take some time to search a remote registry depending on how deep or shallow the start key is. To seach a remote registry key, use _RegSearch(\\remotepcname\startkey, searchvalue, 7, True). This will return all key names, value names, and value data that contain the searchvalue in an array. You can also have it return only key names, value names, or value data. I have used this function in many projects.

@Webs

To access HKCU registry hives, use the Registry UDF on this thread. This will work on local as well as a remote registry. One note, when accessing a remote hive, it will only access domain users, not local users. When accessing a hive on a local registry, this is not a problem. Using this UDF and the function I mentioned above, you should be able to create a UDF to search remote HKCU registry hives for domain users.

Hope this help.

Adam

  • Moderators
Posted

This may be completely unrelated to what you're trying to do, but I have a script that opens the remote RegEdit for me, to a specific key. I use this for validation on what is installed through Add or Remove Programs. The script prompts you for computer name, and then connects and opens that key. You could always change the last line to reflect the key you'd like to access.

$input = InputBox( "Enter asset tag", "Please enter the machine ID" )

Run( "regedit.exe" )

WinWaitActive( "Registry Editor" )

Send( "{LCTRL}, {HOME}, {LEFT}" )

Send( "!f, c" )

Send( $input & "{ENTER}" )

Send( "HK{RIGHT}SOFT{RIGHT}Micro{RIGHT}Window{RIGHT}Curren{RIGHT}Unins{RIGHT}" )

Jeremiah

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted

hello all,

i dont want to use regedit im put a muiti use app that gets information from the remote pc.

but with help from ADAMUL i have been able to do this now.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 625, 443, 192, 124)
$Edit1 = GUICtrlCreateEdit("", 28, 199, 569, 201, BitOR($ES_READONLY,$ES_WANTRETURN,$WS_VSCROLL,$WS_BORDER))
GUICtrlSetData(-1, "")
$Button1 = GUICtrlCreateButton("RUN", 64, 128, 75, 25)
GUISetState(@SW_SHOW)



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

EndSwitch

WEnd



Func _InstalledSoftware($sComputerName = @ComputerName) ;Finds all the for installed software on a remote PC with connection error logging.
    $iInstalledAppsCount = 1

While 2
        $sSubKey = RegEnumKey("\\" & $sComputerName & "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", $iInstalledAppsCount)
        $sDisplayName = RegRead("\\" & $sComputerName & "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $sSubKey, "DisplayName")
        $sDisplayVersion = RegRead("\\" & $sComputerName & "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $sSubKey, "DisplayVersion")

        If $sDisplayName <> "" And $sDisplayVersion <> "" Then
            GUICtrlSetData($Edit1,"App Name: " & $sDisplayName & ", Version: " & $sDisplayVersion, 1)
            GUICtrlSetData($Edit1, @CRLF, 1)
        EndIf
    $iInstalledAppsCount +=1
WEnd
EndFunc

but now i have a problem with it when i click the "RUN" button it list all the software installed but it want come out of the secound wihle loop to dive me control to close the program. i need help to fix this problem.

Posted

madmorgan,

You removed the @error check for the RegEnumKey function in the _InstalledSoftware function I gave you, when you edited it. This will not allow the the _InstalledSoftware function to exit and makes you GUI unresponsive. To simply exit the the function when all keys have been enumerated, add

If @error Then ExitLoop
under the
$sSubKey = RegEnumKey("\\" & $sComputerName & "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", $iInstalledAppsCount)
line. Your GUI will then become responsive again.

For more detailed @error catching for the RegEnumKey function, look at the original _InstalledSoftware function I gave you. If you are connecting to a remote PC, then you should have a conditional statement for an @error values of 1, 2, or 3, since these are remote registry access errors. These @error values are taken care of in the original function, you could just change the response to be a message box instead of an output file. Such as

Switch @error
    Case 1, 2, 3
        If @error = 1 Then MsgBox(16, "Connection Error", $sComputerName & " : ERROR: You Do Not Have Rights to Access the Remote Registry.", 0, $Form1)
        If @error = 2 Or @error = 3 Then MsgBox(16, "Connection Error", $sComputerName & " : ERROR: Unable to Connect to Remote Registry.", 0, $Form1)
        Return SetError(1, 0, 0)
    Case -1
        ExitLoop
EndSwitch

Adam

Posted (edited)

@JLogan3o13

Here is the original function that I gave madmorgan, that does what you do with regedit, but outputs the names and version numbers for installed software in to a separate CSV file for each computer. It also logs errors, and creates error log files as well.

#include <File.au3>
#include <Array.au3>

Func _InstalledSoftware($sComputerName = @ComputerName) ;Finds all the for installed software on a remote PC with connection error logging.
    $iInstalledAppsCount = 1
    $sErrorLogFileName = StringTrimRight(@ScriptFullPath, 4) & " Errors.log" ;Error log file.
    $sInstalledAppsLog = @ScriptDir & "\" & $sComputerName & " Installed Software.csv"
    $hInstalledAppsLogFile = FileOpen($sInstalledAppsLog, 1) ;Output to a CSV file.

    While 1

        $sSubKey = RegEnumKey("\\" & $sComputerName & "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", $iInstalledAppsCount)
        Switch @error
            Case 1, 2, 3
                If @error = 1 Then _FileWriteLog($sErrorLogFileName, $sComputerName & " : ERROR: You Do Not Have Rights to Access the Remote Registry.")
                If @error = 2 Or @error = 3 Then _FileWriteLog($sErrorLogFileName, $sComputerName & " : ERROR: Unable to Connect to Remote Registry.")

                $sNamesOnlyErrorLogFileName = StringTrimRight(@ScriptFullPath, 4) & " Errors-Names only.log"
                $iFoundComputerName = 0
                If FileExists($sNamesOnlyErrorLogFileName) Then
                    Local $aComputerNames
                    _FileReadToArray($sNamesOnlyErrorLogFileName, $aComputerNames)
                    For $iNameIndex = 1 To $aComputerNames[0] Step 1
                        If StringInStr($aComputerNames[$iNameIndex], $sComputerName) Then $iFoundComputerName += 1
                    Next
                EndIf

                If Not $iFoundComputerName Then
                    $hComputerNames = FileOpen($sNamesOnlyErrorLogFileName, 1)
                    FileWriteLine($hComputerNames, $sComputerName)
                    FileClose($hComputerNames)
                EndIf

                FileClose($hInstalledAppsLogFile)
                FileDelete($sInstalledAppsLog)
                Return SetError(1, 0, 0)
            Case -1
                ExitLoop
        EndSwitch

        $sDisplayName = RegRead("\\" & $sComputerName & "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $sSubKey, "DisplayName")
        $sDisplayVersion = RegRead("\\" & $sComputerName & "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $sSubKey, "DisplayVersion")

        If $sDisplayName <> "" Then FileWriteLine($hInstalledAppsLogFile, $sDisplayName & "," & $sDisplayVersion)

        $iInstalledAppsCount += 1

    WEnd

    FileClose($hInstalledAppsLogFile)

    Local $aInstalledApps
    _FileReadToArray($sInstalledAppsLog, $aInstalledApps)
;~  _ArrayDisplay($aInstalledApps) ;For Testing.
    _ArraySort($aInstalledApps, 0, 1)
;~  _ArrayDisplay($aInstalledApps) ;For Testing.
    _FileWriteFromArray($sInstalledAppsLog, $aInstalledApps, 1)
    _FileWriteToLine($sInstalledAppsLog, 1, "Display Name, Display Version") ;CSV file column headers.

    Return 1
EndFunc

This is nice when you are asked for a software list for a PC, when the hardware is going to be upgraded or it needs to be reloaded.

I also have a function to search for installed software by name, and output to a single CSV file for multiple PCs. I am still refining the output of that function.

Adam

Edit: Removed And $sDisplayVersion <> "" from the function, this was keeping the function from finding all the installed software. Some software registry entries do not have a DisplayVersion Value and RegRead will return "". This will cause that software to not be recorded as being installed when it actually is.

Edited by AdamUL
Posted (edited)

thanks Adamul,

i did not notice i removed the @error statment i feel so silly now :( and thanks for the help.

thanks.

Edited by madmorgan
Posted

@Webs

To access HKCU registry hives, use the Registry UDF on this thread. This will work on local as well as a remote registry. One note, when accessing a remote hive, it will only access domain users, not local users. When accessing a hive on a local registry, this is not a problem. Using this UDF and the function I mentioned above, you should be able to create a UDF to search remote HKCU registry hives for domain users.

Hope this help.

Adam

Thanks Adam, I will check it out.

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
  • Recently Browsing   0 members

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