Jump to content
Sign in to follow this  
xinx

Problem with RegWrite

Recommended Posts

xinx

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! :-)

Share this post


Link to post
Share on other sites
DW1

On Win7 64 I cannot repro the issue either... I get the expected result. What OS are you working with? Are you using the latest version of AutoIt?

Share this post


Link to post
Share on other sites
xinx

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

Share this post


Link to post
Share on other sites
xinx

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.

Share this post


Link to post
Share on other sites
water

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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
xinx

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

Share this post


Link to post
Share on other sites
xinx

Just in case anyone reads this thread, the simple resolution was to concatenate the usertype of 'System Admins' to 'SystemAdmins'. Worked a treat :oops:

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  

×