Click here to Skip to main content
14,838,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am far far from a programmer. However, I am trying to automate paperport 11 to change its default path where scanned documents will go. within HKEY_USERS is a GUID and registry change is within there. This is different for every user, so how would I be able to import a registry key into this directory and compensate for the change with the GUID?


[HKEY_USERS\S-1-5-21-3036698917-4077224916-1865345272-18111\Software\ScanSoft\PaperPort Desktop Group\Desktops\Desktop1]
"Path"="c:\\temp"
"SimpleSearch"=dword:00000001
"Name"=""
"StandardDesktop"=dword:00000000

Where the path says c:\\temp is what I have changed in the registry to the path that I want it to be.
Posted
Updated 14-Dec-10 10:55am
v2

First, that's a SID (Security Identifier), not a GUID.

You're code would have to be updated to enumerate the keys under the HKEY_USERS hive. That enumeration would return the names of each key, allowing you to build a string that represent the path to the registry key you want.

There's a problem with your code though. It won't work in all all situations. Not every users registry hive will show up under HKEY_USERS if they are not logged in on that workstation.

Your code requires administrator rights in order to enumerate all of the keys under HKEY_USERS. You're also probably not checking for SIDs that are actual users. You probably don't want to be putting this path under the Local System account, or anything else non-user related.

Your code will only make the change on user accounts that have already logged in. Any new users on the machine will not get this change. Having said that:

You have to make sure this change ends up in the Default User (HKEY_USERS\.DEFAULT) profile since any new users logging into the machine will inherit their initial registry settings from the Default User profile.

A better solution to this would have been policies or making the change in a login script so that each user can run this script and it would execute as the user, not as an administrator.
   
The value you need is the user SID. This WScript will get the SID for a specified user:
VB
strComputer = "."
strUsername = "username"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objAccount = objWMIService.Get _
    ("Win32_UserAccount.Name='" & strUsername & "',Domain='atl-ws-01'")
Wscript.Echo objAccount.SID


To get the username:
VB
Set wshNetwork = CreateObject("WScript.Network")  
strUser = wshNetwork.Username  


good luck!
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900