Just out of curiousty where is RIC's post and how did you get the client name versus the machine name ?
Printable View
Just out of curiousty where is RIC's post and how did you get the client name versus the machine name ?
Check out http://edugeek.net/index.php?name=Fo...iewtopic&t=404 :D
The important bit is
The system has two variables on thin clients:Code:LCase(WshShell.ExpandEnvironmentStrings("%CLIENTNAME%"))
* computername = the server's name
* clientname = the client machine's name
Hope this helps.
I currently use con2prt.exe to assign printers to computers based on location.
Just enter a location into the enviornment settings in windows and make yourself a logon script and hey presto. Work flawlessly for the last 18 months.
Here is a printer script which can be done by room and has been very easy to run. It was provided by our network migration.
Processprinter.vbs
You have this VBS file to run on each log in.Code:Option Explicit
DIM ForReading
DIM ForWriting
DIM ForAppending
DIM strComputer
DIM WshNetwork
DIM objWMIService
DIM colInstalledPrinters
DIM objPrinter
DIM FileIn
DIM FSO
DIM WshShell
DIM objEnv
DIM ClientName
DIM Username
DIM objFile
DIM Found
DIM Wild
DIM strContents
DIM SpltInput
DIM Col0
DIM COl1
DIM ColLen
DIM UFound
DIM UMatch
DIM Match
DIM objShell
DIM FN_Loop
ForReading = 1
ForWriting = 2
ForAppending = 8
strComputer = "."
Set WshNetwork = CreateObject("WScript.Network")
Set objShell = CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer")
ON ERROR RESUME NEXT
REM Delete all printers except for local ones.
For Each objPrinter in colInstalledPrinters
If Left(objPrinter.Name,2) = "\\" Then
objPrinter.Delete_
End If
Next
ON ERROR GOTO 0
FileIn = "\\clustaps\batch$\ClientPrinterMapping.txt"
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objEnv = WshShell.Environment("Process")
FOR FN_Loop = 1 TO 5
Set WshShell = WScript.CreateObject("WScript.Shell")
ClientName = objEnv("COMPUTERNAME")
IF ClientName <> "" THEN EXIT FOR
Wscript.Sleep(5000)
IF FN_LOOP = 5 THEN
MSGBOX "Unable to read the computer name , please inform a technician."
END IF
NEXT
Username = objEnv("USERNAME")
Set objFile = FSO.OpenTextFile(FileIn, ForReading)
Found = 0
Wild = 1
Do While Not objFile.AtEndOfStream
strContents = objFile.ReadLine
SpltInput = split(strContents,VBTAB)
If ubound(SpltInput) > 0 Then
Col0 = SpltInput(0)
Col1 = SpltInput(1)
If UCase(Col0) = "NAME" THEN
ColLen = InStr(Col1,"*")
If Found = 0 and Wild = 1 Then
IF COlLen > 0 Then
IF UCASE(Left(ClientName, ColLen -1)) = UCASE(Left(Col1, ColLen -1)) THEN
Found = 1
Wild = 1
Match = Col1
End IF
End If
End If
IF ColLen = 0 Then
IF UCase(ClientNAme) = UCase(Col1) THEN
Found = 1
Wild = 0
Match = Col1
End If
End If
End If
IF UCASE(Col0) = "UNAME" THEN
IF UCase(Username) = UCase(Col1) THEN
UFound = 1
UMatch = Col1
End If
End IF
End If
Loop
objFile.close
IF Found = 1 Then
call Readblock("NAME",Match)
END IF
IF UFound = 1 Then
call Readblock("UNAME",Username)
END IF
sub ReadBlock(Match1,Match2)
Set objFile = FSO.OpenTextFile(FileIn, ForReading)
Do While Not objFile.AtEndOfStream
strContents = objFile.ReadLine
SpltInput = split(strContents,VBTAB)
If ubound(SpltInput) > 0 Then
Col0 = SpltInput(0)
Col1 = SpltInput(1)
If UCASE(Col0) = UCASE(Match1) AND UCASE(Col1) = UCASE(Match2) Then
Do While Not objFile.AtEndOfStream
strContents = objFile.ReadLine
SpltInput = split(strContents,VBTAB)
If ubound(SpltInput) > 0 Then
Col0 = SpltInput(0)
Col1 = SpltInput(1)
IF UCASE(Col0) = "MAP" Then
ON ERROR RESUME NEXT
FOR FN_Loop = 1 TO 5
WshNetwork.AddWindowsPrinterConnection Col1
IF Err.Number = 0 THEN EXIT FOR
Wscript.Sleep(5000)
IF FN_LOOP = 5 THEN
MSGBOX "Unable to map the printer " + Col1 + ", please inform a technician."
END IF
NEXT
ON ERROR GOTO 0
End If
If UCASE(Col0) = "DEFAULT" Then
ON ERROR RESUME NEXT
FOR FN_Loop = 1 TO 5
WshNetwork.SetDefaultPrinter Col1
IF Err.Number = 0 THEN EXIT FOR
Wscript.Sleep(5000)
IF FN_LOOP = 5 THEN
MSGBOX "Unable to set the default printer to " + Col1 + ", please inform a technician."
END IF
NEXT
ON ERROR GOTO 0
End If
If UCASE(Col0) = "NAME" OR UCASE(Col0) = "UNAME" Then
Exit Do
End If
End If
Loop
EXit Do
End If
End If
Loop
objFile.close
End sub
You then make a txt file which will contain the following. This is a example.
ClientPrinterMapping.txt
Its very easy and i have never had to touch the VBS file only the txt file.Code:REM Room B11
NAME B11*
MAP \\apsrv01\B11_BW_HP4100
MAP \\apsrv01\B11_Colour_TallyT8006e
DEFAULT \\apsrv01\B11_Colour_TallyT8006e
REM Room B12
NAME B12*
MAP \\apsrv01\B12_BW_HP4100
MAP \\apsrv01\B12_Colour_TallyT8006e
DEFAULT \\apsrv01\B12_BW_HP4100
REM B13
NAME B13*
MAP \\apsrv01\B13_BW_HP4050
MAP \\apsrv01\B13_Colour_TallyT8006e
DEFAULT \\apsrv01\B13_BW_HP4050
Sorry for the long post.
Ross
I always love the "just enter a ..." type things :-) These are always the bits which get forgotten (because it's one extra thing to do) :-)Quote:
Originally Posted by accura2000
hi everybudy,
i was looking for the information on printers' networking... so at last i am here...
thanks for the providing the very useful information for mapping of networked printers ...
P.S. Web Link here are also very informative