I'm working on this script which is supposed to map a printer based on computer membership. But I can't it to work. Could anyone take a look at it please?
Note that I've put a msgbox strPrinter at the bottom just to find out if the function is working. And the message box doesn't even appear!
Note that I've put a msgbox strPrinter at the bottom just to find out if the function is working. And the message box doesn't even appear!
Code:
Sub Main()
Set objNetwork = WScript.CreateObject("WScript.Network")
' Navn på domene
strDomain = "Ringve"
' Hent datamaskinnavn
strComputerName = objNetwork.ComputerName
' Last inn referanse til vår datamaskin
Set objComputer = GetObject("WinNT://" & strDomain & "/" & strComputerName & ",computer")
'Legger til Printer
strPrinter = ""
Select Case CBool(-1)
Case isComputerMember("Gymkontor")
strPrinter = "\\Ringve-fil\Dell_Laser_Gymkontor"
Case isComputerMember("Lærerbakrom")
strPrinter = "\\Ringve-fil\Fargelaser_lærerbakrom"
Case isComputerMember("Bibliotek")
strPrinter = "\\Ringve-fil\Dell_Laser_Bibliotek"
Case isComputerMember("FO03")
strPrinter = "\\Ringve-fil\Dell_Fargelaser_FO03"
Case isComputerMember("AA05")
strPrinter = "\\Ringve-fil\HPLaser_AA05"
Case isComputerMember("AA07")
strPrinter = "\\Ringve-fil\HPLaser_AA07"
Case isComputerMember("AA08")
strPrinter = "\\Ringve-fil\HPLaser_AA08"
Case isComputerMember("Østmarka IT")
strPrinter = "\\Ringve-fil\Lexmark_Østmarka_IT-rom"
Case isComputerMember("Østmarka lærerrom")
strPrinter = "\\Ringve-fil\Kopimaskin_PHST-Lærerrom"
Case isComputerMember("Arbeidsrom 3 og 4")
strPrinter = "\\Ringve-fil\Kopimaskin_arbeidsrom_3og4"
Case Else
MsgBox "No Printer"
End Select
'objNetwork.AddWindowsPrinterConnection strPrinter
MsgBox strPrinter
End Sub