Announcement

Collapse
No announcement yet.

Running a Batch File from Group Policy

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Running a Batch File from Group Policy

    Hi, I do not have a great deal of experience with GPO so I am hoping someone can assist it would be appreciated.

    The policy was set to both Users and computers and set to the container for the Zero clients and domain users, domain computers and added into both the logon script and the startup script. Trying both the policy location on the DC and the Netlogon directory with no success as outlined below.

    We have a Zero Client fleet that is spread over multiple rooms. These rooms have different printers. In order to combat the same image being used with different printers I wrote a batch file as follows:

    (NOTE: O:\ is mapped to FNP server through the logon script)

    @Echo off
    cls
    set Found=0
    Echo.
    Echo.
    Echo Please Wait...Adding Printer
    Echo.
    Echo Starting load >> c:\Locate.txt
    For /F %%R in (o:\ZeroPrint\Rooms.txt) Do (
    Echo Searching %%R >> c:\Locate.txt
    For /F %%M in (o:\ZeroPrint\%%R.txt) Do (
    IF %%M==%ViewClient_MAC_Address% (
    Echo Found %%M in %%R >> c:\Locate.txt
    Set Room=%%R
    Goto Found
    )
    )
    )
    Goto NoFind

    :Found
    If %Room%==N320 (
    rundll32 printui.dll,PrintUIEntry /q /in /n "\\fnp\N320-NDPS"
    rundll32 printui.dll,PrintUIEntry /y /q /n\\fnp\N320-NDPS
    Goto End
    )

    If %Room%==N321 (
    REM rundll32 printui.dll,PrintUIEntry /q /in /n "\\fnp\N321-NDPS"
    REM rundll32 printui.dll,PrintUIEntry /y /q /n\\fnp\N321-NDPS
    Goto End
    )

    If %Room%==Test (
    rundll32 printui.dll,PrintUIEntry /q /in /n "\\fnp\Test-NDPS"
    rundll32 printui.dll,PrintUIEntry /y /q /n\\fnp\Test-NDPS
    Goto End
    )

    Goto End

    :NoFind
    Echo.
    Echo This Machines MAC address was not found.
    Echo.
    Echo Please Contact IT.
    Echo.
    Pause
    Echo Could Not Find this PC >> C:\Locate.txt
    Goto End

    :End
    Echo Completed >> c:\Locate.txt
    Exit

    The Echo >> C:\Locate.txt file was created as no output went to the screen.

    Here is the issue. The Locate.txt file contains only the following line:
    Starting load

    When I run it from the machine it contains the following:

    Starting load
    Searching N320
    Searching N321
    Searching Test
    Found C0-41-F6-72-A1-FB in Test
    Completed

    And the printer is loaded and set to default.

    Why does the batch simply stop running at the FOR loop? I have tried placing it on the DC in the Policy path, in the netlogon path and have even placed it in the C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup location to force it to run with the same result.

    The text files contain the room names and the room names.txt contain the MAC address of the machines in the rooms as shown below:

    Room.txt:
    N320
    N321
    Test

    N320:
    CC-2D-8C-80-3E-72
    CC-2D-8C-80-3E-73
    CC-2D-8C-80-3E-74
    CC-2D-8C-80-3E-75
    CC-2D-8C-80-3E-76

    N321:
    CC-2D-8C-80-3E-80
    CC-2D-8C-80-3E-81
    CC-2D-8C-80-3E-82
    CC-2D-8C-80-3E-83
    CC-2D-8C-80-3E-84

    Test:
    CC-2D-8C-80-3E-90
Working...
X