Page 1 of 1 1
Topic Options
#156463 - 2006-02-01 11:19 PM Add printer - using registry only
cyri Offline
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
#156464 - 2006-02-02 12:55 AM Re: Add printer - using registry only
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yes, you can add printer just fine.
you need to have the printer driver installed though and need to see more about the correct registry keys you need to set up.
there are 2-3 of them.

done it during last millenia.
forgive me but I don't remember the keys no more
_________________________
!

download KiXnet

Top
#156465 - 2006-02-02 12:59 AM Re: Add printer - using registry only
cyri Offline
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
#156466 - 2006-02-02 02:07 AM Re: Add printer - using registry only
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
done it with even printer servers and works a treat.
_________________________
!

download KiXnet

Top
#156467 - 2006-02-02 03:02 AM Re: Add printer - using registry only
Benny69 Offline
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.
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#156468 - 2006-02-02 03:48 PM Re: Add printer - using registry only
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yep, with connected printers, the keys to have is just not that much.
but, like you said, it's best to look with some sorta reg compare to make sure.
_________________________
!

download KiXnet

Top
#156469 - 2006-02-21 06:23 PM Re: Add printer - using registry only
cyri Offline
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
#156470 - 2006-02-22 06:19 AM Re: Add printer - using registry only
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
And how do you ensure that the drivers are being installed correctly? Can you guarantee that the drivers of the old and new print server are identical?
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1046 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.436 seconds in which 0.067 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org