mac_shinobi Posted January 20, 2007 Posted January 20, 2007 In your first for loop instead of checking for the LY1-2250 and sr-4650 why not do a for loop that checks for any that aren't the cutePDF printer(s) and delete whats left over. ("Select * from Win32_Printer where DeviceID <> 'cutePDF'") For Each objPrinter in colInstalledPrinters objPrinter.Delete_ next That way if its not cutePDF then it deletes everything else. BTW I forgot to mention that you probably wont need the 2nd for.... loop as your first one if modified should delete all the left over ones
contink Posted January 26, 2007 Posted January 26, 2007 Having had to try and figure this out the hard way (yes I know I should know but I didn't)... ... if you want to set the default printer for a particular room/etc.. and that printer is local then you need to find out how it's connected (eg: USB002) and then set it like this: WshNetwork.SetDefaultPrinter "USB002" Simple isn't it... :oops:
Geoff Posted January 26, 2007 Posted January 26, 2007 Yes, the information you need is the port name.
contink Posted January 26, 2007 Posted January 26, 2007 Yes, the information you need is the port name. .. *gritted teeth*.. and where were you an hour ago when I needed ya.. Ah well.. learned that one.
timbo343 Posted March 9, 2007 Posted March 9, 2007 Can some just help me to add into this script a variable for a specific user, ie, if joe bloggs wanted a certain printer? and fred smith got another printer? Thanks T ' Script to add network printers to workstations and thin clients WHEN THEY ARE PART OF A SPECIFIC GROUP IN AD ' Declare variables and enumerate existing printer connections ' Setting the parameters up On error resume next Set WshShell = WScript.CreateObject("WScript.Shell") Set WshNetwork = WScript.CreateObject("WScript.Network") Set wshnetwork = CreateObject("WScript.Network") Set ADSysInfo = CreateObject("ADSystemInfo") Set CurrentUser = GetObject("LDAP://" & ADSysInfo.Username) Set oPrinters = WshNetwork.EnumPrinterConnections dim Counter, PrinterPath dim strConnectString, strResult strGroups = LCase(CurrentUser.MemberOf) strGroups = LCase(Join(CurrentUser.MemberOf)) ' Sets the groups up with the member of settings in AD Const Maths = "cn=mathematics" Const ITstaff = "cn=information technology" Const ITAdmin = "cn=admin" Const DesTech = "cn=design and technology" Const Careers = "cn=careers" Const Enterprise = "cn=enterprise" Dim computerName computerName = LCase(WshNetwork.ComputerName) 'WScript.Echo "computername variable: " & (computerName) 'Deletes All Network Printers... Not manually installed For i = 0 to oPrinters.Count - 1 step 2 On Error Resume Next Wshnetwork.RemovePrinterConnection oPrinters.Item(i+1), true, true NEXT ' Adding Printers ' ITstaff Group if Instr(strGroups,ITstaff) then wshnetwork.AddwindowsPrinterConnection "\\hades\office-ml2250" End If 'ITstaff ' Maths Group If Instr(strGroups,Maths) then wshnetwork.AddwindowsPrinterConnection "\\hades\MATHS-1320" wshnetwork.AddwindowsPrinterConnection "\\hades\MATHS-6980" wshnetwork.setdefaultprinter "\\hades\maths-1320" End If 'maths ' ITAdmin Group If Instr(strGroups,ITadmin) then wshnetwork.AddwindowsPrinterConnection "\\hades\SR-4650" End If 'ITadmin ' DesTech Group If Instr(strGroups,DesTech) then wshnetwork.AddwindowsPrinterConnection "\\hades\r7-2600n" End If 'DesTech ' Careers Group If Instr(strGroups,Careers) then wshnetwork.AddwindowsPrinterConnection "\\hades\enterprise-2600n" wshnetwork.AddwindowsPrinterConnection "\\careers-01\CareersPrinter" wshnetwork.setdefaultprinter "\\careers-01\CareersPrinter" End If 'Careers ' enterprise group If Instr(strGroups,Enterprise) then wshnetwork.AddwindowsPrinterConnection "\\hades\r7-2600n" End If 'Enterprise ' Adding Printers depentant on computer name Select case (Left(computername,3)) Case "wr-" wshnetwork.addwindowsprinterconnection "\\hades\wr-2200" wshnetwork.setdefaultprinter "\\hades\wr-2200" End Select Select Case (computerName) Case "lft_6169-at" wshnetwork.addwindowsprinterconnection "\\hades\LY1-2200" wshnetwork.setdefaultprinter "\\hades\LY1-2200" End Select Select Case (computerName) Case "lft_6169-at" wshnetwork.addwindowsprinterconnection "\\hades\LY1-2200" wshnetwork.setdefaultprinter "\\hades\LY1-2200" End Select Select Case (computerName) Case "hoy7" wshnetwork.addwindowsprinterconnection "\\hades\wr-2200" wshnetwork.setdefaultprinter "\\hades\wr-2200" End Select
ChrisH Posted March 9, 2007 Posted March 9, 2007 You can grab the username with: Uname= wshnetwork.Username and use Uname as your variable.
timbo343 Posted March 9, 2007 Posted March 9, 2007 so i would set in the header uname= wshnetwork.username then what would i put in the working area of the script? T
timbo343 Posted March 9, 2007 Posted March 9, 2007 so to map a printer for a user would it be if Instr(struser."joe.bloggs") then wshnetwork.AddwindowsPrinterConnection
mac_shinobi Posted March 9, 2007 Posted March 9, 2007 If you use struser then you could do Select Case struser Case "joe.bloggs" wshnetwork.AddwindowsPrinterConnection Case "John.Smith" wshnetwork.AddwindowsPrinterConnection Case Else ' Code here to add printer connection if its anyone else or if you want to ' do anything else afterwards that does not match any of the above users 'in the above case select statements. End Select If you use Uname then just change the first line of code from Select Case struser to Select Case Uname Easier then all the if else statements and easier to read etc.
djm968 Posted March 9, 2007 Posted March 9, 2007 Beat me to it gecko.. That is excatly what I would do.
mac_shinobi Posted March 9, 2007 Posted March 9, 2007 If strUser returns domain\username Then you can use the split function before you do the select case to attain the username from it. Dim x x = split(struser,"\") Select Case x(1) Case "username_one" wshnetwork.AddwindowsPrinterConnection Case "username_two" wshnetwork.AddwindowsPrinterConnection End Select '------------------ Just thought that would be handy.
timbo343 Posted March 9, 2007 Posted March 9, 2007 got it working... needed to change struser = wshnetwork.domain to struser = wshnetwork.username
djm968 Posted March 9, 2007 Posted March 9, 2007 got it working... needed to change struser = wshnetwork.domain to struser = wshnetwork.username Sorry timbo343, I think that was my mistake! :oops:
mac_shinobi Posted March 9, 2007 Posted March 9, 2007 you could just go to http://www.wisesoft.co.uk and get the script builder ( might of made it easier lol ) you have to register but registration is free and there are other useful utils on there by wisesoft82 from this site ( I think thats his username on here )
Behuck Posted April 7, 2007 Posted April 7, 2007 Greetings! I, too, am attempting to use a .vbs script to assign specific printers to specific computers in specific rooms. I've been reading this, and other threads, on the subject matter, seeing some of the same scripting concept that I'm attempt to use. Here is my dilemma-I have named each of my clients with the following structure: RM400-1-PRN1 with the "PRN1" to be used to indicate, in the scripting, the specific printer. In my script, I use the " = right(xxxxx, 3)" but it does not seem to be reading the "PRNx" and mapping the specified printer. Below is the script that I'm trying to use: Example 1: Dim wshNetwork Dim strUsername Dim intCnt Dim CurrentUser Dim strCompName Dim strShortName Dim PrinterPath Set wshNetwork = CreateObject("WScript.Network") On Error Resume Next wshNetwork.RemoveNetworkDrive "h:" wshNetwork.RemoveNetworkDrive "P:" wshNetwork.MapNetworkDrive "h:", "\\xxxx\" & wshNetwork.UserName & "$" strCompName = wshNetwork.ComputerName strShortName = RIGHT(strCompName,4) Select Case strShortName Case "PRN1" PrinterPath = "\\xxxx\LAB1(KOELLER)" wshNetwork.AddWindowsPrinterConnection PrinterPath wshNetwork.SetDefaultPrinter "\\xxxx\LAB1(KOELLER)" Case "PRN3" Set objWSHNetwork = CreateObject("WScript.Network") 'create network object strConnectString = "\\xxxx\lab2 (open)" strResult = objWSHNetwork.AddWindowsPrinterConnection(strConnectString) wshNetwork.SetDefaultPrinter "\\xxxx\lab2 (open)" End Select WScript.Quit or Example 2: Dim wshNetwork Dim strUsername Dim intCnt Dim CurrentUser Dim strCompName Dim strShortName Dim PrinterPath Set wshNetwork = CreateObject("WScript.Network") On Error Resume Next wshNetwork.RemoveNetworkDrive "h:" wshNetwork.RemoveNetworkDrive "P:" wshNetwork.MapNetworkDrive "h:", "\\xxxx\" & wshNetwork.UserName & "$" strCompName = wshNetwork.ComputerName strShortName = RIGHT(strCompName,4) Select Case strShortName Case "PRN3" PrinterPath = "\\xxxx\MediaCtr3500" wshNetwork.AddWindowsPrinterConnection PrinterPath wshNetwork.SetDefaultPrinter "\\xxxx\MediaCtr3500" End Select WScript.Quit ("xxxx" is sever name) If anyone has any suggestions and/or knows what needs to be fixed to correct the problem, it would be greatly appreciated! Behuck
mac_shinobi Posted April 7, 2007 Posted April 7, 2007 replied to your other post , if you need more help feel free to pm me
ind13 Posted April 10, 2007 Posted April 10, 2007 im not sure if its supposed to be case specific but the problem i had was that in the script the computer name had to be lower case otherwise i didn't pick it up ie instead of Case "PRN1" try case "prn1"
Geoff Posted April 10, 2007 Posted April 10, 2007 yes, Ric's script will lcase() the PC names prior to doing the select....case. So you need to make sure all your case "blah" are lowercase.
VGeek Posted April 10, 2007 Posted April 10, 2007 We had a similar problem with vbscripts. I would say test Case "prn1" instead of Case "PRN1" This should help you however I would also try testing the script to make sure it is getting to that line. A simple test by replacing declared variables with test code. For example strShortName = "prn1" try this in places where variables are passed to identify if there is a error in your code. But looks fine to me.
mullet_man Posted April 17, 2007 Posted April 17, 2007 Hi Great script Ric, I have one little problem which am sure you can help with, I have setup using 3 letters to inspect for our computer rooms etc. This has worked fine expect for our Science laptops which are named S-01, S-02 to S-30. If I took the letter inspect down to 2, this would clash with RM2 and RM15. Any ideas? I know I could write them out individually but just to be lazy and smarter. Thanks. Ste.
Ric_ Posted April 17, 2007 Author Posted April 17, 2007 @mullet_man: Not sure what you are after... can you say what you want to achieve, e.g. S-01 to S-30 -> \\server\printer1 RM2-01 to RM2-30 -> \\server\printer2 or whatever? If it is as above, you can use a split on the computerName variable in the script and then you can inspect the bit before the -
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now