+ Post New Thread
Results 1 to 12 of 12
Scripts Thread, File coping script in Coding and Web Development; I need a script to copy a file from the server to a client machine and next time it is ...
  1. #1

    Join Date
    Feb 2011
    Posts
    64
    Thank Post
    5
    Thanked 1 Time in 1 Post
    Rep Power
    0

    File coping script

    I need a script to copy a file from the server to a client machine and next time it is run it will check to see if the file is present. If it has already copied then the script will check and not copy the file down again

    copy /Y "\\DomainController\Share$\File Location" "C:\\Documents and Settings\All Users\Start Menu\Programs\"

    This is what I have so far

  2. #2
    jamesreedersmith's Avatar
    Join Date
    Sep 2009
    Location
    Ruskington
    Posts
    1,167
    Thank Post
    78
    Thanked 258 Times in 230 Posts
    Rep Power
    78
    You can use "if exist" to do this.

  3. #3

    glennda's Avatar
    Join Date
    Jun 2009
    Location
    Sussex
    Posts
    7,817
    Thank Post
    272
    Thanked 1,138 Times in 1,034 Posts
    Rep Power
    350
    you want something like

    if exist C:\path\to\file.exe goto end

    xcopy \\server\share\file.exe C:\path\to\file.exe /relevant /parameters /here

    end

    or you could do

    if exist C:\filename.txt goto end

    xcopy \\server\share\file.exe C:\path\to\file.exe /relevant /parameters /here

    echo done>C:\filename.txt

    end

  4. Thanks to glennda from:

    rpettit (15th May 2011)

  5. #4

    Join Date
    Feb 2011
    Posts
    64
    Thank Post
    5
    Thanked 1 Time in 1 Post
    Rep Power
    0
    Many thanks for the reply. I might need to post another thread but can you help to start with please?

    Is there a way to create a script that will also create a schedule task to run a batch file on shutdown?

    To give a full explanation...I need to copy a file (script) from the server to the client. The script will also need to create a schedule task to run the script on shutdown that has just been copied to the client.

  6. #5

    glennda's Avatar
    Join Date
    Jun 2009
    Location
    Sussex
    Posts
    7,817
    Thank Post
    272
    Thanked 1,138 Times in 1,034 Posts
    Rep Power
    350
    I think you can deploy scheduled tasks through Group Policy Preferences nowadays which might be easier solution.

    What is it the scripts actually need to do i.e could you not setup it as a shutdown script just like the startup script you are going to do?

  7. #6

    Join Date
    Feb 2011
    Posts
    64
    Thank Post
    5
    Thanked 1 Time in 1 Post
    Rep Power
    0
    I am looking to:

    1) Copy a file from server to client (a security template)
    2) Create a batch file to deploy the security template on shutdown (every time the machine is shutdown)

    1) This will copy the file from the server the client.

    if exist C:\path\to\file.exe goto end

    xcopy \\server\share\file.exe C:\path\to\file.exe /relevant /parameters /here

    end

    Now I need a batch file to deploy the template via a script to run during shutdown.

  8. #7

    glennda's Avatar
    Join Date
    Jun 2009
    Location
    Sussex
    Posts
    7,817
    Thank Post
    272
    Thanked 1,138 Times in 1,034 Posts
    Rep Power
    350
    Quote Originally Posted by rpettit View Post
    Now I need a batch file to deploy the template via a script to run during shutdown.
    I don't understand what you mean by this - what sort of security template for what?

    is it something which needs to be executed? if so by what program etc

  9. #8

    Join Date
    Feb 2011
    Posts
    64
    Thank Post
    5
    Thanked 1 Time in 1 Post
    Rep Power
    0
    I want to want to disallow local access when connected to the domain, but allow local access when at home.

    I can do this by deploying a computer security policy via a GPO. I need to change the security policy when the machine shutdowns. So when they are at home they can access their local account and when they are in the school domain the policy will again be applied and restrict access.

    I will create a security template and then apply this via a script or schedule task on computer shutdown.

  10. #9

    glennda's Avatar
    Join Date
    Jun 2009
    Location
    Sussex
    Posts
    7,817
    Thank Post
    272
    Thanked 1,138 Times in 1,034 Posts
    Rep Power
    350
    ok not sure how you would implement the security template from a script.

    but gpos tend to hand around so you might find that when the laptop boots again the gpo's applied which redisables local connections.

  11. #10

    SYNACK's Avatar
    Join Date
    Oct 2007
    Posts
    11,186
    Thank Post
    875
    Thanked 2,717 Times in 2,302 Posts
    Blog Entries
    11
    Rep Power
    780
    You would want to use the "secedit.exe /import" command.

    Not sure if it will work right with GP though, a better bet may be to run a script to disable all local user accounts instead:
    Code:
    '*************************************************
    ' File:  Disable Local User Accounts.vbs
    ' Author: Andrew Barnes
    ' version:  1.0 Date: 07 September 2009 By : Andrew D Barnes
    ' Lists local accounts and disables all except local admin and ASPNET
    '*************************************************
    Set objShell = CreateObject("Wscript.Shell")
    Set objNetwork = CreateObject("Wscript.Network")
    strComputer = objNetwork.ComputerName
    Set colAccounts = GetObject("WinNT://" & strComputer & "")
    colAccounts.Filter = Array("user")
        Message = Message & "Local User accounts:" & vbCrLf & vbCrLf
    For Each objUser In colAccounts
     If objUser.Name <> "Administrator" AND objUser.Name <> "ASPNET" Then
       Message = Message & objUser.Name
       If objUser.AccountDisabled = TRUE then
         Message = Message & " is currently disabled" & vbCrLf
       Else
        Message = Message & " was enabled" & vbCrLf
        objUser.AccountDisabled = True
        objUser.SetInfo
       End if
        End If
    Next
    ' Initialize title text.
    Title = "Local User Accounts By Andrew Barnes"
    objShell.Popup Message, , Title, vbInformation + vbOKOnly
    http://gallery.technet.microsoft.com...5-f6dd90421394

    then reverse the process to allow them in at home.
    Last edited by SYNACK; 16th May 2011 at 12:49 AM.

  12. #11


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,065
    Thank Post
    232
    Thanked 2,717 Times in 2,005 Posts
    Rep Power
    795
    Instead of...

    Code:
    if exist C:\path\to\file.exe goto end
    xcopy \\server\share\file.exe C:\path\to\file.exe /relevant /parameters /here
    :end
    You could simplify it even further still...

    Code:
    if exist C:\path\to\file.exe goto :eof
    xcopy \\server\share\file.exe C:\path\to\file.exe /relevant /parameters /here
    Code:
    if not exist C:\path\to\file.exe xcopy \\server\share\file.exe C:\path\to\file.exe /relevant /parameters /here
    Code:
    robocopy \\server\share\file.exe C:\path\to\file.exe /XO /R:0 /W:0 /NP
    * RoboCopy is included as standard with Windows 7 and Server 2008 R2.

  13. #12

    SYNACK's Avatar
    Join Date
    Oct 2007
    Posts
    11,186
    Thank Post
    875
    Thanked 2,717 Times in 2,302 Posts
    Blog Entries
    11
    Rep Power
    780
    +1 use robocopy instead, way more robust and simple scriptwise.

SHARE:
+ Post New Thread

Similar Threads

  1. Change a file name to something else by script
    By andy_nic in forum Scripts
    Replies: 11
    Last Post: 28th January 2010, 11:57 AM
  2. need .reg file or script please
    By Grommit in forum Windows
    Replies: 6
    Last Post: 30th December 2009, 01:56 PM
  3. File Rename Script
    By Jackd in forum How do you do....it?
    Replies: 2
    Last Post: 19th November 2008, 07:39 AM
  4. Script to get all file on a url
    By Midget in forum Scripts
    Replies: 5
    Last Post: 23rd January 2007, 01:10 PM
  5. Replies: 4
    Last Post: 23rd March 2006, 06:27 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •