Petri IT Knowledgebase Forums
 

Petri.co.il forums Home Forums Start Page Forums Frequently Asked Questions FAQ Member List Members List
Go Back   Petri IT Knowledgebase Forums > Windows Scripting > General Scripting
Petri.co.il is happy to award auglan the title of Most Valuable Member !!!
Register Calendar Calendar Search Petri IT Knowledgebase Forums Search Todays Posts Today's Posts Mark Forums Read

Notices

Edit users' printer settings

Edit users' printer settings

this thread has 8 replies and has been viewed 3611 times

Closed Thread
 
Thread Tools Search this Thread Display Modes
  #1  
Old 15th November 2006, 13:25
sluice sluice is offline
Casual
Casual
 
 Join Date: Nov 2006
  6 month star 12 month star
 Posts: 13
 Reputation: sluice is on a distinguished road (10)
Default Edit users' printer settings

We need to redirect users in our NT4 domain so that they look to a new printer server for their existing network printers. The printer name will remain the same but the server name will change. It would be nice to be able to edit their roaming profiles, if possible. Each user may have several printers on 2 or 3 servers. I see the problem will be to lookup \\server\printer and change it to \\new_server\printer, but I don't know where and what to edit.
  #2  
Old 15th November 2006, 15:37
tonyyeb's Avatar
tonyyeb tonyyeb is offline
Moderator
 
 Join Date: Dec 2004
  6 month star 12 month star
 Location: Hull, UK
 Posts: 2,182
 Reputation: tonyyeb is a jewel in the roughtonyyeb is a jewel in the roughtonyyeb is a jewel in the rough (283)
Default Re: Edit users' printer settings

Hi there

EDIT:

Of course there is an easy way - i wasn't thinking.

* Enumerate all the printers
* Add the new printer by swapping the server name in the UNC
* Delete the old printer

Now i dont know how proficient you are with VB script but using these examples should get you to the point where you want to be:

http://www.microsoft.com/technet/scr...t/default.mspx
__________________
Server 2000 MCP
Development: ASP, ASP.Net, PHP, VB, VB.Net, MySQL, MSSQL - Check out my blog http://tonyyeb.blogspot.com

** Remember to give credit where credit is due and leave reputation points To grant some reputation points to the user that helped you, just click on the little Yin-Yang icon on the right of the user's answer and follow the prompt. where appropriate **

Last edited by tonyyeb; 15th November 2006 at 15:53.. Reason: Being slow in the brain
  #3  
Old 15th November 2006, 16:57
Dumber's Avatar
Dumber Dumber is online now
Moderator
 
 Join Date: Dec 2003
  6 month star 12 month star
 Location: The Netherlands
 Posts: 8,068
 Reputation: Dumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to behold (820)
Default Re: Edit users' printer settings

I once wrote this script, hopefully it helps you out.
I'ms sure others can write it much more better, however this works for me a few years ago.

Code:
'==========================================================================
'
'' NAME: Remove and add printerconnecton
'
' AUTHOR: Marcel 
' DATE  : 6-7-2003
'
' COMMENT: This printer checks whatever the default printer is. Also he will remove and install the new printers

'==========================================================================

Option Explicit
'Variable Declaratie
Dim oPrinter,DefPrinter,oReg,DefLocal,GetSize,DefNetwork,x,Defnew
Set oReg = CreateObject ("wscript.shell")
set oPrinter = CreateObject ("Wscript.network")

Read Default printer
DefPrinter = Oreg.RegRead ("HKCU\Software\microsoft\windows NT\Currentversion\Windows\Device")
If Left (DefPrinter,11) = "\\Servedc01" Then WScript.Quit (0)

If Left (DefPrinter ,2) = "\\" Then
'Check if the default printer start with \\

	if Left (DefPrinter,8) = "\\AEDPCD" Then
		'if the default printer begins eith \\AEDPCD 
		WScript.Echo "Local shared printer used"
		WScript.Echo "Adding ICT printer temporary" 
		On Error Resume Next
		oPrinter.SetDefaultPrinter "\\Serveps06\Servep11"
			If Err <> 0 Then
				On Error Resume next
				oPrinter.SetDefaultPrinter "\\Servedc01\Servep11"
					If Err = 0 Then
						SetDefnetwork
		  				SetNetwork
				 		WScript.Quit (0)
					Else
				 		oPrinter.AddWindowsPrinterConnection "\\Serveps06\Servep11"
				 		oprinter.SetDefaultPrinter "\\Serveps06\Servep11"
					End If 
			End If
	 	WScript.Echo "using temporary ICT printer"
	 	DeleteAll
	 	AddAll
	 	SetDefnetwork
	 	SetNetwork
 	End if
	 
	If Left (DefPrinter,11) = "\\Serveps06" Then
	'If the default printer begins with \\Serveps06 do
		WScript.Echo "old printer are defiend"
		WScript.Echo DefPrinter
	 	DeleteAll
	 	AddAll
		SetDefnetwork
	 	SetNetwork
	End If	
Else
	If Right (DefPrinter,5) = "LPT1:" Then
		'IF LPT1: See the start from the  default printer
	 	WScript.Echo "Local Printer installed."
		DefLocal=DefPrinter
		DefPrinter = ""
		oPrinter.AddWindowsPrinterConnection "\\Serveps06\Servep11"
		oPrinter.SetDefaultPrinter  "\\Serveps06\Servep11"
		WScript.Echo "Default printer temporary set to ICT printer"
	 	DeleteAll
	 	AddAll
	 	Setlocal
	 End If
end If

Sub Setlocal
	'Set Default printer back to Local printer
	If DefLocal <> "" Then
		oReg.RegWrite "HKCU\Software\microsoft\windows NT\Currentversion\Windows\Device" , DefLocal, "REG_SZ"
		WScript.Echo "Default been set on Local Port"
	end If
End Sub

Sub SetDefnetwork
'find what the printer share name is,without the servername
'Also change the servername
	if DefPrinter <> "" Then
		GetSize = InStr(defprinter, ",")-1
		DefNetwork = left (DefPrinter, getsize)
		DefNew = Replace (defnetwork,"\\Serveps06\","\\Servedc01\") 'Change servername over here
	End If
End Sub

Sub SetNetwork
'Set new default networkprinter
WScript.Echo "Set default network printer"
	If DefNetwork <> "" Then
		oPrinter.SetDefaultPrinter Defnew 'printer goed zetten
	End If
End Sub


Sub DeleteAll
 'Delete Al printers 
On Error Resume Next
	WScript.Echo "deleting Printers"
	oPrinter.RemovePrinterConnection "\\Serveps06\Servep01"
	oPrinter.RemovePrinterConnection "\\Serveps06\Servep02"
	oPrinter.RemovePrinterConnection "\\Serveps06\Servep03"
	oPrinter.RemovePrinterConnection "\\Serveps06\Servep04"
	oPrinter.RemovePrinterConnection "\\Serveps06\Servep05"
	oPrinter.RemovePrinterConnection "\\Serveps06\Servep06"
	oPrinter.RemovePrinterConnection "\\Serveps06\Servep07"
	oPrinter.RemovePrinterConnection "\\Serveps06\Servep11"
	oPrinter.RemovePrinterConnection "\\Serveps06\Servep12"
	oPrinter.RemovePrinterConnection "\\Serveps06\Colonnadeduhafp01"
	oPrinter.RemovePrinterConnection "\\Serveps06\aedexp01"
	oPrinter.RemovePrinterConnection "\\Serveps06\Woonenergiep01"
End Sub

Sub AddAll
'Add all Printers
	WScript.Echo "Adding Printers"
 	oPrinter.AddWindowsPrinterConnection "\\Servedc01\Servep01"
 	oPrinter.AddWindowsPrinterConnection "\\Servedc01\Servep02"
 	oPrinter.AddWindowsPrinterConnection "\\Servedc01\Servep03"
 	oPrinter.AddWindowsPrinterConnection "\\Servedc01\Servep04"
 	oPrinter.AddWindowsPrinterConnection "\\Servedc01\Servep05"
 	oPrinter.AddWindowsPrinterConnection "\\Servedc01\Servep06"
 	oPrinter.AddWindowsPrinterConnection "\\Servedc01\Servep07"
 	oPrinter.AddWindowsPrinterConnection "\\Servedc01\Servep11"
 	oPrinter.AddWindowsPrinterConnection "\\Servedc01\Servep12"
 	oPrinter.AddWindowsPrinterConnection "\\Servedc01\Colonnadeduhafp01"
 	oPrinter.AddWindowsPrinterConnection "\\Servedc01\aedexp01"
 	oPrinter.AddWindowsPrinterConnection "\\Servedc01\Woonenergiep01"
end Sub
__________________
Marcel
Netherlands
http://www.phetios.com
http://blog.nessus.nl

MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
No matter how secure, there is always the human factor.

Last edited by Dumber; 15th November 2006 at 17:00..
  #4  
Old 16th November 2006, 12:47
sluice sluice is offline
Casual
Casual
 
 Join Date: Nov 2006
  6 month star 12 month star
 Posts: 13
 Reputation: sluice is on a distinguished road (10)
Default Re: Edit users' printer settings

Dumber,
Thank you for that script. I should be able to modify it to suit many users, but it won't be quick!
Regards, Sluice
  #5  
Old 16th November 2006, 12:57
sluice sluice is offline
Casual
Casual
 
 Join Date: Nov 2006
  6 month star 12 month star
 Posts: 13
 Reputation: sluice is on a distinguished road (10)
Default Re: Edit users' printer settings

Just one other question:
Dumber, your script goes into the user's registry and amends their printer setting. Is there any way of editing the roaming profile on the profile server?
  #6  
Old 16th November 2006, 15:36
tonyyeb's Avatar
tonyyeb tonyyeb is offline
Moderator
 
 Join Date: Dec 2004
  6 month star 12 month star
 Location: Hull, UK
 Posts: 2,182
 Reputation: tonyyeb is a jewel in the roughtonyyeb is a jewel in the roughtonyyeb is a jewel in the rough (283)
Default Re: Edit users' printer settings

Quote:
Originally Posted by sluice View Post
Just one other question:
Dumber, your script goes into the user's registry and amends their printer setting. Is there any way of editing the roaming profile on the profile server?
Not as easy as it sounds i think. Registry settings IIRC are in the NTUSER.DAT (or .MAN) and would need some way of editing that.

I would use the script so that it makes that change when they log on. Then when they log off the settings should be saved back (unless you are using mandatory or readonly profiles).
__________________
Server 2000 MCP
Development: ASP, ASP.Net, PHP, VB, VB.Net, MySQL, MSSQL - Check out my blog http://tonyyeb.blogspot.com

** Remember to give credit where credit is due and leave reputation points To grant some reputation points to the user that helped you, just click on the little Yin-Yang icon on the right of the user's answer and follow the prompt. where appropriate **
  #7  
Old 16th November 2006, 23:04
Dumber's Avatar
Dumber Dumber is online now
Moderator
 
 Join Date: Dec 2003
  6 month star 12 month star
 Location: The Netherlands
 Posts: 8,068
 Reputation: Dumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to behold (820)
Default Re: Edit users' printer settings

Just like what Tony said.
I've used it as a loginscript.
__________________
Marcel
Netherlands
http://www.phetios.com
http://blog.nessus.nl

MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
No matter how secure, there is always the human factor.
  #8  
Old 17th November 2006, 00:40
amitmanor amitmanor is offline
Casual
Casual
 
 Join Date: Nov 2006
  6 month star 12 month star
 Posts: 4
 Reputation: amitmanor is on a distinguished road (22)
Default Re: Edit users' printer settings

Quote:
Originally Posted by Dumber View Post
Sub DeleteAll
'Delete Al printers
On Error Resume Next
WScript.Echo "deleting Printers"
oPrinter.RemovePrinterConnection "\\Serveps06\Servep01"
oPrinter.RemovePrinterConnection "\\Serveps06\Servep02"
oPrinter.RemovePrinterConnection "\\Serveps06\Servep03"
oPrinter.RemovePrinterConnection "\\Serveps06\Servep04"
oPrinter.RemovePrinterConnection "\\Serveps06\Servep05"
oPrinter.RemovePrinterConnection "\\Serveps06\Servep06"
oPrinter.RemovePrinterConnection "\\Serveps06\Servep07"
oPrinter.RemovePrinterConnection "\\Serveps06\Servep11"
oPrinter.RemovePrinterConnection "\\Serveps06\Servep12"
oPrinter.RemovePrinterConnection "\\Serveps06\Colonnadeduhafp01"
oPrinter.RemovePrinterConnection "\\Serveps06\aedexp01"
oPrinter.RemovePrinterConnection "\\Serveps06\Woonenergiep01"
End Sub
[/CODE]
Hey dumber
i just thought i might sugest you with the following code:

Set WshNetwork = CreateObject("WScript.Network")

RemovePrinters

'Remove All connected printer
Function RemovePrinters()
Dim PrinterCollection, i
Set PrinterCollection = WshNetwork.EnumPrinterConnections

For i = 0 To PrinterCollection.Count -1 Step 2

If PrinterCollection(i) <> "" Then
'On Error Resume Next
If InStr(PrinterCollection.Item(i+1),"\\") <>0 Then
WshNetwork.RemovePrinterConnection PrinterCollection.Item(i+1),True
End If
End If

Next
Set PrinterCollection = Nothing
End Function

'Clean up
Set WshNetwork = Nothing
Set PrinterCollection = Nothing

WScript.Quit

regards, amit.
  #9  
Old 17th November 2006, 10:31
Dumber's Avatar
Dumber Dumber is online now
Moderator
 
 Join Date: Dec 2003
  6 month star 12 month star
 Location: The Netherlands
 Posts: 8,068
 Reputation: Dumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to behold (820)
Default Re: Edit users' printer settings

AMit,

Thanks. That can work indeed.
The script i wrote was in 2003, when i needed is very fast. So i've created it quick and dirty
__________________
Marcel
Netherlands
http://www.phetios.com
http://blog.nessus.nl

MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
No matter how secure, there is always the human factor.
Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Allow users to edit all fields in GAL? armstrongtj Exchange 2000 / 2003 5 22nd August 2006 12:56
Moving users settings/files TheDonkey Active Directory 1 26th May 2006 03:43
Moving 'Documents and Settings' for *all users* Jerome GPO 5 24th September 2005 10:45
Change settings under Restricted users account pcking999 Active Directory 2 6th April 2005 23:18
Lock down printer settings tonyyeb Windows Server 2000 / 2003 2 12th January 2005 20:26


All times are GMT +3. The time now is 21:14.

Steel Blue 3.5.4 vBulletin Style ©2006 vBEnhanced
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
 

Valid XHTML 1.0!   Valid CSS!

Copyright 2005 Daniel Petri