Copy Key from registry
Hi All,
We have an issue where users do not get a printer set in Lotus Notes within a citrix desktop session. I have found that if I manuall copy a REG_SZ value from HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\SessionDefaultDevices\UserSID\ to
HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\ this sets the printer within Notes. An example of the value is:
Name - Device
Type - REG_SZ
Value - Adobe PDF (from MURGLAP10101) in session 73,winspool,Ne22:
Is there any way to copy this key and paste it in the required location bearing in mind this will somehow have to resolve the usersid as well?
Thanks
Ally
Answers (4)
You can do this with active setup.
Another trick I found with some software you can put the same key under HKLM and it will the work for all users, this you need to test. Windows 7 when it reads the hives most programs combine the keyset settings that are under both HKLM and HKCU that are for that software.
Comments:
-
for active setup
http://www.itninja.com/blog/view/active-setup-concept
http://www.sepago.de/d/helge/2010/04/22/active-setup-explained
http://www.itninja.com/blog/view/active-setup
search for active setup in the ninja search box and there is even more - SMal.tmcc 11 years ago -
Thanks for the links will have a look over them. Modifying hklm would not be an option unfortunately as the value I need to copy is each users session printer. - AllyRussell 11 years ago
-
Yes you are correct, If the data you are trying to inject is constant, it may work and save you going thru active setup. On a test machine put the key under HKLM and see if it works with no key under the user hive. I have had about 80-90 percent success doing this. Windows and software a lot of times blends both keys sets together for one set of keys to read ignoring if they originated from HKLM or HKCU - SMal.tmcc 11 years ago
-
If this value varies for each user you can always add a reg merge to their login scripts. Even Active setup will not be able to inject variable info that is user unique without some sort of scripting to create the unique keys - SMal.tmcc 11 years ago
Are there multiple keys (SID's) listed in "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\SessionDefaultDevices\" for each user or is there just one?
Comments:
-
Since it HKCU I would assume it would be only that current users sid. I have never seen others users SID's under the users hive, user hives do not know about other user hives - SMal.tmcc 11 years ago
-
Just the one sid, relating to whatever user is logged on. - AllyRussell 11 years ago
If the other scenarios do not work for you, you can use a script like this to manipulate the registry information in the keys you have described. Basically, we look at the original registry path you gave (HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\SessionDefaultDevices\) and enumerate all of its subkeys. From there, we look through each of the subkeys for a value named "Device" that we can copy. If the value is found, the equivalent value is created under the second path you gave (HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\) thus creating the desired results. Let me know if you have any questions or run into any issues.
Option Explicit
On Error Resume Next
Const HKCU = &H80000001
Dim strComputer, objReg, strOrigPath, strNewPath, arrKeys, strKey, strPrinter
strComputer = "."
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
strOrigPath = "Software\Microsoft\Windows NT\CurrentVersion\Windows\SessionDefaultDevices"
strNewPath = "Software\Microsoft\Windows NT\CurrentVersion\Windows"
objReg.EnumKey HKCU, strOrigPath, arrKeys
For Each strKey In arrKeys
objReg.GetStringValue HKCU, strOrigPath & "\" & strKey, "Device", strPrinter
If strPrinter <> vbNull Then
objReg.SetStringValue HKCU, strNewPath, "Device", strPrinter
End If
Next
Set strComputer = Nothing
Set objReg = Nothing
Set strOrigPath = Nothing
Set strNewPath = Nothing
Set arrKeys = Nothing
Set strKey = Nothing
Set strPrinter = Nothing
There is another value under the second path named "UserSelectedDefault", so if that is necessary, you can add a "objReg.SetDWORDValue" line under the existing "objReg.SetStringValue" line for the "Device" value, and set the value to 1 like this:
objReg.SetDWORDValue HKCU, strNewPath, "UserSelectedDefault", 1