Advanced Network Printer Script - Multi Office

Author Message
rekrapg

  • Total Posts : 4
  • Scores: 0
  • Reward points : 0
  • Joined: 10/26/2011
  • Status: offline
Advanced Network Printer Script - Multi Office Wednesday, February 01, 2012 4:08 PM (permalink)
0
Hey All,
 
So I have just completed the script I needed.  It's not commented, but i'm sure anyone on here can see where i'm going.  I am a noob at vbs, so i'm probably doing things the hard way.  Without any further ado, the script info:
 
I have 4 offices to provide printer install scripts for.  2 have multiple levels, one single storey, and one VPN connectivity only.  I also have people connecting via USB modems that want to print to our printers too.  So, this script does that.  It grabs firstly the Default Gateway that the person is connecting through, and that determines the 'Case' that is completed.  I utilised various web sources to learn some of the coding on the way, but lost references - so if some of this is your work thanks HEAPS! Script below:
 
 
 Function GetDefaultGateway 
 Dim Adapter, Adapters, WMI 
 GetDefaultGateway = "" 
 Set WMI = GetObject("winmgmts:\\.\root\cimv2") 
 Set Adapters = WMI.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") 
 For Each Adapter In Adapters 
  If Not IsNull(Adapter.DefaultIPGateway) Then 
   If Not Adapter.defaultIPGateway(0) = "0.0.0.0" Then 
    GetDefaultGateway = Adapter.DefaultIPGateway(0) 
    Exit For 
   End If 
  End If 
 Next 
End Function Dim oPrinter 
Set oPrinter = CreateObject("WScript.Network") 
Select Case GetDefaultGateway 
 Case "111.111.111.111" 
 Dim FloorLevelA 
 FloorLevelA = InputBox("Please enter which floor you work on;" & Chr(13) & Chr(13) & "Enter the number 2 if you are on Level 2" & Chr(13)& "Enter the number 3 if you are on Level 3","Office 1 Printer Setup") 
 Select Case FloorLevelA 
  Case "2" 
  oPrinter.AddWindowsPrinterConnection "\\PSERVER1\PRINTER1" 
  oPrinter.AddWindowsPrinterConnection "\\PSERVER1\PRINTER2" 
  oPrinter.AddWindowsPrinterConnection "\\PSERVER1\PRINTER3" 
  oPrinter.AddWindowsPrinterConnection "\\PSERVER1\PRINTER4" 
  oPrinter.AddWindowsPrinterConnection "\\PSERVER1\PRINTER5" 
  oPrinter.SetDefaultPrinter "\\PSERVER1\PRINTER2" 
  MsgBox ("Your printers have been added and your default set to PRINTER2") 
  Case "3" 
  oPrinter.AddWindowsPrinterConnection "\\PSERVER1\PRINTER1" 
  oPrinter.AddWindowsPrinterConnection "\\PSERVER1\PRINTER2" 
  oPrinter.AddWindowsPrinterConnection "\\PSERVER1\PRINTER3" 
  oPrinter.AddWindowsPrinterConnection "\\PSERVER1\PRINTER4" 
  oPrinter.AddWindowsPrinterConnection "\\PSERVER1\PRINTER5" 
  oPrinter.SetDefaultPrinter "\\PSERVER1\PRINTER5" 
  MsgBox ("Your printers have been added and your default set to PRINTER5") 
 End Select 
 Case "112.112.112.112" 
 oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER1" 
 oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER2" 
 oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER3" 
 oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER4" 
 oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER5" 
 oPrinter.SetDefaultPrinter "\\PSERVER2\PRINTER1" 
 MsgBox ("Your printers have been added and your default set to PRINTER1") 
 Case "113.113.113.113" 
 Dim FloorLevelB 
 FloorLevelB = InputBox("Please enter which floor you work on;" & Chr(13) & Chr(13) & "Enter the letter G if you are on the ground floor" & Chr(13)& "Enter the number 1 if you are on Level 1","Office 2 Printer Setup") 
 Select Case FloorLevelB 
  Case "G" 
  oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER1" 
  oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER2" 
  oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER3" 
  oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER4" 
  oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER5" 
  oPrinter.SetDefaultPrinter "\\PSERVER2\PRINTER4" 
  MsgBox ("Your printers have been added and your default set to PRINTER4") 
  Case "1" 
  oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER1" 
  oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER2" 
  oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER3" 
  oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER4" 
  oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER5" 
  oPrinter.SetDefaultPrinter "\\PSERVER2\PRINTER5" 
  MsgBox ("Your printers have been added and your default set to PRINTER5") 
 End Select 
' VPN Office 
 Case "192.168.0.1" 
  MsgBox ("You are not currently connected to the VPN client - Please connect up to the Cisco AnyConnect VPN client and try again") 
 Case "222.222.222.222" 
  Dim VPNmsg 
  VPNmsg = MsgBox ("Are you in the VPN Office at Office 3? Select no if you are using a USB Modem.", _ 
  vbYesNo + vbQuestion, _ 
  "VPN Connection Printer Setup") 
  Select Case VPNmsg 
   Case vbYes 
   Set WSHNetwork = WScript.CreateObject("WScript.Network") 
   Set shell = WScript.CreateObject( "WScript.Shell" ) 
   CompName = shell.ExpandEnvironmentStrings("%COMPUTERNAME%") 
   Set objWMIService = GetObject("winmgmts:\\" & CompName & "\root\cimv2") 
   Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_ 
   Set oShell = WScript.CreateObject("WScript.shell") 
   Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_ 
   Sub createPort (name, ip) 
    objNewPort.Name = name 
    objNewPort.Protocol = 1 
    objNewPort.HostAddress = ip 
    objNewPort.SNMPEnabled = False 
    objNewPort.Put_ 
   End Sub 
   Sub addPrinter (driver, port, name) 
    objPrinter.DriverName = driver 
    objPrinter.PortName = port 
    objPrinter.DeviceID = name 
    objPrinter.Network = True 
    objPrinter.Shared = False 
    objPrinter.ShareName = "" 
    objPrinter.Put_ 
   End Sub 
   createPort "PRINTER1_IP", "192.168.0.250" 
   oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""Office 3""    /f \\server1\software$\drivers\mpc5501a\oemsetup.inf   /r ""PRINTER1_IP"" /m ""PCL6 Driver for Universal Print"""  ,,True 
   oPrinter.SetDefaultPrinter "Office 3" 
   MsgBox ("Your printer (Office 3) has been added and set as your default printer") 
   Case vbNo 
   Dim OfficeRoam 
   OfficeRoam = InputBox("Please select which office to print to and the click OK;" & Chr(13) & Chr(13) & "Enter the number 1 if you wish to print to Office 1 Level 2" & Chr(13)& "Enter the number 2 if you wish to print to Office 1 Level 3" & Chr(13)& "Enter the number 3 if you wish to print to Office 2 level 1" & Chr(13)& "Enter the number 4 if you wish to print to Office 4 (Mainland Office)" & Chr(13) & Chr(13)& "*Note 1* Printing to Office 3 is not available whilst roaming" & Chr(13)& "*Note 2* This process will take around 10 minutes and download 15mb of data","VPN Roaming Printer Setup - All Offices") 
   Select Case OfficeRoam 
    Case "1" 
     Set WSHNetwork = WScript.CreateObject("WScript.Network") 
     Set shell = WScript.CreateObject( "WScript.Shell" ) 
     CompName = shell.ExpandEnvironmentStrings("%COMPUTERNAME%") 
     Set objWMIService = GetObject("winmgmts:\\" & CompName & "\root\cimv2") 
     Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_ 
     Set oShell = WScript.CreateObject("WScript.shell") 
     Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_ 
     Sub createPort (name, ip) 
      objNewPort.Name = name 
      objNewPort.Protocol = 1 
      objNewPort.HostAddress = ip 
      objNewPort.SNMPEnabled = False 
      objNewPort.Put_ 
     End Sub 
     Sub addPrinter (driver, port, name) 
      objPrinter.DriverName = driver 
      objPrinter.PortName = port 
      objPrinter.DeviceID = name 
      objPrinter.Network = True 
      objPrinter.Shared = False 
      objPrinter.ShareName = "" 
      objPrinter.Put_ 
     End Sub 
     createPort "PRINTER2_IP", "111.111.111.250" 
     oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""PRINTER2 IP Print""    /f \\server1\software$\drivers\mpc5501a\oemsetup.inf   /r ""PRINTER2_IP"" /m ""PCL6 Driver for Universal Print"""  ,,True 
     MsgBox ("PRINTER2 IP Print has been added to your printer list") 
    Case "2" 
     Set WSHNetwork = WScript.CreateObject("WScript.Network") 
     Set shell = WScript.CreateObject( "WScript.Shell" ) 
     CompName = shell.ExpandEnvironmentStrings("%COMPUTERNAME%") 
     Set objWMIService = GetObject("winmgmts:\\" & CompName & "\root\cimv2") 
     Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_ 
     Set oShell = WScript.CreateObject("WScript.shell") 
     Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_ 
     Sub createPort (name, ip) 
      objNewPort.Name = name 
      objNewPort.Protocol = 1 
      objNewPort.HostAddress = ip 
      objNewPort.SNMPEnabled = False 
      objNewPort.Put_ 
     End Sub 
     Sub addPrinter (driver, port, name) 
      objPrinter.DriverName = driver 
      objPrinter.PortName = port 
      objPrinter.DeviceID = name 
      objPrinter.Network = True 
      objPrinter.Shared = False 
      objPrinter.ShareName = "" 
      objPrinter.Put_ 
     End Sub 
     createPort "PRINTER5_IP", "111.111.111.249" 
     oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""PRINTER5 IP Print""    /f \\server1\software$\drivers\mpc5501a\oemsetup.inf   /r ""PRINTER5_IP"" /m ""PCL6 Driver for Universal Print"""  ,,True 
     MsgBox ("PRINTER5 Ip Print has been added to your printer list")     
    Case "3" 
     Set WSHNetwork = WScript.CreateObject("WScript.Network") 
     Set shell = WScript.CreateObject( "WScript.Shell" ) 
     CompName = shell.ExpandEnvironmentStrings("%COMPUTERNAME%") 
     Set objWMIService = GetObject("winmgmts:\\" & CompName & "\root\cimv2") 
     Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_ 
     Set oShell = WScript.CreateObject("WScript.shell") 
     Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_ 
     Sub createPort (name, ip) 
      objNewPort.Name = name 
      objNewPort.Protocol = 1 
      objNewPort.HostAddress = ip 
      objNewPort.SNMPEnabled = False 
      objNewPort.Put_ 
     End Sub 
     Sub addPrinter (driver, port, name) 
      objPrinter.DriverName = driver 
      objPrinter.PortName = port 
      objPrinter.DeviceID = name 
      objPrinter.Network = True 
      objPrinter.Shared = False 
      objPrinter.ShareName = "" 
      objPrinter.Put_ 
     End Sub 
     createPort "PRINTER5_IP", "112.112.112.250" 
     oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""PRINTER5 IP Print""    /f \\server1\software$\drivers\mpc5501a\oemsetup.inf   /r ""PRINTER5_IP"" /m ""PCL6 Driver for Universal Print"""  ,,True 
     MsgBox ("PRINTER5 IP Print has been added to your printer list")  
    Case "4" 
     Set WSHNetwork = WScript.CreateObject("WScript.Network") 
     Set shell = WScript.CreateObject( "WScript.Shell" ) 
     CompName = shell.ExpandEnvironmentStrings("%COMPUTERNAME%") 
     Set objWMIService = GetObject("winmgmts:\\" & CompName & "\root\cimv2") 
     Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_ 
     Set oShell = WScript.CreateObject("WScript.shell") 
     Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_ 
     Sub createPort (name, ip) 
      objNewPort.Name = name 
      objNewPort.Protocol = 1 
      objNewPort.HostAddress = ip 
      objNewPort.SNMPEnabled = False 
      objNewPort.Put_ 
     End Sub 
     Sub addPrinter (driver, port, name) 
      objPrinter.DriverName = driver 
      objPrinter.PortName = port 
      objPrinter.DeviceID = name 
      objPrinter.Network = True 
      objPrinter.Shared = False 
      objPrinter.ShareName = "" 
      objPrinter.Put_ 
     End Sub 
     createPort "PRINTER1_IP", "113.113.113.250" 
     oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""PRINTER1 IP Print""    /f \\server1\software$\drivers\mpc5501a\oemsetup.inf   /r ""PRINTER1_IP"" /m ""PCL6 Driver for Universal Print"""  ,,True 
     MsgBox ("PRINTER1 IP Print has been added to your printer list")      
   End Select 
  End Select 
 Case Else 
 MsgBox ("You are not connected to the Cisco AnyConnect VPN Client or not in an Project office.  Please connect up the Cisco AnyConnect VPN Client and run this again, or contact your local support personal for further assistance") 
End Select 

<message edited by rekrapg on Wednesday, February 01, 2012 4:11 PM>
 
#1
    rekrapg

    • Total Posts : 4
    • Scores: 0
    • Reward points : 0
    • Joined: 10/26/2011
    • Status: offline
    Re:Advanced Network Printer Script - Multi Office Sunday, February 05, 2012 10:39 AM (permalink)
    0
    Take 2 - added some Do loops and commented a bit on the code (not much)
     
      'Create the Function To determine And store current default gateway
    '
    Function GetDefaultGateway  
     Dim Adapter, Adapters, WMI  
     GetDefaultGateway = ""  
     Set WMI = GetObject("winmgmts:\\.\root\cimv2")  
     Set Adapters = WMI.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")  
     For Each Adapter In Adapters  
      If Not IsNull(Adapter.DefaultIPGateway) Then  
       If Not Adapter.defaultIPGateway(0) = "0.0.0.0" Then  
        GetDefaultGateway = Adapter.DefaultIPGateway(0)  
        Exit For  
       End If  
      End If  
     Next  
    End Function 
    'start case for determining which office end user is in
    '
    Dim oPrinter 'to be used throughout script for printer addition
    Set oPrinter = CreateObject("WScript.Network")
    Select Case GetDefaultGateway  
     Case "111.111.111.111" 'default gateway ip of office 1 (multi floor office #1)
     Dim FloorLevelA
     Do 'added do loop so end user will always know whats wrong if incorrect input
     FloorLevelA = InputBox("Choose your floor level" & Chr(13) & "Please enter one of the below options;" & Chr(13) & Chr(13) & "1 = Level 2" & Chr(13)& "2 = Level 3","Office 1 Printer Setup")
     If VarType(FloorLevelA) = 0 Then
      MsgBox "You have cancelled the printer installation utility", 64, "Install Cancelled"
      Exit Do
     Else
     Select Case FloorLevelA  
      Case "1"  
      oPrinter.AddWindowsPrinterConnection "\\PSERVER1\PRINTER1"  
      oPrinter.AddWindowsPrinterConnection "\\PSERVER1\PRINTER2"  
      oPrinter.AddWindowsPrinterConnection "\\PSERVER1\PRINTER3"  
      oPrinter.AddWindowsPrinterConnection "\\PSERVER1\PRINTER4"  
      oPrinter.AddWindowsPrinterConnection "\\PSERVER1\PRINTER5"  
      oPrinter.SetDefaultPrinter "\\PSERVER1\PRINTER1"  
      MsgBox "Your printers have been added and your default set to PRINTER1", 64, "Printer Installation Completed"
      Exit Do 
      Case "2"  
      oPrinter.AddWindowsPrinterConnection "\\PSERVER1\PRINTER1"  
      oPrinter.AddWindowsPrinterConnection "\\PSERVER1\PRINTER2"  
      oPrinter.AddWindowsPrinterConnection "\\PSERVER1\PRINTER3"  
      oPrinter.AddWindowsPrinterConnection "\\PSERVER1\PRINTER4"  
      oPrinter.AddWindowsPrinterConnection "\\PSERVER1\PRINTER5"  
      oPrinter.SetDefaultPrinter "\\PSERVER1\PRINTER5"  
      MsgBox "Your printers have been added and your default set to PRINTER5", 64, "Printer Installation Completed"
      Exit Do
      Case Else
      MsgBox "Error: Incorrect entry.  Please try again", 16, "Unavailable Selection" 'typed incorrect number choice, start do loop again
     End Select
     End If
     Loop
     Case "112.112.112.112" 'default gateway ip of office 2 
     oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER1"  
     oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER2"  
     oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER3"  
     oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER4"  
     oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER5"  
     oPrinter.SetDefaultPrinter "\\PSERVER2\PRINTER1"  
     MsgBox "Your printers have been added and your default set to PRINTER1", 64, "Printer Installation Completed"  
     Case "113.113.113.113" 'default gateway office 3 (multi floor office #2)
     Dim FloorLevelB
     Do
     FloorLevelB = InputBox("Choose your floor level" & Chr(13) & "Please enter one of the below options;" & Chr(13) & Chr(13) & "1 = Ground floor" & Chr(13)& "2 = Level 1","Office 3 Printer Setup")
     If VarType(FloorLevelB) = 0 Then
      MsgBox "You have cancelled the printer installation utility", 64, "Install Cancelled"
      Exit Do
     Else
     Select Case FloorLevelB  
      Case "1"  
      oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER1"  
      oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER2"  
      oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER3"  
      oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER4"  
      oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER5"  
      oPrinter.SetDefaultPrinter "\\PSERVER2\PRINTER4"  
      MsgBox "Your printers have been added and your default set to PRINTER4", 64, "Printer Installation Completed"
      Exit Do
      Case "2"  
      oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER1"  
      oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER2"  
      oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER3"  
      oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER4"  
      oPrinter.AddWindowsPrinterConnection "\\PSERVER2\PRINTER5"  
      oPrinter.SetDefaultPrinter "\\PSERVER2\PRINTER5"  
      MsgBox "Your printers have been added and your default set to PRINTER5", 64, "Printer Installation Completed"
      Exit Do
      Case Else
      MsgBox "Error: Incorrect entry.  Please try again", 16, "Unavailable Selection"
     End Select
     End If
     Loop 
     End Select  
     ' VPN Office  
     Case "192.168.0.1" 'this is the VPN only office - default gateway if not actually connected via VPN
     MsgBox "You are not currently connected to the VPN client - Please connect up to the Cisco AnyConnect VPN client and try again", 16, "VPN Not Connected"
     Case "222.222.222.222" 'connected via VPN.  determines that either client in the VPN only office, or roaming
     Dim VPNmsg  
     VPNmsg = MsgBox ("Are you in the VPN Office at Office 4?" & Chr(13) &  Chr(13) & "Select 'No' if you are using a USB Modem.", _ 'vbYesNo for user choice - Yes, I am in VPN office, or No, I am roaming
     vbYesNo + vbQuestion, _  
     "VPN Connection Printer Setup")  
     Select Case VPNmsg  
      Case vbYes 'if yes, add direct IP print for the local printer that's tunneled in the VPN program
      Set WSHNetwork = WScript.CreateObject("WScript.Network")  
      Set shell = WScript.CreateObject( "WScript.Shell" )  
      CompName = shell.ExpandEnvironmentStrings("%COMPUTERNAME%")  
      Set objWMIService = GetObject("winmgmts:\\" & CompName & "\root\cimv2")  
      Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_  
      Set oShell = WScript.CreateObject("WScript.shell")  
      Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_  
      Sub createPort (name, ip)  
       objNewPort.Name = name  
       objNewPort.Protocol = 1  
       objNewPort.HostAddress = ip  
       objNewPort.SNMPEnabled = False  
       objNewPort.Put_  
      End Sub  
      Sub addPrinter (driver, port, name)  
       objPrinter.DriverName = driver  
       objPrinter.PortName = port  
       objPrinter.DeviceID = name  
       objPrinter.Network = True  
       objPrinter.Shared = False  
       objPrinter.ShareName = ""  
       objPrinter.Put_  
      End Sub  
      createPort "PRINTER1_IP", "192.168.0.250"  
      oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""Office 4""    /f \\server1\software$\drivers\mpc5501a\oemsetup.inf   /r ""PRINTER1_IP"" /m ""PCL6 Driver for Universal Print"""  ,,True  
      oPrinter.SetDefaultPrinter "Office 4"  
      MsgBox "Your printer (Office 4) has been added and set as your default printer", 64, "Printer Installation Completed"
      Case vbNo 'no is selected, client is roaming. so give client choice of main printer in each office to be installed as direct ip printing
      Dim OfficeRoam  
      OfficeRoam = InputBox("Please select which office to print to and the click OK;" & Chr(13) & Chr(13) & "1 = Office 1 Level 2" & Chr(13)& "2 = Office 1 Level 3" & Chr(13)& "3 = Office 2 level 1" & Chr(13)& "4 = Office 3" & Chr(13) & Chr(13)& "*Note 1* Printing to Office 4 is not available whilst roaming" & Chr(13)& "*Note 2* This process will take around 10 minutes and download 15mb of data","VPN Roaming Printer Setup - All Offices")  
      Select Case OfficeRoam  
       Case "1"
       Set WSHNetwork = WScript.CreateObject("WScript.Network")  
       Set shell = WScript.CreateObject( "WScript.Shell" )  
       CompName = shell.ExpandEnvironmentStrings("%COMPUTERNAME%")  
       Set objWMIService = GetObject("winmgmts:\\" & CompName & "\root\cimv2")  
       Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_  
       Set oShell = WScript.CreateObject("WScript.shell")  
       Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_  
       Sub createPort (name, ip)  
        objNewPort.Name = name  
        objNewPort.Protocol = 1  
        objNewPort.HostAddress = ip  
        objNewPort.SNMPEnabled = False  
        objNewPort.Put_  
       End Sub  
       Sub addPrinter (driver, port, name)  
        objPrinter.DriverName = driver  
        objPrinter.PortName = port  
        objPrinter.DeviceID = name  
        objPrinter.Network = True  
        objPrinter.Shared = False  
        objPrinter.ShareName = ""  
        objPrinter.Put_  
       End Sub  
       createPort "PRINTER2_IP", "111.111.111.250"  
       oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""PRINTER2 IP Print""    /f \\server1\software$\drivers\mpc5501a\oemsetup.inf   /r ""PRINTER2_IP"" /m ""PCL6 Driver for Universal Print"""  ,,True  
       MsgBox "PRINTER2 IP Print has been added to your printer list", 64, "Printer Installation Completed"
       Case "2"  
       Set WSHNetwork = WScript.CreateObject("WScript.Network")  
       Set shell = WScript.CreateObject( "WScript.Shell" )  
       CompName = shell.ExpandEnvironmentStrings("%COMPUTERNAME%")  
       Set objWMIService = GetObject("winmgmts:\\" & CompName & "\root\cimv2")  
       Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_  
       Set oShell = WScript.CreateObject("WScript.shell")  
       Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_  
       Sub createPort (name, ip)  
        objNewPort.Name = name  
        objNewPort.Protocol = 1  
        objNewPort.HostAddress = ip  
        objNewPort.SNMPEnabled = False  
        objNewPort.Put_  
       End Sub  
       Sub addPrinter (driver, port, name)  
        objPrinter.DriverName = driver  
        objPrinter.PortName = port  
        objPrinter.DeviceID = name  
        objPrinter.Network = True  
        objPrinter.Shared = False  
        objPrinter.ShareName = ""  
        objPrinter.Put_  
       End Sub  
       createPort "PRINTER5_IP", "111.111.111.249"  
       oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""PRINTER5 IP Print""    /f \\server1\software$\drivers\mpc5501a\oemsetup.inf   /r ""PRINTER5_IP"" /m ""PCL6 Driver for Universal Print"""  ,,True  
       MsgBox "PRINTER5 Ip Print has been added to your printer list", 64, "Printer Installation Completed"
       Case "3"  
       Set WSHNetwork = WScript.CreateObject("WScript.Network")  
       Set shell = WScript.CreateObject( "WScript.Shell" )  
       CompName = shell.ExpandEnvironmentStrings("%COMPUTERNAME%")  
       Set objWMIService = GetObject("winmgmts:\\" & CompName & "\root\cimv2")  
       Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_  
       Set oShell = WScript.CreateObject("WScript.shell")  
       Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_  
       Sub createPort (name, ip)  
        objNewPort.Name = name  
        objNewPort.Protocol = 1  
        objNewPort.HostAddress = ip  
        objNewPort.SNMPEnabled = False  
        objNewPort.Put_  
       End Sub  
       Sub addPrinter (driver, port, name)  
        objPrinter.DriverName = driver  
        objPrinter.PortName = port  
        objPrinter.DeviceID = name  
        objPrinter.Network = True  
        objPrinter.Shared = False  
        objPrinter.ShareName = ""  
        objPrinter.Put_  
       End Sub  
       createPort "PRINTER5_IP", "112.112.112.250"  
       oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""PRINTER5 IP Print""    /f \\server1\software$\drivers\mpc5501a\oemsetup.inf   /r ""PRINTER5_IP"" /m ""PCL6 Driver for Universal Print"""  ,,True  
       MsgBox "PRINTER5 IP Print has been added to your printer list", 64, "Printer Installation Completed"
       Case "4"  
       Set WSHNetwork = WScript.CreateObject("WScript.Network")  
       Set shell = WScript.CreateObject( "WScript.Shell" )  
       CompName = shell.ExpandEnvironmentStrings("%COMPUTERNAME%")  
       Set objWMIService = GetObject("winmgmts:\\" & CompName & "\root\cimv2")  
       Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_  
       Set oShell = WScript.CreateObject("WScript.shell")  
       Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_  
       Sub createPort (name, ip)  
        objNewPort.Name = name  
        objNewPort.Protocol = 1  
        objNewPort.HostAddress = ip  
        objNewPort.SNMPEnabled = False  
        objNewPort.Put_  
       End Sub  
       Sub addPrinter (driver, port, name)  
        objPrinter.DriverName = driver  
        objPrinter.PortName = port  
        objPrinter.DeviceID = name  
        objPrinter.Network = True  
        objPrinter.Shared = False  
        objPrinter.ShareName = ""  
        objPrinter.Put_  
       End Sub  
       createPort "PRINTER1_IP", "113.113.113.250"  
       oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""PRINTER1 IP Print""    /f \\server1\software$\drivers\mpc5501a\oemsetup.inf   /r ""PRINTER1_IP"" /m ""PCL6 Driver for Universal Print"""  ,,True  
       MsgBox "PRINTER1 IP Print has been added to your printer list", 64, "Printer Installation Completed"
      Case Else
       MsgBox "Error: Incorrect entry.  Please try again", 16, "Unavailable Selection"
      End Select
     End Select  
     Case Else  
     MsgBox "You are not connected to the Cisco AnyConnect VPN Client or not in an Project office." & Chr(13) &  Chr(13) & "Option 1: Connect up the Cisco AnyConnect VPN Client (Perth) and run this again" & Chr(13) & Chr(13) & "Option 2: Contact your local support personal for further assistance", 48, "No MyBusiness Network Detected"
    End Select 

     
    #2

      Online Bookmarks Sharing: Share/Bookmark

      Jump to:

      Current active users

      There are 0 members and 1 guests.

      Icon Legend and Permission

      • New Messages
      • No New Messages
      • Hot Topic w/ New Messages
      • Hot Topic w/o New Messages
      • Locked w/ New Messages
      • Locked w/o New Messages
      • Read Message
      • Post New Thread
      • Reply to message
      • Post New Poll
      • Submit Vote
      • Post reward post
      • Delete my own posts
      • Delete my own threads
      • Rate post

      2000-2012 ASPPlayground.NET Forum Version 3.9