Jump to content

Problem with RegWrite


Recommended Posts

Hi all.

I'm having a problem with writing something to the registry

RegWrite("HKEY_LOCAL_MACHINE\Software\xinx\management\Users\" & $SelectedUserType & "\" & $sUser, $FolderType, "REG_SZ", $Folder)

If the $SelectedUserType is 'System Administrators' then the result is a little unexpected.

Instead of showing as: HKEY_LOCAL_MACHINE\Software\xinx\management\Users\System Administrators\Admin like I should see, it shows as HKEY_LOCAL_MACHINE\Software\xinx\management\Users\System\Administrators\Admin (which means it has basically split the System Administrators in two and made the variable into two reg keys).

It works if the $SelectedUserType is 'SystemAdmins' for example, but just doesn't seem to like it if the variable has a space...

I hope this makes sense, and any help is much appreciated! :-)

Link to comment
Share on other sites

Ack sorry, tiredness!

Firstly, thank you for your quick responses :oops:

Secondly, I forgot to say that this runs from another PC and is meant to write to the registry on the server.

It's a bit difficult to explain how this all works, but if the program is run and it detects it is not running on the server (i.e., on a client PC) it then runs this command:

$RemoteProfile = "C:ManagementRemoteCreateProfile.exe"
$Sharename = Test
$PsExecCommand = 'exePsExec ' & $server & ' -s' & ' "' & $RemoteProfile & '" ' & $SelectedUserType & ' ""' & $sUser & ' "' & $ProfileFolder & '" ' & $Sharename & ' Profile'
$iValue = Run($PsExecCommand, "", @SW_HIDE)

The code in RemoteCreateProfile is:

$SelectedUserType = $CmdLine[1]
$sUser = $CmdLine[2]
$Folder = $CmdLine[3]
$ShareName = $CmdLine[4]
$FolderType = $CmdLine[5]
$iValue = DirCreate($Folder)
If $iValue = 1 Then
If @OSArch = "X86" Then
  RunWait('RP32.exe "' & $SelectedUserType & '" "' & $sUser & '" "' & $FolderType & '" "' & $Folder & '"')
Else
  RunWait('RP64.exe "' & $SelectedUserType & '" "' & $sUser & '" "' & $FolderType & '" "' & $Folder & '"')
EndIf
EndIf

And in RP32 (or RP64) the code is:

$SelectedUserType = $CmdLine[1]
$sUser = $CmdLine[2]
$FolderType = $CmdLine[3]
$Folder = $CmdLine[4]
RegWrite("HKLM64SoftwarexinxmanagementUsers" & $SelectedUserType & "" & $sUser, $FolderType, "REG_SZ", $Folder)

Additional: I tried using the single quotes as you asked, but strangely it now shows as 'System' (with the single quotes) in the registry! :-/ Weird.

Edited by xinx
Link to comment
Share on other sites

Hi danwilli,

Just checked and made sure that I am using the latest version (just downloaded alatest AutoIT and recompiled the scripts), but still no joy.

The O/s that it is running from is 32-bit Windows XP, and it is writing to 64-bit Windows Server 2008. It works if the $SelectedUserType is only one word which is the part I do not understand.

Link to comment
Share on other sites

When writing to the Registry on a 64 bit system you need to replace HKLM with HKLM64.

According to the help file: "When running on 64-bit Windows if you want to write a key or value specific to the 64-bit environment you have to suffix the HK... with 64 i.e. HKLM64."

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Hi water,

Thanks for you input. However, when run locally on the server using HKLM it does not cause a problem, i.e., the script on the server doesn't have HKLM64 in it either. Only when running the program from a remote PC does this problem occur :oops:

Edit: I thought it was worth a shot anyway, changed HKLM to HKLM64 but still has the same results.

Edited by xinx
Link to comment
Share on other sites

  • 2 weeks later...

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