Jump to content

Recommended Posts

Posted

I haven't got my riddle solving head on today, so could someone tell me what this is doing? Trying to work out how to add a printer if they're on a certain pc.

 

if left(compname,6) = "SUITE1" then

 

PrinterPath = "\\curricsvr1\JUNIOR-SUITE"

PrinterPath2 = "\\curricsvr1\DJ1220C"

PrinterPath3 = "\\curricsvr1\DJ2000C"

WshNetwork.AddwindowsPrinterConnection PrinterPath

WshNetwork.AddwindowsPrinterConnection PrinterPath2

WshNetwork.AddwindowsPrinterConnection PrinterPath3

WshNetwork.SetDefaultPrinter "\\curricsvr1\JUNIOR-SUITE"

 

end if

 

Ta!

Posted
if the computer name begins with "SUITE1" it will add those printers and make a printer called JUNIOR-SUITE the defult printer
  • Thanks 1
Posted

Hey,

 

This is a basic VB Script, it is adding printers and as far as I can tell it is trying to add them determined on their name. If this was my riddle I would prob use CMD script.

 

"@ECHO OFF

 

IF %HOSTNAME% = "AHOSTNAME1" {

REM ----ADD PRINTER GLOBALLY FOR AN USER THAT LOGS ON----

RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /ga /n \\SERVERNAME2\PRINTERSHARE2

REM ---- RESTART THE PRINT SPOOLER SERVICE----

NET STOP SPOOLER

NET START SPOOLER

}

 

IF %HOSTNAME% = "AHOSTNAME2" {

REM ----ADD PRINTER GLOBALLY FOR AN USER THAT LOGS ON----

RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /ga /n \\SERVERNAME2\PRINTERSHARE2

REM ---- RESTART THE PRINT SPOOLER SERVICE----

NET STOP SPOOLER

NET START SPOOLER

}

 

EXIT"

 

LET ME KNOW IF YOU NEED ANY MORE HELP.

 

DAN

Posted
The 'left' function takes a string (which is held in compname) and a number, and returns that many characters beginning at the start of the string. So left(compname,6) gets the first six characters in the computer name.
  • Thanks 1
Posted

Take 6 characters from the left of the computer name. I'm guessing your PCs are named something like suite10, suite11, suite12 etc??

 

Provided you have got a good naming convention then it's easy to take part of the name and work with it to do things like deciding where a machine is and which printer it should get. Other things to look for are the mid and right functions which can extract other bits of the name (eg mid(compname,3,4) starts at character 3 and takes 4 characters - "ite1" and right(compname,2) would return "10" from the first name above)

 

Dan's batch file works fine but you can probably imagine that it gets a bit longwinded if you have more than a few computers - picking the fragment of the name which identifies the room often keeps things simple!

  • Thanks 1
Posted

Hmm, ok, i realised the computer i wanted was already on there (named differently to what i was expecting. I've not long started here to things aren't quite the way i'd have them)

 

I added the printer i wanted. Logged in. I saw it run CMD and call the script. But then when i tried printers and faxes it wasn't there.

 

Any ideas what i've done wrong. I copied the format from the previous entries?

Posted

It's not my code, i've just added a line lol

 

on error resume next

Set WshNetwork = CreateObject("WScript.Network")

Dim Compname

Compname = WSHNetwork.ComputerName

if left(compname,6) = "SUITE1" then 

PrinterPath = "\\curricsvr1\JUNIOR-SUITE"
PrinterPath2 = "\\curricsvr1\DJ1220C"
PrinterPath3 = "\\curricsvr1\DJ2000C"
 	WshNetwork.AddwindowsPrinterConnection PrinterPath
 	WshNetwork.AddwindowsPrinterConnection PrinterPath2
WshNetwork.AddwindowsPrinterConnection PrinterPath3
WshNetwork.SetDefaultPrinter "\\curricsvr1\JUNIOR-SUITE"

end if 


if left(compname,3) = "JNR" then 

PrinterPath = "\\curricsvr1\JUNIOR-SUITE"
PrinterPath2 = "\\curricsvr1\DJ1220C"
PrinterPath3 = "\\curricsvr1\DJ2000C"
 	WshNetwork.AddwindowsPrinterConnection PrinterPath
 	WshNetwork.AddwindowsPrinterConnection PrinterPath2
WshNetwork.AddwindowsPrinterConnection PrinterPath3
WshNetwork.SetDefaultPrinter "\\curricsvr1\JUNIOR-SUITE"

end if

if left(compname,3) = "TAR" then 

PrinterPath = "\\curricsvr1\JUNIOR-SUITE"
PrinterPath2 = "\\curricsvr1\DJ1220C"
 	WshNetwork.AddwindowsPrinterConnection PrinterPath
 	WshNetwork.AddwindowsPrinterConnection PrinterPath2
WshNetwork.SetDefaultPrinter "\\curricsvr1\JUNIOR-SUITE"

end if


if left(compname,3) = "JUN" then 

PrinterPath = "\\curricsvr1\JUNIOR-SUITE"
PrinterPath2 = "\\curricsvr1\INFLIB"
 	WshNetwork.AddwindowsPrinterConnection PrinterPath
 	WshNetwork.AddwindowsPrinterConnection PrinterPath2
WshNetwork.SetDefaultPrinter "\\curricsvr1\JUNIOR-SUITE"


end if

if left(compname,6) = "JUNLIB" then

PrinterPath =  "\\curricsvr1\INFLIB"
PrinterPath2 = "\\curricsvr1\KM2430DL"
PrinterPath3 = "\\curricsvr1\JUNIOR-SUITE"	
WshNetwork.AddwindowsPrinterConnection PrinterPath
WshNetwork.AddwindowsPrinterConnection PrinterPath2
wshNetwork.SetDefaultPrinter "\\curricsvr1\INFLIB"

end if


if left(compname,3) = "LSR" then 

PrinterPath = "\\curricsvr1\JUNIOR-SUITE"
PrinterPath2 = "\\curricsvr1\DJ1220C"
PrinterPath3 = "\\LSR-PC1\HP DeskJet 840C/841C/842C/843C"
 	WshNetwork.AddwindowsPrinterConnection PrinterPath
 	WshNetwork.AddwindowsPrinterConnection PrinterPath2
WshNetwork.AddwindowsPrinterConnection PrinterPath3
WshNetwork.SetDefaultPrinter "\\LSR-PC1\HP DeskJet 840C/841C/842C/843C"

end if

if left(compname,8) = "INFSUITE" then 

PrinterPath = "\\curricsvr1\KM2430DL"
rem PrinterPath2 = "\\curricsvr1\INFLIB1"
 	WshNetwork.AddwindowsPrinterConnection PrinterPath
 	WshNetwork.AddwindowsPrinterConnection PrinterPath2
WshNetwork.SetDefaultPrinter "\\curricsvr1\KM2430DL"

end if

if left(compname,3) = "INF" then 

PrinterPath = "\\curricsvr1\KM2430DL"
PrinterPath2 = "\\curricsvr1\INFLIB1"
 	WshNetwork.AddwindowsPrinterConnection PrinterPath
 	WshNetwork.AddwindowsPrinterConnection PrinterPath2
WshNetwork.SetDefaultPrinter "\\curricsvr1\INFLIB"


end if


if left(compname,3) = "HAR" then 

PrinterPath = "\\curricsvr1\JUNIOR-SUITE"
PrinterPath2 = "\\curricsvr1\DJ1220C"
PrinterPath3 = "\\curricsvr1\DJ2000C"
 	WshNetwork.AddwindowsPrinterConnection PrinterPath
 	WshNetwork.AddwindowsPrinterConnection PrinterPath2
WshNetwork.AddwindowsPrinterConnection PrinterPath3

end if


if left(compname,6) = "JUNLIB" then 

PrinterPath = "\\curricsvr1\KM2430DL"
PrinterPath2 = "\\curricsvr1\DJ2000C"
 	WshNetwork.AddwindowsPrinterConnection PrinterPath
 	WshNetwork.AddwindowsPrinterConnection PrinterPath2
WshNetwork.SetDefaultPrinter "\\curricsvr1\KM2430DL"


end if


if left(compname,6) = "RESOURCES" then

PrinterPath = "\\curricsvr1\TASROOM"
Printerpath2 = "\\curricsvr1\JUNIOR-SUITE"
WshNetwork.SetDefaultPrinter "\\curricsvr1\TASROOM"

end if

Posted

If it is the resources printer that you are trying to add then you are missing the two lines:

 

WshNetwork.AddwindowsPrinterConnection PrinterPath

WshNetwork.AddwindowsPrinterConnection PrinterPath2

  • Thanks 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...