#156463 - 2006-02-01 11:19 PM
Add printer - using registry only
|
cyri
Getting the hang of it
Registered: 2005-06-27
Posts: 95
|
Is there a way to add a printer with only registry entries? So, if there was no addprinterconnection() and all I could do was import a .reg with all the printer settings, would that attach the printer?
Reason: We use roaming profiles. We have a custom utility that builds the new profile, set permissions, etc. I want to be able to preserve the users printer connections in the newly created profile.
A run once at user login is not an option. The printers already need to be there before the user logs in for the first time. Merging the printers would have to be done purely with the registry.
Is that possible?
|
|
Top
|
|
|
|
#156465 - 2006-02-02 12:59 AM
Re: Add printer - using registry only
|
cyri
Getting the hang of it
Registered: 2005-06-27
Posts: 95
|
Thanks Jooel. Yeah drivers are not really a concern because this will be a roaming Terminal Services profile and the Terminal Servers already have the drivers installed. Hopefully I can use a regshot while adding a printer to catch the registry changes. Never tried it before.
|
|
Top
|
|
|
|
#156467 - 2006-02-02 03:02 AM
Re: Add printer - using registry only
|
Benny69
Moderator
   
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
Lonk, Doc, Howard,... correct me if i don't have it quite right, but i think that part of what you are looking for is: "HKEY_USERS\" + @SID + "\Printers\Connections" I would say to make sure, look at some allready installed printers and then replicate the keys and values to install. but i have not tested this thought. I know that when i want to remove printers from a user all i have to do is delete "HKEY_USERS\" + @SID + "\Printers\Connections" this key and they all disapear, then i recreate the key and then i use "WScript.Network" to create the printers that i want them to have.
I am sure that there are better ways to do this but it seams to work for me.
|
|
Top
|
|
|
|
#156469 - 2006-02-21 06:23 PM
Re: Add printer - using registry only
|
cyri
Getting the hang of it
Registered: 2005-06-27
Posts: 95
|
Just wanted to let you guys know that this is working perfectly. Here is a sample script. We actually had to write in VBScript. Sorry, not my decision so no flaming. There isn't any error handling yet, but it works great so far.
Code:
Set WshShell = WScript.CreateObject("WScript.Shell") Set fso = CreateObject("Scripting.FileSystemObject")
'This value is set for testing purposes only 'strValueName=TForm.txtUserID.value strValueName="test01"
strKey="HKU\" & strValueName strOldProf="\\test01\profiles\" & strValueName & ".pds\ntuser.dat" strNewProf="\\test01\profiles\" & strValueName & ".new\ntuser.dat" TmpDir = WshShell.Environment("Process")("Temp") RegFile1=TmpDir & "\" & strValueName & ".reg" RegFile2=TmpDir & "\" & strValueName & "2.reg" RegPath1="""\Printers""" RegPath2="""\Software\Microsoft\Windows NT\CurrentVersion\Windows"""
Step1 = WshShell.Run ("reg.exe load " & strKey & " " & strOldProf, 0, TRUE) Wscript.echo Err.Number Step2 = WshShell.Run ("reg.exe export " & strKey & RegPath1 & " " & RegFile1, 0, TRUE) Step3 = WshShell.Run ("reg.exe export " & strKey & RegPath2 & " " & RegFile2, 0, TRUE) Step4 = WshShell.Run ("reg.exe unload " & strKey, 0, TRUE) Step5 = WshShell.Run ("reg.exe load " & strKey & " " & strNewProf, 0, TRUE) Step6 = WshShell.Run ("reg.exe import " & RegFile1, 0, TRUE) Step7 = WshShell.Run ("reg.exe import " & RegFile2, 0, TRUE) Step8 = WshShell.Run ("reg.exe unload " & strKey, 0, TRUE) fso.deletefile RegFile1 fso.deletefile RegFile2 Wscript.Echo "Process completed successfully."
Set WshShell = Nothing Set fso = Nothing
This will migrate printer connections and set the default printer to what they had before. Working great for our Terminal Servers where the drivers are already installed.
Thank you.
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1336 anonymous users online.
|
|
|