Topic: Help with VBScript Pages that link to <a href="https://ozoneasylum.com/backlink?for=28417" title="Pages that link to Topic: Help with VBScript" rel="nofollow" >Topic: Help with VBScript\

 
Author Thread
Synthetic
Paranoid (IV) Inmate

From: under your rug,
Insane since: Jul 2001

IP logged posted posted 09-12-2006 00:23 Edit Quote

Sorry if this is the wrong forum, don't really see VBScript listed.

I need help with mapping printers based on a computers name

code:
Dim multiPrinter, PrinterLocation1, PrinterLocation2, PrinterLocation3, PrinterLocation4
PrinterLocation1 = "\\023netcdc1\023Lab1HP4200"
PrinterLocation2 = "\\023netcdc1\023Lab2HP4200"
PrinterLocation3 = "\\023netcdc1\023Lab3HP4050"
PrinterLocation4 = "\\023netcdc1\023Lab4HP4200"
Set multiPrinter = CreateObject("WScript.Network") 
multiPrinter.AddWindowsPrinterConnection PrinterLocation1
multiPrinter.AddWindowsPrinterConnection PrinterLocation2
multiPrinter.AddWindowsPrinterConnection PrinterLocation3
multiPrinter.AddwindowsPrinterConnection PrinterLocation4



Is what i have so far, this basicly maps all 4 printers for each site area. Well the idea is to map only 1 printer based on what lab your in, that is ofcourse desernable by your computer name. "023lab4r6w3" and lab1 might have "023lab1r5w2" If they are in lab 2 i want to print only to lab 2, lab 3 printer 3, etc.

The breakdown is 023 is the site code, lab1-4 are the labs, r5 means row 5, and w2 means workstation 2.

Its at a center for kids, so the learning curve varies quite a bit. Just want it fairly simple so they are not printing to the wrong areas. I know there are other ways to do this but thats not my call, just looking for advice on how this could be done and not how to do it any other way.

Thanks in advance for any assistance,

Synthetic's Chess Player Page

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

IP logged posted posted 09-12-2006 22:40 Edit Quote

I don't think that would be too hard to do.

Do all the computer names have 3 digits before the "labX" and then 4 characters after?

If so, you can grab the name of the computer, then parse out the "labX" part, then match it with the printer name.

Here is some code that will display the name of the computer.

code:
Dim objNet
On Error Resume Next 

Set objNet = CreateObject("WScript.NetWork") 
	
Dim strInfo

strInfo = objNet.ComputerName

MsgBox strInfo
	
'Destroy the Object to free the Memory
Set objNet = Nothing



After you have that, use the "Mid" function to pull out the lab number.

code:
strMyString = Mid(strMain, 8, 10)



just pass the computer name to the mid function and tell it where to start and how many characters.

code:
strMyString = Mid(strInfo,4,4)





Later,

C:\

(Edited by CPrompt on 09-12-2006 22:44)

Synthetic
Paranoid (IV) Inmate

From: under your rug,
Insane since: Jul 2001

IP logged posted posted 09-14-2006 02:07 Edit Quote

Thanks, just enough to get me where i wanted to be

code:
Dim objNet
On Error Resume Next 

Set objNet = CreateObject("WScript.NetWork") 
	
Dim strInfo

strInfo = objNet.ComputerName

'Destroy the Object to free the Memory
Set objNet = Nothing

strMyString = Mid(strMain, 8, 10)

strMyString = Mid(strInfo,7,1)

'We are pulling the lab number from the computer name
if		strMyString = 1 then
PrinterGO = "\\023netcdc1\023Lab1HP4200"
msgbox "Lab 1 Printer Installed"
elseif  strMyString = 2 then
PrinterGO = "\\023netcdc1\023Lab2HP4200"
msgbox "Lab 2 Printer Installed"
elseif	strMyString = 3 then
PrinterGO = "\\023netcdc1\023Lab3HP4050"
msgbox "Lab 3 Printer Installed"
elseif	PstrMyString = 4 then
PrinterGO = "\\023netcdc1\023Lab4HP4200"
msgbox "Lab 4 Printer Installed"
else    
msgbox "didn't work"
end if

'Sets the printer based on the number pulled from previous function
Set objPrinter = CreateObject("WScript.Network") 
objPrinter.AddWindowsPrinterConnection PrinterGO



Synthetic's Chess Player Page

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

IP logged posted posted 09-14-2006 02:36 Edit Quote

cool. glad it could help

Later,

C:\



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu