VBS GPO Logon Script Not Executing Properly

Home Forums Scripting Windows Script Host VBS GPO Logon Script Not Executing Properly

Viewing 1 post (of 1 total)
  • Author
    Posts

  • nelks
    Member
    #151787

    Hello. I have been having an issue that I am hoping someone can help me with. I wrote two scripts, one for logon and one for logoff, to create and remove a virtual dummy printer for users. I am posting this in the AD section as these scripts work perfectly when launched as the user on an XP based workstation. However, when launched via GPO the scripts run, but nothing happens. I have confimed they are running, because I added in echo statements as a test and all expected message boxes popped up. However, the printer does not actually get created or removed. I even tried creating a batch file that called each vbs script via wscript. If anyone can offer any insight as to why this may be occurring, it would be greatly appreciated. Again, when launched manually by double-clicking on the machine in question, each script works flawlessly. Only when launched via GPO do they run but do not perform the expected actions. I have included a copy of the scripts below.

    #1 Logon Script. Creates a port, printer and sets default printer.

    On Error Resume Next

    Dim objNetwork,objWMIService,objNewPort,oShell,objPrinter
    Set shell = WScript.CreateObject( “WScript.Shell” )
    CompName = shell.ExpandEnvironmentStrings(“%COMPUTERNAME%”)
    Set WSHNetwork = WScript.CreateObject(“WScript.Network”)
    Set objWMIService = GetObject(“winmgmts:\” & CompName & “rootcimv2”)
    Set objNewPort = objWMIService.Get(“Win32_TCPIPPrinterPort”).SpawnInstance_
    Set oShell = WScript.CreateObject(“WScript.shell”)
    Set objPrinter = objWMIService.Get(“Win32_Printer”).SpawnInstance_
    Set objNetwork = createobject(“Wscript.Network”)

    ‘———————————————-
    ‘Add Printer Port (port name and ip address)
    ‘———————————————-
    createPort “Virtual Printer”, “127.0.0.1”

    ‘———————————————-
    ‘ Add Printer (printer driver, port name and printer name)
    ‘———————————————-
    addPrinter “HP Laserjet 5″,”Virtual Printer”,”Training Room Virtual Printer”
    ‘MsgBox (“Printer installation complete”)
    objNetwork.SetDefaultPrinter “Virtual Printer”

    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.Location = “Training Room”
    objPrinter.Network = True
    objPrinter.Shared = False
    objPrinter.ShareName = “”
    objPrinter.Put_
    end Sub

    WScript.Quit
    [/CODE]
    #2 Clear all print jobs, remove printer[CODE]

    On Error Resume Next

    Dim objWMIService,strArgument

    Set objWMIService = GetObject(“winmgmts:{impersonationLevel=impersonate}!\.rootcimv2”)
    Set colInstalledPrinters = objWMIService.ExecQuery (“Select * from Win32_Printer”)

    For Each objPrinter in colInstalledPrinters
    objPrinter.CancelAllJobs()
    Next

    Set objShell = CreateObject(“Wscript.Shell”)
    strArgument = “c:windowssystem32rundll32.exe printui.dll,PrintUIEntry /dl /n ” & chr(34) & “Training Room Virtual Printer” & chr(34)
    objShell.Run strArgument

    WScript.Quit
    [/CODE][CODE]

    On Error Resume Next

    Dim objNetwork,objWMIService,objNewPort,oShell,objPrinter
    Set shell = WScript.CreateObject( “WScript.Shell” )
    CompName = shell.ExpandEnvironmentStrings(“%COMPUTERNAME%”)
    Set WSHNetwork = WScript.CreateObject(“WScript.Network”)
    Set objWMIService = GetObject(“winmgmts:\” & CompName & “rootcimv2”)
    Set objNewPort = objWMIService.Get(“Win32_TCPIPPrinterPort”).SpawnInstance_
    Set oShell = WScript.CreateObject(“WScript.shell”)
    Set objPrinter = objWMIService.Get(“Win32_Printer”).SpawnInstance_
    Set objNetwork = createobject(“Wscript.Network”)


    ‘Add Printer Port (port name and ip address)


    createPort “Virtual Printer”, “127.0.0.1”


    ‘ Add Printer (printer driver, port name and printer name)


    addPrinter “HP Laserjet 5″,”Virtual Printer”,”Training Room Virtual Printer”
    ‘MsgBox (“Printer installation complete”)
    objNetwork.SetDefaultPrinter “Virtual Printer”

    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.Location = “Training Room”
    objPrinter.Network = True
    objPrinter.Shared = False
    objPrinter.ShareName = “”
    objPrinter.Put_
    end Sub

    WScript.Quit
    [/CODE]
    #2 Clear all print jobs, remove printer

    On Error Resume Next

    Dim objWMIService,strArgument

    Set objWMIService = GetObject(“winmgmts:{impersonationLevel=impersonate}!\.rootcimv2”)
    Set colInstalledPrinters = objWMIService.ExecQuery (“Select * from Win32_Printer”)

    For Each objPrinter in colInstalledPrinters
    objPrinter.CancelAllJobs()
    Next

    Set objShell = CreateObject(“Wscript.Shell”)
    strArgument = “c:windowssystem32rundll32.exe printui.dll,PrintUIEntry /dl /n ” & chr(34) & “Training Room Virtual Printer” & chr(34)
    objShell.Run strArgument

    WScript.Quit
    [/CODE][CODE]

    On Error Resume Next

    Dim objWMIService,strArgument

    Set objWMIService = GetObject(“winmgmts:{impersonationLevel=impersonate}!\.rootcimv2”)
    Set colInstalledPrinters = objWMIService.ExecQuery (“Select * from Win32_Printer”)

    For Each objPrinter in colInstalledPrinters
    objPrinter.CancelAllJobs()
    Next

    Set objShell = CreateObject(“Wscript.Shell”)
    strArgument = “c:windowssystem32rundll32.exe printui.dll,PrintUIEntry /dl /n ” & chr(34) & “Training Room Virtual Printer” & chr(34)
    objShell.Run strArgument

    WScript.Quit
    [/CODE]

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

External Sharing and Guest User Access in Microsoft 365 and Teams

This eBook will dive into policy considerations you need to make when creating and managing guest user access to your Teams network, as well as the different layers of guest access and the common challenges that accompany a more complicated Microsoft 365 infrastructure.

You will learn:

  • Who should be allowed to be invited as a guest?
  • What type of guests should be able to access files in SharePoint and OneDrive?
  • How should guests be offboarded?
  • How should you determine who has access to sensitive information in your environment?

Sponsored by:

 
Office 365 Coexistence for Mergers & Acquisitions: Don’t Panic! Make it SimpleLive Webinar on Tuesday, November 16, 2021 @ 1 pm ET

In this session, Microsoft MVPs Steve Goodman and Mike Weaver, and tenant migration expert Rich Dean, will cover the four most common steps toward Office 365 coexistence and explain the simplest route to project success.

  • Directory Sync/GAL Sync – How to prepare for access and awareness
  • Calendar Sharing – How to retrieve a user’s shared calendar, or a room’s free time
  • Email Routing – How to guarantee email is routed to the active mailbox before and after migration
  • Domain Sharing – How to accommodate both original and new SMTP domains at every stage

Aimed at IT Admins, Infrastructure Engineers and Project Managers, this session outlines both technical and project management considerations – giving you a great head start when faced with a tenant migration.the different layers of guest access and the common challenges that accompany a more complicated Microsoft 365 infrastructure.

Sponsored by: