Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Problem installing printers with VB

$
0
0

Hello All,

I hope you guys can help me with a problem i have. For a customer we are trying to install printers via a script executed at login. We got it working on 32 bits workstations, but i wont work on 64 bits workstations.

We know that the problem is in removing the printers before connecting them. With the script we have now it works only in 32 bit, but we need a solution that will work on both. Or a script thats checkes the architecture of the PC en executes the script for 32 or 64 bits.

Big thanks in advance!

Michel 

Option Explicit 
 Dim WSHNetwork, FSO, strUserName, strUserDomain, ObjGroupDict, EnvVar, strVarUserName
Dim objNetwork, strLocal, strComputer, objWMIService, colInstalledPrinters, objPrinter
 Dim strUNCPrinter1, strUNCPrinter2, strUNCPrinter3, strUNCPrinter4
 Dim strUNCPrinter5
 dim printers
 dim counter




Set WSHNetwork = WScript.CreateObject("WScript.Network")
 Set EnvVar = WScript.CreateObject("WScript.Shell")
 Set FSO = CreateObject("Scripting.FileSystemObject")
 strVarUserName = EnvVar.ExpandEnvironmentStrings("%username%")




'Wait for user to log in




strUserName = ""
 While strUserName = ""
 WScript.Sleep 100 
 strUserName = WSHNetwork.UserName
 Wend
 strUserDomain = WSHNetwork.UserDomain




Set ObjGroupDict = CreateMemberOfObject(strUserDomain, strUserName)




' Create printers

strUNCPrinter1 = "\\s-exch\P50 - A4 Dubbel (Kleur)"
 strUNCPrinter2 = "\\s-exch\P50 - A4 Dubbel (Z-W)"
 strUNCPrinter3 = "\\s-exch\P50 - A4 Enkel (Kleur)"
 strUNCPrinter4 = "\\s-exch\P50 - A4 Enkel (Z-W)"
 strUNCPrinter5 = "\\s-exch\P50 - TCE - Briefpapier (Z-W)"




'Remove printers

Set objNetwork = CreateObject("WScript.Network")
  objNetwork.RemoveWindowsPrinterConnection "\\s-exch\P50 - A4 Dubbel (Kleur)"
  objNetwork.RemoveWindowsPrinterConnection "\\s-exch\P50 - A4 Dubbel (Z-W)"
  objNetwork.RemoveWindowsPrinterConnection "\\s-exch\P50 - A4 Enkel (Kleur)"
  objNetwork.RemoveWindowsPrinterConnection "\\s-exch\P50 - A4 Enkel (Z-W)"
  objNetwork.RemoveWindowsPrinterConnection "\\s-exch\P50 - TCE - Briefpapier (Z-W)"




' Create printermappings based on groupmembership

If MemberOf(ObjGroupDict, "P50") Then
   Set objNetwork = CreateObject("WScript.Network") 
   objNetwork.AddWindowsPrinterConnection strUNCPrinter1
 End If

If MemberOf(ObjGroupDict, "P50") Then
   Set objNetwork = CreateObject("WScript.Network") 
   objNetwork.AddWindowsPrinterConnection strUNCPrinter2
 End If

If MemberOf(ObjGroupDict, "P50") Then
   Set objNetwork = CreateObject("WScript.Network") 
   objNetwork.AddWindowsPrinterConnection strUNCPrinter3
 End If

If MemberOf(ObjGroupDict, "P50") Then
   Set objNetwork = CreateObject("WScript.Network") 
   objNetwork.AddWindowsPrinterConnection strUNCPrinter4
 End If

If MemberOf(ObjGroupDict, "P50") Then
   Set objNetwork = CreateObject("WScript.Network") 
   objNetwork.AddWindowsPrinterConnection strUNCPrinter5
 End If


 Function MemberOf(ObjDict, strKey)
   MemberOf = CBool(ObjGroupDict.Exists(strKey))
 End Function

Function CreateMemberOfObject(strDomain, strUserName)
   Dim objUser, objGroup
   Set CreateMemberOfObject = CreateObject("Scripting.Dictionary")
   CreateMemberOfObject.CompareMode = vbTextCompare
   Set objUser = GetObject("WinNT://" & strDomain & "/" & strUserName & ",user")
   For Each objGroup In objUser.Groups
   CreateMemberOfObject.Add objGroup.Name, "-"
   Next
   Set objUser = Nothing
 End Function



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>