Creating a policy that runs a .bat file on loging in from a network share

Posted on 2011-10-03
Last Modified: 2012-05-12
I would like to run a .bat file from a DFS drive that runs every time a user logs in a Pc on the network,
The file is on a server called file2 which is shared as everybody’s Y drive. I thought I can run this through a system policy and would like help with the correct syntax please.
Drive as said is the y drive on all users Pc and is as follows Y: \\FILE2\FIle2 DFS
and the bat file I want to run is below

 @echo off
if exist %systemdrive%\policy\it_policy1.szp goto end
if not exist %systemdrive%\policy\ goto next
mkdir %systemdrive%\policy
net use y: /d
net use y: \\file2\file2 DNS
copy y:\it_policy1.szp %systemdrive%\policy
Regedit /s y:\it_policy1.reg
net use y: /delete goto end

Would this work or am I totally wrong?
Question by:dances1960

    Author Comment

    Or since the Y drive already exists do I need this at all?
    LVL 41

    Accepted Solution

    No need to map the Y drive. You can use UNC paths instead. Group POlicy Preferences is preferred over regedit, especially when running on Vista/7/Windows 2008/R2 because of UAC. Group Policy Preferences can even copy over your file, so you don't actually need a script at all.

    Group Policy Preferences
    LVL 66

    Assisted Solution

    There is a policy specifically for this....

    Run these programs at user logon

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    The problems with reply email signatures

    Do you wish that you could place an email signature under a reply? Well, unfortunately, you can't. That great Exchange/Office 365 signature you've created will just appear at the bottom of an email chain. What a pain! Is there really no way to solve this? Well, there might be...

    You might have come across a situation when you have Exchange 2013 server in two different sites (Production and DR). After adding the Database copy in ECP console it displays Database copy status unknown for the DR exchange server. Issue is strange…
    If your business is like most, chances are you still need to maintain a fax infrastructure for your staff. It’s hard to believe that a communication technology that was thriving in the mid-80s could still be an essential part of your team’s modern I…
    This tutorial will show how to inventory, catalog, and restore media from legacy versions of Backup Exec into both 2012 and 2014 versions of the software. Select Storage from the tabs along the ribbon bar as the top: Ensure the proper storage devi…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now