Jump to content
Sign in to follow this  

anyone tested the code in the link

Recommended Posts

Has anyone tested out the code from the topic below?


Before I even ask my question in short detail I am curious if some of the guys here put the code through its paces. 



Edited by Briandr

Share this post

Link to post
Share on other sites

I don't but a script from 2007 could't run as there are many changes in AutoIT, especialy script breaking changes. and i wouldn't why test code which makes trouble, as Arthur said.

Share this post

Link to post
Share on other sites

This is more recent and linked at the end of that thread.


I have tried/played with some of these.  I do not remember them working perfectly and probably why I created my own.

I used the security.udf and wrote a loop to load/unload hive files and make the changes as needed.  Got to custom tailor what profiles I wanted loaded this way.


Share this post

Link to post
Share on other sites

I can offer a little more since I feel comfortable someone can at least give me pointers. We have to use HP Connection Mgr. Why I am not sure, but if you seen it on newer Revolves laptops it's pop up notifications are fairly aggressive. I found the keys in the registry to disable and the AutoIT script does so via HKCU. What I need is to make sure existing as well as future users have these settings disabled. If you are wondering I have gotten my hands on the MSI installers and unless I missed something in Orca I could not locate what would disable these pop ups or at least turn them off. So back to AutoIT. One thought was to copy the AutoIT script to Roaming Users Start Up folder and then code it so the script self destructs after it runs. 

Vicious, I will look at your code and see if I can make sense out it from my perspective. Don't get me wrong I am sure your code is fine. Just want to see if I can understand it. 

Thanks for replying to you and AutoBert.




Edited by Briandr

Share this post

Link to post
Share on other sites

I took a look at this and what struck me as odd was the function for _RegWriteAllUsers. It looks like it was trying to execute a line right when it was declaring the function? It compiled cleanly, but is that by design?

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=C:\Program Files (x86)\AutoIt3\Icons\dell_icon.ico
#AutoIt3Wrapper_Res_Comment=Install wrapper
#AutoIt3Wrapper_Res_Description=Install wrapper
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <File.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Dim $ChassisType, $Model

$LogDirectory = @WindowsDir & "\Dell\KACE"
$ModuleName = @ScriptName
$ModuleName = StringSplit($ModuleName, ".")
$ModuleName = $ModuleName[1]
$Log = $LogDirectory & "\" & $ModuleName & ".log"
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$StrComputer = "localhost"

If Not FileExists($LogDirectory) Then DirCreate($LogDirectory) ;Creates path if does not exist
If FileExists($Log) Then FileDelete($Log)

_FileWriteLog($Log, $ModuleName & " module called.")




Func _Win32_ComputerSystem()
    ;Get General PC Info
    $objWMIService = ObjGet("winmgmts:\\" & $StrComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    If IsObj($colItems) Then
        For $objItem In $colItems
            ;$DOMAIN = $objItem.Domain
            $Manufacturer = $objItem.Manufacturer
            $Model = $objItem.Model
            _FileWriteLog($Log, "Model: " & $Model)
            ;$MachineName = $objItem.Name
            ;$NumberOfProcessors = $objItem.NumberOfProcessors
            ;$PartOfDomain = $objItem.PartOfDomain
            ;$MEM = Round($objItem.TotalPhysicalMemory / 1024 / 1024, 0)
EndFunc   ;==>_Win32_ComputerSystem

Func _HPConnectionManagerCustom()
If Not StringRegExp($Model, "(?i)(EliteBook|ProBook|6530b)") Then Exit
       RegWriteAllUsers("Software\Hewlett-Packard\HP Connection Manager", "Preferences.Notification.ShowInitialStatus", "REG_SZ", "False")
       ConsoleWrite("1 " & @error & @LF)
       RegWriteAllUsers("Software\Hewlett-Packard\HP Connection Manager", "Preferences.Notification.ShowConnectivity", "REG_SZ", "False")
       ConsoleWrite("2 " & @error & @LF)
       RegWriteAllUsers("Software\Hewlett-Packard\HP Connection Manager", "Preferences.Notification.ShowPower", "REG_SZ", "False")
EndFunc   ;==>_HPConnecnnectionManagerCustom

Func _RegWriteAllUsers($keyname, $valuename = "", $type = "", $value = "")
;Mount default profile for writing as it is not mountes to HKU by default
If FileGetVersion(@WindowsDir & "\system32\ntoskrnl.exe") >= 6 Then
RunWait('reg load "HKEY_USERS\DEFAULT" "' & @UserProfileDir & '\..\Default\NTUSER.DAT"', "", @SW_HIDE)
RunWait('reg load "HKEY_USERS\DEFAULT" "' & @UserProfileDir & '\..\Default User\NTUSER.DAT"', "", @SW_HIDE)
;Write to all offline profiles
For $i = 1 To 999999999
Local $var = RegEnumKey("HKEY_USERS", $i)
If @error <> 0 Then ExitLoop
If StringInStr($var, "_Classes") Then ContinueLoop
If StringLen($var) = 8 Then ContinueLoop ;filter out system SIDs
RegWrite("HKEY_USERS\" & $var & "\" & $keyname, $valuename, $type, $value)
;UnMount default profile
RunWait('reg unload "HKEY_USERS\DEFAULT"', "", @SW_HIDE)
;write to current profile
RegWrite("HKEY_CURRENT_USER\" & $keyname, $valuename, $type, $value)


Share this post

Link to post
Share on other sites

I had a short look into the UDF may be usefull on x86 enviroments without UAC, on all other it must fail.


Edited by AutoBert

Share this post

Link to post
Share on other sites

When I ran the code by itself (not merging in mine) it did write to the registry the way it should and that was on Win 7 x64 SP1+ MS's million updates.

Share this post

Link to post
Share on other sites

Sometimes even though keys are HKCU, they will work globally if put in HKLM, you can give that a shot.

A startup script in the all users startup also could work, just have it check the registry and if a key exists then exit.

Also changes made to the default user hive will auto populate to all new users as long as the software does not overwrite them after the fact. 


Last, I did not post any of my code.  


Here is an example of how I enumerate through all users registry for working on old computer drives when replacing computers.

#Include <SecurityEx.au3>
#Include <Reg.au3>
#Include <Array.au3>
#Include <FileConstants.au3>
#Include <File.au3>

$vDrive = InputBox("Drive Letter Selection", "Enter Driver Letter For Scan (Do Not Include Colon:)", "C")
If @Error Then Exit
$vOutlookVer = InputBox("Enter Outlook Version", "Outlook 2013 = 15" & @CRLF & "Outlook 2010 = 14" & @CRLF & "Outlook 2007 = 12")
If @Error Then Exit

$aUsers = _FileListToArray($vDrive & ":\Users", "*", $FLTA_FOLDERS)
For $i = 1 to $aUsers[0]

    If NOT StringInStr($aUsers[$i], "Administrator") AND NOT StringInStr($aUsers[$i], "Default") AND NOT StringInStr($aUsers[$i], "All Users") AND NOT StringInStr($aUsers[$i], "Public") Then
        _RegLoadHive($vDrive & ":\Users\" & $aUsers[$i] & "\ntuser.dat", "HKU\" & $aUsers[$i])
        For $i2 = 1 to 200
            If $vOutlookVer = 12 Then
                $sSubKey = RegEnumVal("HKU\" & $aUsers[$i] & "\Software\Microsoft\Office\" & $vOutlookVer & ".0\Outlook\Catalog", $i2)
                If @Error Then ExitLoop
                $sSubKey = RegEnumVal("HKU\" & $aUsers[$i] & "\Software\Microsoft\Office\" & $vOutlookVer & ".0\Outlook\Search\Catalog", $i2)
                If @Error Then ExitLoop

            If StringRegExp($sSubKey, ".*\.pst$") Then
                DirCreate(@DesktopDir & "\Outlook Archives\" & $aUsers[$i])
               _FileWriteLog(@DesktopDir & "\Outlook Archives\Outlook Archives.txt", $aUsers[$i] & " - " & $sSubKey)
               $sSubKeyMod = StringRegExpReplace($sSubKey, "^.", $vDrive)
               FileCopy($sSubKeyMod, @DesktopDir & "\Outlook Archives\" & $aUsers[$i] & "\" & $aUsers[$i] & "-" & $i2 & ".pst")

        _RegUnloadHive("HKU\" & $aUsers[$i])


    MsgBox(0, "BoCC Automation", "Copy of Outlook Archives Completed")


I just used a UDF to load/unload the hive (an older version of my code I used cmd to do this instead) and general array/loop code.

Share this post

Link to post
Share on other sites

Thanks Vicious. I know the guys at the forums sometimes don't like giving out code. I am hopeful I can merge what I have to what was in the link you posted. I think I have a good shot at it. May have to wrestle with it a bit.  But I will also play around with the code you just posted. 

Share this post

Link to post
Share on other sites

Don't worry about all the stuff that my code is doing, just how I put users profile in an array and loop through it loading the hives, working on them, and then unloading them.

If its a new computer, try just making the changes to the default user hive.  This is how I push a lot of HKCU only keys on new PC builds. 

Share this post

Link to post
Share on other sites

In this case we are dealing with new computers. I just need to add in my section of code to diferentiate laptops from desktops. I will chew on this code you have for archives. See if I can tweak it to make it do what I need to do. Thanks.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Create New...