Please Read: Significant Update Planned, Migrating Forum Software This Month

See more
See less

Script to copy new hosts file to all computers

  • Filter
  • Time
  • Show
Clear All
new posts

  • Script to copy new hosts file to all computers

    Can anyone advise me on how to copy a new hosts file to all computers via a login script?

    I need to replace the existing hosts files on every workstation (approx. 700 pc's) with the standard default version , since we have working dns servers.

    A login script runs with the credentials of the logged in user, which means 90% of users (at least) who login don't have the credentials to allow this simple line to run:

    copy \\server\share\hosts %systemroot%\system32\drivers\etc /y

    Yes, if I login using an administrators account, it works perfectly, but obviously I don't want to give the entire user base admin rights! Nor do I want to visit 700 pc's!

    I'm a novice to scripting, but I don't think there is a way to force a dos command at the end of a login script to use different (admin) credentials.

    I thought maybe a vbscript, which could be called at the end of the login script, could run with impersonation of some kind embedded, but I really don't know.

    Anyone know how to to do this?

    Cheers guys


  • #2
    Re: Script to copy new hosts file to all computers

    You do have options:

    Try running the "copy \\.." script that you have as a startup script in GPO rather than as a logon script. GPO Startup scripts run with higher privileges, and so they do not run in the context of an end-user's account.

    Or you can use CPAU to build a script that uses the Administrator's password, so that you can run that "copy \\..." line as Administrator. The nice thing about CPAU is that it allows you to encrypt the script into a text file, so that your end users never see then actual password (or at least, they can't read it).

    You may have heard of "RUNAS". Well, runas prompts you to enter the password, which is no good in this context. Even using the /savecred switch is no good for you, apart from being very insecure, so CPAU is a better way to do it. I advise trying the GPO Startup Script option first though.
    Best wishes,
    MCP:Server 2003; MCITP:Server 2008; MCTS: SBS2008


    • #3
      Re: Script to copy new hosts file to all computers

      Use a computerconfiguration startup script with a GPO, that is linked to the workstations OU.

      Example batch-file (uses the /D, so only newer files are copied):
      Xcopy.exe /D /y "\\\SysVol\\Startupscripts\Files\host." "%SystemRoot%\system32\drivers\etc\"
      In this example the batch-file can be put in the share:
      "\\\SysVol\\Startupscripts \"
      The new host-file is in the share:
      "\\\SysVol\\Startupscripts \Files\"

      Last edited by Rems; 28th February 2007, 18:57.

      This posting is provided "AS IS" with no warranties, and confers no rights.


      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts


      • #4
        Re: Script to copy new hosts file to all computers

        Thanks guys

        Rems - couldn't get that to work, made no difference to the existing hosts file, will keep looking.

        Cheers for now



        • #5
          Re: Script to copy new hosts file to all computers

          Rems - fiddled about the example code you posted, and got it to work!

          Thanks a bunch, guy!

          All the best