locked
Batch file to copy file not working RRS feed

  • Question

  • I have a host file I need to copy to all my workstations. I have a scrip that which is below. I have the host file in a share that everyone can access and I also put the batch file in that share. I created a Group Policy startup script and pointed the location to \\US-data\it$\private\hostfile\hostsfile.bat but when I reboot my machine, the reg key gets applied but it does not copy the host file.


    I know the batch file works as if I run it locally on my workstation, it copies the host file to my local machine and it creates the regkey. So why is it not working.

    ---------------------------------------------------------------------------------------------------------------------------------------------------

    :keyverify
    reg query HKEY_LOCAL_MACHINE\SOFTWARE\esahostfile
    if %errorlevel%==1 (goto copyhost) else (goto End)

    :copyhost
    xcopy /Y \\US-data\it$\private\hostfile\hosts %systemroot%\System32\drivers\etc\hosts

    reg add HKEY_LOCAL_MACHINE\SOFTWARE\esahostfile

    :End

    ---------------------------------------------------------------------------------------------------------------------------------------------------

     

    Thursday, April 11, 2013 11:54 AM

Answers

All replies

  • Hello,

    Forget your script and use Group Policy Preferences Files for this.
    Add the group "Domain Computers" to the NTFS and Share permissions.

    Also enable this policy:

    http://gpsearch.azurewebsites.net/#1839


    MVP Group Policy - Mythen, Insiderinfos und Troubleshooting zum Thema GPOs: Let's go, use GPO!

    • Proposed as answer by Joseph__Moody Thursday, April 11, 2013 12:27 PM
    • Marked as answer by Vivian_Wang Monday, April 15, 2013 9:09 AM
    Thursday, April 11, 2013 12:18 PM
  • It sounds like your share doesn't have the correct permissions. I would bet your domain computers do not have read/execute on the share/folder for \\US-data\it$

    I would recommend preferences as well. Much easier to manage!


    If my answer helped you, check out my blog (and subscribe): DeployHappiness.com

    Thursday, April 11, 2013 12:29 PM
  •  
    > \\US-data\it$\private\hostfile\hosts
    > <file://%5C%5CUS-data%5Cit$%5Cprivate%5Chostfile%5Chosts>file.bat but
    > when I reboot my machine, the reg key gets applied but it does not
    > copy the host file.
    >
     
    As Joseph mentioned - check ACLs on both share and NTFS level to make
    sure domain computers can access the file. And some type of logging is
    always recommended:
     xcopy /Y \\US-data\it$\private\hostfile\hosts
    <file://%5C%5CUS-data%5Cit$%5Cprivate%5Chostfile%5Chosts>
    %systemroot%\System32\drivers\etc\hosts >%temp%\logfile.txt 2>&1
     
    In opposition to my precedessors - for file operations, I do NOT
    recommend using GP Preferences in general, because they are almost
    unconfigurable and they always run synchronous (meaning delay in startup
    and logon is inevitable).
     

    NO THEY ARE NOT EVIL, if you know what you are doing: Good or bad GPOs?
    Wenn meine Antwort hilfreich war, freue ich mich über eine Bewertung! If my answer was helpful, I'm glad about a rating!
    Thursday, April 11, 2013 1:53 PM
  • Hey Martin,

    Can you explain the file operations performance a little more? Would it still be desirable to use a script even if the preference is set to create?

    Thank you so much!

    Joseph


    If my answer helped you, check out my blog (and subscribe): DeployHappiness.com

    Thursday, April 11, 2013 2:15 PM
  • In opposition to my precedessors - for file operations, I do NOT
    recommend using GP Preferences in general, because they are almost
    unconfigurable and they always run synchronous (meaning delay in startup

    and logon is inevitable).

    Well, there should not be any need to run this each time.
    You check the option "Apply once and do not reapply".


    MVP Group Policy - Mythen, Insiderinfos und Troubleshooting zum Thema GPOs: Let's go, use GPO!

    Thursday, April 11, 2013 2:56 PM
  •  
    > Can you explain the file operations performance a little more?
     
    Performance is not the point - copying 10 GB of data takes its time
    anywhere you do it.
     
    > Would it still be desirable to use a script even if the preference is
    > set to create?
     
    Depends...
     
    What about the "next version"? -> Update. What about "more files in
    different locations"? -> dozens of file preferences. What about "need
    this 470 MB mkv video on all computers" -> loooong delay.
     
    Speaking for myself:
    I use some robocopy commands in combination with some "if exist" or "if
    not exist", and I like it if I'm in full control and full speed ;-)
    I execute these in startup scripts (async) and in "run these programs"
    (async, too). Logon scripts run sync, so timing is critical there, as
    well as in GPO processing.
     
    ym2c
     
    regards, Martin
     

    NO THEY ARE NOT EVIL, if you know what you are doing: Good or bad GPOs?
    Wenn meine Antwort hilfreich war, freue ich mich über eine Bewertung! If my answer was helpful, I'm glad about a rating!
    Thursday, April 11, 2013 3:27 PM
  • Thank you for explaining!

    If my answer helped you, check out my blog (and subscribe): DeployHappiness.com

    Friday, April 12, 2013 12:00 PM