Results 1 to 3 of 3

Thread: VBScript to copy files

  1. #1
    kev147 is offline 30+ Helpful Posts 50+ Helpful Posts
    Join Date
    Dec 1969
    Posts
    50

    Default

    Here is the code that you can use to copy files. You can launch this vbscript via group policy to copy files such as Corporate wallpaper & screensaver to the PC and then use group policy to configure the registry under administrative templates. Any suggestions/recommendations welcome.

    -------------------------------------------------------------------------------------
    On Error Resume Next

    Dim WshShell,WshEnv

    'Configures Variables
    Set WshShell = CreateObject("WScript.Shell")
    set WshEnv = WshShell.Environment("Process")
    SysDrive = WshEnv("SYSTEMDRIVE")
    SysRoot = WshEnv("SYSTEMROOT")
    LogonSvr = WshEnv("LOGONSERVER")

    'Set the Source and Destination paths below
    '------------------------------------------------------------------------------------------
    SourceLocation = SysDrive & "\Kev\"
    SourceFilename = "azul.jpg"
    'DestinationLocation = SysRoot & "\"
    DestinationLocation = "\\w15821\c$\"
    DestinationFilename = "zazul.jpg"
    '------------------------------------------------------------------------------------------

    msgbox SourceLocation & SourceFilename
    msgbox DestinationLocation & DestinationFilename

    'copies file from source to destination
    set fso = CreateObject("Scripting.FileSystemObject")
    fso.CopyFile SourceLocation & SourceFilename, DestinationLocation & DestinationFilename, overwrite = TRUE

    'Clears cache
    set fso = nothing
    set WshShell = nothing
    set WshEnv = nothing

    msgbox "Completed!"
    -------------------------------------------------------------------------------------

  2. #2
    AdamV is offline 100+ Helpful Posts! 50+ Helpful Posts
    Join Date
    Dec 1969
    Posts
    669

    Default

    This seems to copy to the same machine name every time, should you not be picking up the machine name from the machine on which it is run, or use a relative path from an environmental variable such as windir ?

    (and what is wrong with just using a one line xcopy command anyway? ;-) )

  3. #3
    kev147 is offline 30+ Helpful Posts 50+ Helpful Posts
    Join Date
    Dec 1969
    Posts
    50

    Default

    It is not the final script for my purposes. If you look at the script I have set an environment variable for LogonServer. This is so I can have the corporate screensaver and wallpaper within the netlogon share and then use this variable to configure the source.

    Valid point about the destination though. I need to modify it to set the computername variable.

    I am aware that you can use the xcopy command to copy files. The problem is that I have to provide a solution for each method (VBScript & batch). This is so that we have a fallback if anything goes wrong.

    Thanks for your comments though. I will repost the script once I have modified it.

Posting Permissions

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

Search Engine Friendly URLs by vBSEO