chicabow
asked on
Login script for printers
Can I add a script to log, perhaps a policy or something, that maps all the users who log in to the printers in the office. Instead of manually going to each computer and mapping the computers, it would be nice to have a policy that does this automatically. Can this be done, if so where in the policy is this controlled.
Thanks.
Thanks.
ASKER
yes I want the user to just log in the morning and all the available printers are listed for them, printer name change and are avialable at times and sometimes not...instead of editing every user, I want this controlled via server somehow.
servername is cheffy and printer is hplaser.
so whats the syntax?
servername is cheffy and printer is hplaser.
so whats the syntax?
net use LPT1: \\servername\printername /yes
ASKER
will test this soon,, now will I be able to "wipe" out all the printer references the current users have, then reassign using this script mentioned above?
The reason for this is because I want to rename the printers currently in the network but don't want to cause any issues or hickups.
The reason for this is because I want to rename the printers currently in the network but don't want to cause any issues or hickups.
You should be okay with this... TEST IT FIRST though.. :)
ASKER
Its not working for me....I tried many different variations, with quote, no quotes....still nothing is working....is there a way to log what happens since we can't actually see the script run?
If you are using it in a batch file, test the batch file by itself first... Add the line 'pause' and it will keep the window open..
ASKER
I tried that and I got this error
System error 85 has occured
The local device name is already in use.
But it's not in use....so i'm at a loss here...
System error 85 has occured
The local device name is already in use.
But it's not in use....so i'm at a loss here...
try LPT2
Let me know
Let me know
ASKER
Still no go.... :(
Here is a MS article on mapping printers with DOS commands..
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q314499
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q314499
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
James is right with his suggestion, I would definitely avoid using dos batch commands and mapping LPT ports.
If you use his commands in a VB script you can assign this script to a group policy for an OU. Therefore say you had an OU for each department at your company you would have a different GP on each OU assigning different printers to the users. This means that if a user moved departments it would be a simple matter of dragging them into the new OU and they would get a different set of printers next time they logged on.
If you use his commands in a VB script you can assign this script to a group policy for an OU. Therefore say you had an OU for each department at your company you would have a different GP on each OU assigning different printers to the users. This means that if a user moved departments it would be a simple matter of dragging them into the new OU and they would get a different set of printers next time they logged on.
ASKER
Wow that works like a charm JamesDS, well I just created the file and double clicked and it worked....I have not assigned it to the GPOs yet. So need the exact steps of how to attach a vbs to a Group Policy, never used vbs before....
Would also like to enhance this script to remove all instances of printer currently listed then re-add the listed ones. Would like all clients to have a clean list of valid printers.
Please advise.
Would also like to enhance this script to remove all instances of printer currently listed then re-add the listed ones. Would like all clients to have a clean list of valid printers.
Please advise.
Yea.. those scripts are wonderful.. and I will also be copying it for future reference... :)
Here is a link to logon scripts that may help you with your GPO's
http://www.tycho7.com/Software/Win2k/logon_scripts.htm
Here is a link to logon scripts that may help you with your GPO's
http://www.tycho7.com/Software/Win2k/logon_scripts.htm
ASKER
I don't see anything about associating with VBS files, I already have each user with a specific bat file, but now I need to add vbs files as well how can this be done using the GPO?
ASKER
And the question about removing the printers..
The same way you do your batch files... Scripts are placed in winnt\sysvol\domain\script s. And you use the logon script policy to point your GPO to that script...
ASKER
ok....looking for direction on using (where and how) the logon script policy.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ThankQ
FE
FE
Setting a policy for printer mapping for an OU isn't always what you want to do though. Where I work, in a school, the users have roaming profiles and will log onto many different machines. They will always want to have the nearest printers available to them and other printers throughout the organisation invisible.
The obvious answer would be to assign the policy to an OU containing computers, but, if I put them there (in the Computer startup/shutdown policy) the scripts don't appear to run.
(Anyone any idea why?)
So, I copy the script to the local hard drive and stick a shortcut to it in the startup folder. To ensure that as users move around they don't accumulate printers all over the site the script does the following:
Enumerates all connected printers.
Deletes all connected printers.
Connects only those printers which are nearby.
Works for me, but I'd much rather be able to assign the script to OUs of workstations.
The obvious answer would be to assign the policy to an OU containing computers, but, if I put them there (in the Computer startup/shutdown policy) the scripts don't appear to run.
(Anyone any idea why?)
So, I copy the script to the local hard drive and stick a shortcut to it in the startup folder. To ensure that as users move around they don't accumulate printers all over the site the script does the following:
Enumerates all connected printers.
Deletes all connected printers.
Connects only those printers which are nearby.
Works for me, but I'd much rather be able to assign the script to OUs of workstations.
To give my two cents worth.... I use Kix32 in your environment for login script processing.
KIX is a free utility that can be used for many type of scenarios... printers included. Obviously I can't detail them all but here an example of a KIX script I use to automatically add and remove printers based on the user NT group.
This command addes printers if the use belongs to the DEPT_IS nt group
If ingroup("DEPT_IS")
$ReturnCode = KeyExist("HKEY_CURRENT_USE R\Printers \Connectio ns\,,aumel svr011,AUM ELISD1DL")
If $ReturnCode = 0
? "Printer doesn't exist....adding"
If addPrinterConnection ("\\aumelsvr011\AUMELISD1D L") = 0
? "Added printer ISD Lexmark T622....AUMELISD1DL"
Endif
Endif
Endif
This command deletes printers if the reg key for the specific printer is found.
$ReturnCode = KeyExist("HKEY_CURRENT_USE R\Printers \Connectio ns\,,aumel svr011,AUM ELBOG1DP")
If $ReturnCode
? "Printer doesn't exist....adding"
If delPrinterConnection ("\\aumelsvr011\AUMELBOG1D P") = 0
? "Removed printer Business Operations Hewlett Packard 4050....AUMELBOG1DP"
Endif
Endif
I hope this is helpful for some. KIX can be found at www.kixtart.org
Regards
HoPPeR
KIX is a free utility that can be used for many type of scenarios... printers included. Obviously I can't detail them all but here an example of a KIX script I use to automatically add and remove printers based on the user NT group.
This command addes printers if the use belongs to the DEPT_IS nt group
If ingroup("DEPT_IS")
$ReturnCode = KeyExist("HKEY_CURRENT_USE
If $ReturnCode = 0
? "Printer doesn't exist....adding"
If addPrinterConnection ("\\aumelsvr011\AUMELISD1D
? "Added printer ISD Lexmark T622....AUMELISD1DL"
Endif
Endif
Endif
This command deletes printers if the reg key for the specific printer is found.
$ReturnCode = KeyExist("HKEY_CURRENT_USE
If $ReturnCode
? "Printer doesn't exist....adding"
If delPrinterConnection ("\\aumelsvr011\AUMELBOG1D
? "Removed printer Business Operations Hewlett Packard 4050....AUMELBOG1DP"
Endif
Endif
I hope this is helpful for some. KIX can be found at www.kixtart.org
Regards
HoPPeR
Additionally this code sets an existing printer as the default:
Option Explicit
Dim objPrinter
Set objPrinter = CreateObject("WScript.Netw ork")
objPrinter.SetDefaultPrint er "\\server\printer"
' End of Script
Useful to set the default printer for different groups...
Option Explicit
Dim objPrinter
Set objPrinter = CreateObject("WScript.Netw
objPrinter.SetDefaultPrint
' End of Script
Useful to set the default printer for different groups...
I also work in a school. The way I handled the login script problem was to name the computers in an organized fashion that would allow my login script to assign printers based on the name of the computer that the user logs on to. Therefore, if a student logs into computer LAB10, his default printer will be "Printer4". I created a separate script for the teachers, because I don't want students accessing the faulty printers.
-------------------------- ---------- ---------- ---------- ---------- -------
Dim objNetwork
Dim objPrinters
Dim Printer1, Printer2, Printer3, Printer4
on error resume next
Set objNetwork = CreateObject("WScript.Netw ork")
Set objPrinters = objNetwork.EnumPrinterConn ections
objNetwork.AddWindowsPrint erConnecti on Printer1
objNetwork.AddWindowsPrint erConnecti on Printer2
objNetwork.AddWindowsPrint erConnecti on Printer3
objNetwork.AddWindowsPrint erConnecti on Printer4
Select Case left(objNetwork.ComputerNa me,3)
Case "100"
objNetwork.SetDefaultPrint er Printer1
Case "200"
objNetwork.SetDefaultPrint er Printer2
Case "300"
objNetwork.SetDefaultPrint er Printer3
Case "LAB"
objNetwork.SetDefaultPrint er Printer4
Case Else
End Select
-------------------------- ---------- ---------- ---------- ---------- -
You can also add code to check for a local printer and make that the default in lieu of the closest workgroup printer. This code is much more complicated and I had to account for a terminal server login as well. I hope this helps.
-------------------------- ---------- ---------- ---------- ---------- --
Set objPrinters = WshNetwork.EnumPrinterConn ections
for i=0 to objPrinters.Count-1 Step 2
if Left(objPrinters(i),4)="LP T1" OR Left(objPrinters(i),4)="US B1" Then
if left(objPrinters(i + 1),3)="Acr" then
'don't set acrobat printers as default
else
WshNetwork.SetDefaultPrint er objPrinters(i + 1)
defaultPrinter = objPrinters(i+1)
defaultPrinterAssigned = true
localPrinter=true
end if
elseif Left(objPrinters(i),2)="TS " AND DefaultPrinterAssigned = false then
PrinterDesc = split(objPrinters(i+1)," ")
count = 0
for each token in PrinterDesc
if token="session" then
sessionnumber = PrinterDesc(count + 1)
end if
count = count + 1
next
if TermSessionID = sessionnumber then
WshNetwork.SetDefaultPrint er objPrinters(i + 1)
defaultPrinter = objPrinters(i+1)
defaultPrinterAssigned = true
TerminalSessionPrinter = true
else
defaultPrinterAssigned = false
end if
End If
Next
--------------------------
Dim objNetwork
Dim objPrinters
Dim Printer1, Printer2, Printer3, Printer4
on error resume next
Set objNetwork = CreateObject("WScript.Netw
Set objPrinters = objNetwork.EnumPrinterConn
objNetwork.AddWindowsPrint
objNetwork.AddWindowsPrint
objNetwork.AddWindowsPrint
objNetwork.AddWindowsPrint
Select Case left(objNetwork.ComputerNa
Case "100"
objNetwork.SetDefaultPrint
Case "200"
objNetwork.SetDefaultPrint
Case "300"
objNetwork.SetDefaultPrint
Case "LAB"
objNetwork.SetDefaultPrint
Case Else
End Select
--------------------------
You can also add code to check for a local printer and make that the default in lieu of the closest workgroup printer. This code is much more complicated and I had to account for a terminal server login as well. I hope this helps.
--------------------------
Set objPrinters = WshNetwork.EnumPrinterConn
for i=0 to objPrinters.Count-1 Step 2
if Left(objPrinters(i),4)="LP
if left(objPrinters(i + 1),3)="Acr" then
'don't set acrobat printers as default
else
WshNetwork.SetDefaultPrint
defaultPrinter = objPrinters(i+1)
defaultPrinterAssigned = true
localPrinter=true
end if
elseif Left(objPrinters(i),2)="TS
PrinterDesc = split(objPrinters(i+1)," ")
count = 0
for each token in PrinterDesc
if token="session" then
sessionnumber = PrinterDesc(count + 1)
end if
count = count + 1
next
if TermSessionID = sessionnumber then
WshNetwork.SetDefaultPrint
defaultPrinter = objPrinters(i+1)
defaultPrinterAssigned = true
TerminalSessionPrinter = true
else
defaultPrinterAssigned = false
end if
End If
Next
This works for me in MANY environments.
rundll32 printui.dll,PrintUIEntry /in /n \\%servername%\%printernam e%
Run this in the run line to get all variables.
rundll32 printui.dll,PrintUIEntry /?
Can you dig?
-chumpmasterg
rundll32 printui.dll,PrintUIEntry /in /n \\%servername%\%printernam
Run this in the run line to get all variables.
rundll32 printui.dll,PrintUIEntry /?
Can you dig?
-chumpmasterg
How about connecting to a printer server i.e. jetdirect via an IP port or FQDN? Any Ideas?
I've got a 300 User network that we are configuring from the ground up and during the first few sites that we made live we noticed that we are going to have to script the printer installs this is going to be far too much work for us to add them to every machine and then readd them when a second user logged into the machine.
I have the same question as Brianpmoris, what about TCP/IP Printer Ports on the clients? Our Client wants 2 mappings for each printer. One for using the windows 2003 print server in the AD (\\server\prt-01) and another map to a local TCP printer port (IP_10.0.0.22).
The reason is if they lost access to the domain / print server they could still print off of the local static mapped ones. First off if anyone has any suggestions on a better way to do this I'm all ears...
Second off I need a script to be able to make this happen. I've read about 10 different ways to map a printer via a script or command line. I really would like to know what the best and easiest way to make this happen is. All of my servers are Server 2003 and all of the workstations are Windows XP Pro.
I have the same question as Brianpmoris, what about TCP/IP Printer Ports on the clients? Our Client wants 2 mappings for each printer. One for using the windows 2003 print server in the AD (\\server\prt-01) and another map to a local TCP printer port (IP_10.0.0.22).
The reason is if they lost access to the domain / print server they could still print off of the local static mapped ones. First off if anyone has any suggestions on a better way to do this I'm all ears...
Second off I need a script to be able to make this happen. I've read about 10 different ways to map a printer via a script or command line. I really would like to know what the best and easiest way to make this happen is. All of my servers are Server 2003 and all of the workstations are Windows XP Pro.
dacomb... you need to ask your question in a new thread if you really want to attract attention to your question... You might even want to place it in the scripting section too, along with in the W2K3 section..
FE
FE
Check out this site: http://www.robvanderwoude.com/index.html - search for command line printer control
I wrote the following batch file based on info found at this site and others to do exactly what you want to do.
There are commands to map to a particular port -either local or by IP - see above site
@ECHO OFF
rem VER | FIND "Windows 2000" >NUL
rem IF ERRORLEVEL 1 GOTO Not2000
SETLOCAL
SET Printer=%1
:: Check printer specified
IF NOT DEFINED Printer GOTO NoPrinter
IF NOT "%Printer:~0,2%"=="\\" GOTO MissingBS
FOR /F "tokens=1* delims=\" %%A IN ('ECHO.%Printer%') DO (
SET PrintServer=%%A
Set PrintShare=%%B
)
rem echo "Line 12"
IF NOT DEFINED PrintShare GOTO NotDefinedShare
PING %PrintServer% -n 1 -w 1000 2>&1 | FIND "TTL=" >NUL
IF ERRORLEVEL 1 GOTO Syntax
NET VIEW \\%PrintServer% 2>&1 | FIND /I "%PrintShare%" >NUL
IF ERRORLEVEL 1 GOTO Syntax
rem echo "Line 30"
rem echo "Line 40"
:: Install the printer on the specified computer
echo
ECHO About to INstall the Printer: %Printer%
echo
rem Most of this was taken from http://www.robvanderwoude.com/index.html - Command Line Printer Control
rem This line give the printers property
RUNDLL32 PRINTUI.DLL,PrintUIEntry /p /n\\machine\printer
rem
rem If ths property of the printer is available then it is installed already so don't re-add
rem This line deletes printers - gd
rem RUNDLL32.EXE PRINTUI.DLL, PrintUIEntry /gd /n%Printer% %RemotePC%
rem
rem This line ADDs printers - ga
IF NOT ERRORLEVEL 1 RUNDLL32.EXE PRINTUI.DLL, PrintUIEntry /ga /n%Printer% %RemotePC%
net stop spooler
net start spooler
IF NOT ERRORLEVEL 1 ECHO Printer: %printer% installed
ENDLOCAL
GOTO:EOF
:NOPrinter
echo
echo Error - Printer not defined: %Printer%
echo
goto Syntax
:MissingBS
echo
echo Error - Missing BackSlashes : %Printer%
echo
goto Syntax
:NotDefinedShare
echo
echo Error - NotDefinedShare : %Printer%
echo
goto Syntax
:Not2000
echo
echo Error - Not 2000 or XP
echo VER | FIND "Windows 2000" >NUL
echo
goto Syntax
:Syntax
ECHO.
ECHO AddPrint.bat, Version 1.00 for Windows 2000
ECHO Install a network printer on any PC on the network
ECHO.
ECHO Usage: ADDPRINT \\print_server\printer_sha re
ECHO.
ECHO Where: "print_server" is the print server name or IP address
ECHO "printer_share" is the share name for the printer
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
IF "%OS%"=="Windows_NT" ENDLOCAL
I wrote the following batch file based on info found at this site and others to do exactly what you want to do.
There are commands to map to a particular port -either local or by IP - see above site
@ECHO OFF
rem VER | FIND "Windows 2000" >NUL
rem IF ERRORLEVEL 1 GOTO Not2000
SETLOCAL
SET Printer=%1
:: Check printer specified
IF NOT DEFINED Printer GOTO NoPrinter
IF NOT "%Printer:~0,2%"=="\\" GOTO MissingBS
FOR /F "tokens=1* delims=\" %%A IN ('ECHO.%Printer%') DO (
SET PrintServer=%%A
Set PrintShare=%%B
)
rem echo "Line 12"
IF NOT DEFINED PrintShare GOTO NotDefinedShare
PING %PrintServer% -n 1 -w 1000 2>&1 | FIND "TTL=" >NUL
IF ERRORLEVEL 1 GOTO Syntax
NET VIEW \\%PrintServer% 2>&1 | FIND /I "%PrintShare%" >NUL
IF ERRORLEVEL 1 GOTO Syntax
rem echo "Line 30"
rem echo "Line 40"
:: Install the printer on the specified computer
echo
ECHO About to INstall the Printer: %Printer%
echo
rem Most of this was taken from http://www.robvanderwoude.com/index.html - Command Line Printer Control
rem This line give the printers property
RUNDLL32 PRINTUI.DLL,PrintUIEntry /p /n\\machine\printer
rem
rem If ths property of the printer is available then it is installed already so don't re-add
rem This line deletes printers - gd
rem RUNDLL32.EXE PRINTUI.DLL, PrintUIEntry /gd /n%Printer% %RemotePC%
rem
rem This line ADDs printers - ga
IF NOT ERRORLEVEL 1 RUNDLL32.EXE PRINTUI.DLL, PrintUIEntry /ga /n%Printer% %RemotePC%
net stop spooler
net start spooler
IF NOT ERRORLEVEL 1 ECHO Printer: %printer% installed
ENDLOCAL
GOTO:EOF
:NOPrinter
echo
echo Error - Printer not defined: %Printer%
echo
goto Syntax
:MissingBS
echo
echo Error - Missing BackSlashes : %Printer%
echo
goto Syntax
:NotDefinedShare
echo
echo Error - NotDefinedShare : %Printer%
echo
goto Syntax
:Not2000
echo
echo Error - Not 2000 or XP
echo VER | FIND "Windows 2000" >NUL
echo
goto Syntax
:Syntax
ECHO.
ECHO AddPrint.bat, Version 1.00 for Windows 2000
ECHO Install a network printer on any PC on the network
ECHO.
ECHO Usage: ADDPRINT \\print_server\printer_sha
ECHO.
ECHO Where: "print_server" is the print server name or IP address
ECHO "printer_share" is the share name for the printer
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
IF "%OS%"=="Windows_NT" ENDLOCAL
I use VBscripting for mapping printers.
I have the same problem as you have, the users needs a list of printers to select from.
VBScript lacks forms, this can be fixed by using wshDialog (GNU general public license, version 2).
First the list is shown for the selection of a default printer and the aging for selection for additional printers.
You need to change the domain name for the SQL statement (The domain is “domain.local” right know). All printer need to be listed in the AD.
The script follows:
Option Explicit
Const vbModal = 1
Const ADS_SCOPE_SUBTREE = 2
Dim oDlg, oReplicatorForm, oPrinterForm, sBtn, objConnection, objCommand, objRecordSet, x, i, oNet, oShell, oPrinters
Set objConnection = CreateObject("ADODB.Connec tion")
Set objCommand = CreateObject("ADODB.Comman d")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnectio n = objConnection
objCommand.CommandText = "SELECT printerName,serverName,loc ation,UncN ame FROM " _
& " 'LDAP://DC=domain,DC=local ' WHERE objectClass='printQueue' ORDER BY printerName"
objCommand.Properties("Pag e Size") = 1000
objCommand.Properties("Tim eout") = 30
objCommand.Properties("Sea rchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cac he Results") = True
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
x=1
i=0
Set oNet = CreateObject("WScript.Netw ork")
Set oShell = WScript.CreateObject("WScr ipt.Shell" )
Set oDlg = Wscript.CreateObject("WshD ialog.Kit" )
Set oReplicatorForm = BuildReplicatorForm(objRec ordSet)
objRecordSet.MoveFirst
Set oPrinterForm = BuildPrinterForm(objRecord Set)
objRecordSet.MoveFirst
oReplicatorForm.Show vbModal
Select Case Ucase(oDlg.Clicked)
Case "1"
sBtn = oReplicatorForm.GetOptionB utton("FRM 1")
If oReplicatorForm.Ctl("Remov e").Value Then
Set oPrinters = oNet.EnumPrinterConnection s
For i = 1 to oPrinters.Count - 1 Step 2
If Left(oPrinters.Item(i),2)= "\\" Then
oNet.RemovePrinterConnecti on oPrinters.Item(i)
End If
Next
End If
oNet.AddWindowsPrinterConn ection sBtn
oNet.SetDefaultPrinter sBtn
oPrinterForm.Show vbModal
Select Case Ucase(oDlg.Clicked)
Case "3"
Do while x=<objRecordSet.RecordCoun t
If oPrinterForm.Ctl("Box"&x). Value Then
oNet.AddWindowsPrinterConn ection objRecordSet.Fields("UncNa me").Value
objRecordSet.MoveNext
End If
x=x+1
Loop
MsgBox "Printer installationen er ferdigt"
Case Else
MsgBox "Du har kun installeret en default printer"
End Select
Case Else
MsgBox "Du har annulleret instalationen du har ikke adgang til printerene"
End Select
oReplicatorForm.Clear
oPrinterForm.Clear
Wscript.DisconnectObject oDlg
Set oDlg = Nothing
Function BuildReplicatorForm(objRec ordSet1)
Dim oFrm1, BtnPlaceHigh, BtnPlaceLeft, Rows, oCtl, x
Set oFrm1 = oDlg.NewForm
BtnPlaceHigh=300
BtnPlaceLeft=150
Rows=(objRecordSet1.Record Count-(obj RecordSet1 .RecordCou nt mod 15))/15+1
x=0
oFrm1.NewButton "1", 450, 7600, 750, 375, "&Next"
oFrm1.NewButton "Cancel", 1400, 7600, 750, 375, "&Cancel"
oFrm1.Ctl("Cancel").Cancel = True
Set oCtl = oFrm1.NewCheckBox("Remove" , 450, 7100, 1800, 375, "Remove old printers",1, "FRM1")
oCtl.ToolTipText = "Fjern gamle printere"
oFrm1.NewImage "IMG1", 250, 200 , 0, 0, "IconQuestion"
oFrm1.NewLabel "LBL1", 1150, 300, 3000, 375, "Printer valg"
oFrm1.NewFrame "FRM1", 400, 700, Rows*4500, 6300, " Vælg Default Printer "
Set oCtl = oFrm1.NewLabel("LBL2", (Rows*4500)-1450, 7500, 1800, 200, "By Sune Stevnsborg")
oCtl.ForeColor = RGB(66, 66, 66)
Set oCtl = oFrm1.NewLabel("LBL3", (Rows*4500)-1450, 7710, 1800, 200, "For Leif Hansen Gruppen")
oCtl.ForeColor = RGB(66,66, 66)
Do Until objRecordSet1.EOF
Set oCtl = oFrm1.NewOptionButton(objR ecordSet1. Fields("Un cName").Va lue, BtnPlaceLeft, BtnPlaceHigh, 4300, 375, objRecordSet1.Fields("prin terName"). Value,Fals e, "FRM1")
oCtl.ToolTipText = "Vælg Default Printer"
objRecordSet1.MoveNext
BtnPlaceHigh=BtnPlaceHigh+ 400
x=x+1
If x=15 Then
BtnPlaceLeft=BtnPlaceLeft+ 4350
BtnPlaceHigh=300
X=0
End If
Loop
oFrm1.Caption = "Printer Installation"
oFrm1.TaskBar = False
oFrm1.AutoSize
Set BuildReplicatorForm = oFrm1
End Function
Function BuildPrinterForm(objRecord Set2)
Dim oFrm2, BtnNr, BtnPlaceHigh, BtnPlaceLeft, Rows, oCtl, x
Set oFrm2 = oDlg.NewForm("2")
BtnNr=1
BtnPlaceHigh=300
BtnPlaceLeft=150
Rows=(objRecordSet2.Record Count-(obj RecordSet2 .RecordCou nt mod 15))/15+1
x=0
oFrm2.NewButton "3", 450, 7100, 750, 375, "&Done"
oFrm2.NewButton "Cancel", 1400, 7100, 750, 375, "&Cancel"
oFrm2.Ctl("Cancel").Cancel = True
oFrm2.NewImage "IMG1", 250, 200 , 0, 0, "IconQuestion"
oFrm2.NewLabel "LBL1", 1150, 300, 3000, 375, "Printer valg"
oFrm2.NewFrame "FRM2", 400, 700, Rows*4500, 6300, " Vælg yderlgere printere "
Set oCtl = oFrm2.NewLabel("LBL2", (Rows*4500)-1450, 7100, 1800, 200, "By Sune Stevnsborg")
oCtl.ForeColor = RGB(66, 66, 66)
Set oCtl = oFrm2.NewLabel("LBL3", (Rows*4500)-1450, 7310, 1800, 200, "For Leif Hansen Gruppen")
oCtl.ForeColor = RGB(66,66, 66)
Do Until objRecordSet2.EOF
Set oCtl = oFrm2.NewCheckBox("Box"&Bt nNr, BtnPlaceLeft, BtnPlaceHigh, 4300, 375, objRecordSet2.Fields("prin terName"). Value,, "FRM2")
oCtl.ToolTipText = "Vælg yderlgere printere"
objRecordSet2.MoveNext
BtnNr=BtnNr+1
BtnPlaceHigh=BtnPlaceHigh+ 400
x=x+1
If x=15 Then
BtnPlaceLeft=BtnPlaceLeft+ 4350
BtnPlaceHigh=300
X=0
End If
Loop
oFrm2.Caption = "Printer Installation"
oFrm2.TaskBar = False
oFrm2.AutoSize
Set BuildPrinterForm = oFrm2
End Function
I have the same problem as you have, the users needs a list of printers to select from.
VBScript lacks forms, this can be fixed by using wshDialog (GNU general public license, version 2).
First the list is shown for the selection of a default printer and the aging for selection for additional printers.
You need to change the domain name for the SQL statement (The domain is “domain.local” right know). All printer need to be listed in the AD.
The script follows:
Option Explicit
Const vbModal = 1
Const ADS_SCOPE_SUBTREE = 2
Dim oDlg, oReplicatorForm, oPrinterForm, sBtn, objConnection, objCommand, objRecordSet, x, i, oNet, oShell, oPrinters
Set objConnection = CreateObject("ADODB.Connec
Set objCommand = CreateObject("ADODB.Comman
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnectio
objCommand.CommandText = "SELECT printerName,serverName,loc
& " 'LDAP://DC=domain,DC=local
objCommand.Properties("Pag
objCommand.Properties("Tim
objCommand.Properties("Sea
objCommand.Properties("Cac
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
x=1
i=0
Set oNet = CreateObject("WScript.Netw
Set oShell = WScript.CreateObject("WScr
Set oDlg = Wscript.CreateObject("WshD
Set oReplicatorForm = BuildReplicatorForm(objRec
objRecordSet.MoveFirst
Set oPrinterForm = BuildPrinterForm(objRecord
objRecordSet.MoveFirst
oReplicatorForm.Show vbModal
Select Case Ucase(oDlg.Clicked)
Case "1"
sBtn = oReplicatorForm.GetOptionB
If oReplicatorForm.Ctl("Remov
Set oPrinters = oNet.EnumPrinterConnection
For i = 1 to oPrinters.Count - 1 Step 2
If Left(oPrinters.Item(i),2)=
oNet.RemovePrinterConnecti
End If
Next
End If
oNet.AddWindowsPrinterConn
oNet.SetDefaultPrinter sBtn
oPrinterForm.Show vbModal
Select Case Ucase(oDlg.Clicked)
Case "3"
Do while x=<objRecordSet.RecordCoun
If oPrinterForm.Ctl("Box"&x).
oNet.AddWindowsPrinterConn
objRecordSet.MoveNext
End If
x=x+1
Loop
MsgBox "Printer installationen er ferdigt"
Case Else
MsgBox "Du har kun installeret en default printer"
End Select
Case Else
MsgBox "Du har annulleret instalationen du har ikke adgang til printerene"
End Select
oReplicatorForm.Clear
oPrinterForm.Clear
Wscript.DisconnectObject oDlg
Set oDlg = Nothing
Function BuildReplicatorForm(objRec
Dim oFrm1, BtnPlaceHigh, BtnPlaceLeft, Rows, oCtl, x
Set oFrm1 = oDlg.NewForm
BtnPlaceHigh=300
BtnPlaceLeft=150
Rows=(objRecordSet1.Record
x=0
oFrm1.NewButton "1", 450, 7600, 750, 375, "&Next"
oFrm1.NewButton "Cancel", 1400, 7600, 750, 375, "&Cancel"
oFrm1.Ctl("Cancel").Cancel
Set oCtl = oFrm1.NewCheckBox("Remove"
oCtl.ToolTipText = "Fjern gamle printere"
oFrm1.NewImage "IMG1", 250, 200 , 0, 0, "IconQuestion"
oFrm1.NewLabel "LBL1", 1150, 300, 3000, 375, "Printer valg"
oFrm1.NewFrame "FRM1", 400, 700, Rows*4500, 6300, " Vælg Default Printer "
Set oCtl = oFrm1.NewLabel("LBL2", (Rows*4500)-1450, 7500, 1800, 200, "By Sune Stevnsborg")
oCtl.ForeColor = RGB(66, 66, 66)
Set oCtl = oFrm1.NewLabel("LBL3", (Rows*4500)-1450, 7710, 1800, 200, "For Leif Hansen Gruppen")
oCtl.ForeColor = RGB(66,66, 66)
Do Until objRecordSet1.EOF
Set oCtl = oFrm1.NewOptionButton(objR
oCtl.ToolTipText = "Vælg Default Printer"
objRecordSet1.MoveNext
BtnPlaceHigh=BtnPlaceHigh+
x=x+1
If x=15 Then
BtnPlaceLeft=BtnPlaceLeft+
BtnPlaceHigh=300
X=0
End If
Loop
oFrm1.Caption = "Printer Installation"
oFrm1.TaskBar = False
oFrm1.AutoSize
Set BuildReplicatorForm = oFrm1
End Function
Function BuildPrinterForm(objRecord
Dim oFrm2, BtnNr, BtnPlaceHigh, BtnPlaceLeft, Rows, oCtl, x
Set oFrm2 = oDlg.NewForm("2")
BtnNr=1
BtnPlaceHigh=300
BtnPlaceLeft=150
Rows=(objRecordSet2.Record
x=0
oFrm2.NewButton "3", 450, 7100, 750, 375, "&Done"
oFrm2.NewButton "Cancel", 1400, 7100, 750, 375, "&Cancel"
oFrm2.Ctl("Cancel").Cancel
oFrm2.NewImage "IMG1", 250, 200 , 0, 0, "IconQuestion"
oFrm2.NewLabel "LBL1", 1150, 300, 3000, 375, "Printer valg"
oFrm2.NewFrame "FRM2", 400, 700, Rows*4500, 6300, " Vælg yderlgere printere "
Set oCtl = oFrm2.NewLabel("LBL2", (Rows*4500)-1450, 7100, 1800, 200, "By Sune Stevnsborg")
oCtl.ForeColor = RGB(66, 66, 66)
Set oCtl = oFrm2.NewLabel("LBL3", (Rows*4500)-1450, 7310, 1800, 200, "For Leif Hansen Gruppen")
oCtl.ForeColor = RGB(66,66, 66)
Do Until objRecordSet2.EOF
Set oCtl = oFrm2.NewCheckBox("Box"&Bt
oCtl.ToolTipText = "Vælg yderlgere printere"
objRecordSet2.MoveNext
BtnNr=BtnNr+1
BtnPlaceHigh=BtnPlaceHigh+
x=x+1
If x=15 Then
BtnPlaceLeft=BtnPlaceLeft+
BtnPlaceHigh=300
X=0
End If
Loop
oFrm2.Caption = "Printer Installation"
oFrm2.TaskBar = False
oFrm2.AutoSize
Set BuildPrinterForm = oFrm2
End Function
I am no script kiddy so please don’t flame me for my appalling script. On windows XP there are built in vbs scripts that will allow you to create IP printer ports and manage printer objects.
cscript c:\windows\system32\prnpor t.vbs -a -o raw -r IP_192.168.0.10 -h 192.168.0.10
cscript c:\windows\system32\prnmng r.vbs -a -p "HPLJ2300" -m "HP Laserjet 2300 Series PCL 5e" -r "IP_192.168.0.10"
I placed both of the above lines in a bacth file and it did the job just fine. I am sure a better script can be created as my coding skills are very lame.
cscript c:\windows\system32\prnpor
cscript c:\windows\system32\prnmng
I placed both of the above lines in a bacth file and it did the job just fine. I am sure a better script can be created as my coding skills are very lame.
Here is a simpler solution I found on the web recently
I created a script and launched it from the login script (login.bat)
Dim net
Set net = CreateObject("WScript.Netw ork")
net.AddWindowsPrinterConne ction "\\dbsinhouse3\Canon3100FA X"
net.AddWindowsPrinterConne ction "\\dbsinhouse3\Canon3100PC L"
net.AddWindowsPrinterConne ction "\\dbsinhouse3\CanoniRC"
net.AddWindowsPrinterConne ction "\\dbsinhouse3\LexmarkO"
net.AddWindowsPrinterConne ction "\\dbsinhouse3\Tek850"
Work wonderful and is so simple.
I created a script and launched it from the login script (login.bat)
Dim net
Set net = CreateObject("WScript.Netw
net.AddWindowsPrinterConne
net.AddWindowsPrinterConne
net.AddWindowsPrinterConne
net.AddWindowsPrinterConne
net.AddWindowsPrinterConne
Work wonderful and is so simple.
ASKER
That looks good, is there one for Network Places as well?
I have a bunch of network places I want added is there a script for it?
I have a bunch of network places I want added is there a script for it?
Can you explain network places? I don't understand the question you presented.
Thanks
Thanks
I use con2prt, it is easy to use, but i need to connect printers to computers.
eks. all computers in room A shoud have printer A as default printer, i have uset logon script, it does not work.
This connect all printers, but Xerox will always be default.
\\Bilbo\NETLOGON\con2prt /c \\bilbo\Xerox
\\Bilbo\NETLOGON\con2prt /c \\bilbo\EDB1
\\Bilbo\NETLOGON\con2prt /c \\bilbo\Lille-M
\\Bilbo\NETLOGON\con2prt /c \\bilbo\SOL
\\Bilbo\NETLOGON\con2prt /c \\bilbo\Mediatek
Any ide?
eks. all computers in room A shoud have printer A as default printer, i have uset logon script, it does not work.
This connect all printers, but Xerox will always be default.
\\Bilbo\NETLOGON\con2prt /c \\bilbo\Xerox
\\Bilbo\NETLOGON\con2prt /c \\bilbo\EDB1
\\Bilbo\NETLOGON\con2prt /c \\bilbo\Lille-M
\\Bilbo\NETLOGON\con2prt /c \\bilbo\SOL
\\Bilbo\NETLOGON\con2prt /c \\bilbo\Mediatek
Any ide?
I prefer the IFMEMBER method...once setup properly...it's easy to manage through AD which printers a user is assigned.
http://www.microsoft.com/technet/archive/winntas/tips/winntmag/grlogon.mspx?mfr=true
First make all of your printers shared on a print server...
Example logon script.....too easy.
ifmember "accounting users"
if not errorlevel 1 goto EXIT
cscript prnmngr.vbs -x
cscript prnmngr.vbs -ac -p "\\servname\printersharena me"
:EXIT
i just deleted all printers and added \servername\printer provided the user is a member of "accounting users".
http://www.microsoft.com/technet/archive/winntas/tips/winntmag/grlogon.mspx?mfr=true
First make all of your printers shared on a print server...
Example logon script.....too easy.
ifmember "accounting users"
if not errorlevel 1 goto EXIT
cscript prnmngr.vbs -x
cscript prnmngr.vbs -ac -p "\\servname\printersharena
:EXIT
i just deleted all printers and added \servername\printer provided the user is a member of "accounting users".
http://www.computerhope.com/nethlp.htm#01