+ Post New Thread
Results 1 to 9 of 9
Scripts Thread, Scripting help needed to copy files in Coding and Web Development; Hi there, I need a script to copy files from my network to a location on the PC. However I ...
  1. #1

    Join Date
    Nov 2007
    Location
    Rotherham
    Posts
    1,678
    Thank Post
    122
    Thanked 126 Times in 102 Posts
    Rep Power
    45

    Scripting help needed to copy files

    Hi there,
    I need a script to copy files from my network to a location on the PC. However I need it to copy the the files to a different loaction depending on the OS of the PC.

    Basically I'm copying stuff to the profile path and I've got Win7 and XP clients.

    Can anyone help?

  2. #2

    ZeroHour's Avatar
    Join Date
    Dec 2005
    Location
    Edinburgh, Scotland
    Posts
    5,628
    Thank Post
    920
    Thanked 1,336 Times in 816 Posts
    Blog Entries
    1
    Rep Power
    448
    Use group policy preferences with targeting rules?

  3. #3

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,157
    Thank Post
    116
    Thanked 529 Times in 452 Posts
    Blog Entries
    2
    Rep Power
    124
    Are you running this as part of the machine startup/user login process (ie you're pulling files from a server to the local workstation) or are you running it on the server (or your own machine) and pushing files out to clients?

    If it's the former, then it's easy - the OS can tell you where the user profiles are. If it's the latter then you can use the WMI stuff linked to by @jinnantonnix; - you just change the "." (which means "local computer" to the computer name. That will then give you the OS name and you can then work out where to put the files.

    I would definitely go with machine startup or (probably even easier) user logon - what are you trying to achieve?

  4. #4

    Join Date
    Nov 2007
    Location
    Rotherham
    Posts
    1,678
    Thank Post
    122
    Thanked 126 Times in 102 Posts
    Rep Power
    45
    Basically I'm copying some files from the server to the local profile path. It's in a script that happens once a week just to make sure the computers are upto date. It's mostly some document templates and shortcut links.

  5. #5

    Join Date
    Nov 2007
    Location
    Rotherham
    Posts
    1,678
    Thank Post
    122
    Thanked 126 Times in 102 Posts
    Rep Power
    45
    OK so I've been having a play (and a headache) and I've come up with this.

    Code:
    OSVersion = ""
    strComputer = "."
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" _
        & strComputer & "\root\cimv2")
    Set colOperatingSystems = objWMIService.ExecQuery _
        ("Select * from Win32_OperatingSystem")
    For Each objOperatingSystem in colOperatingSystems
        OSVersion = objOperatingSystem.Caption
        Wscript.Echo OSVersion
    next
    If OSVersion = "Microsoft Windows 7 Professional" Then
        objFSO.CopyFile "C:\scripts\*.txt","C:\scripts\temp\", False
        Wscript.Echo "It's all gone right"
    else
        Wscript.Echo "It's all gone wrong"
    End If
    the problem is that it doesn't work. Now I am working on a windows 7 Pro machine but the If statement returns a fasle result so echo's "it's all gone wrong". Why?
    I'm still working on it which is why the first echo show the OS and I'm not copying the correct files.
    Last edited by Stuart_C; 3rd August 2010 at 01:07 PM.

  6. #6

    Join Date
    Nov 2007
    Location
    Rotherham
    Posts
    1,678
    Thank Post
    122
    Thanked 126 Times in 102 Posts
    Rep Power
    45
    Got it, for some reason there is a space on the end of the OS Version that I hadn't got in my IF statement.

  7. #7

    ZeroHour's Avatar
    Join Date
    Dec 2005
    Location
    Edinburgh, Scotland
    Posts
    5,628
    Thank Post
    920
    Thanked 1,336 Times in 816 Posts
    Blog Entries
    1
    Rep Power
    448
    I have to ask, but why didnt you just use group policy preferences? its a standard way to do this and much simpler and should be more reliable since its an official tool of MS.

  8. #8

    Join Date
    Nov 2007
    Location
    Rotherham
    Posts
    1,678
    Thank Post
    122
    Thanked 126 Times in 102 Posts
    Rep Power
    45
    Because I'm a cretin who didn't really think about doing it that way?

    To be honest it's a case of I have scripted it using bat files so why not script it with vbs when it gets complicated.

    Might have a look and see what needs doing to use the file options in preferences. Shame really I'd almost got there, was just trying to figure out how to create the folders if they didn't exist.

  9. #9

    ZeroHour's Avatar
    Join Date
    Dec 2005
    Location
    Edinburgh, Scotland
    Posts
    5,628
    Thank Post
    920
    Thanked 1,336 Times in 816 Posts
    Blog Entries
    1
    Rep Power
    448
    Is think its {your file system object}.CreateFolder
    Use If (fso.FolderExists("{path}")) type of thing to ensure it does/doesnt exist.

    Another useful function for you is:
    Code:
    Set WshShell = WScript.CreateObject("WScript.Shell") 'If you dont have it already set in the script.
    
    function LogtoEvent (MSG,success)
    	select case success
    		case 1	WshShell.LogEvent EVENT_SUCCESS, MSG ' 1 is a success
    		case 0	WshShell.LogEvent EVENT_FAILURE, MSG ' 0 is a error
    		case 2	WshShell.LogEvent EVENT_WARNING, MSG ' 2 is a warning
    		case 3	WshShell.LogEvent EVENT_INFORMATION, MSG ' do not use
    	end select
    end function
    
    LogtoEvent "LOG THIS MESSAGE IN EVENT LOG",1
    I use that in pretty much all my vbs to log things as they run.

SHARE:
+ Post New Thread

Similar Threads

  1. Copy files to another location
    By Chuckster in forum How do you do....it?
    Replies: 7
    Last Post: 23rd October 2009, 02:09 PM
  2. Scripting challenge: Copy files into profile
    By tmcd35 in forum Windows Server 2000/2003
    Replies: 0
    Last Post: 26th August 2009, 02:22 PM
  3. AD Scripting Help needed
    By Grommit in forum Wireless Networks
    Replies: 2
    Last Post: 22nd October 2008, 08:05 PM
  4. How to copy files from two domains
    By timbo343 in forum Scripts
    Replies: 5
    Last Post: 18th February 2008, 09:43 PM
  5. Failed to copy files from CD
    By Dos_Box in forum Learning Network Manager
    Replies: 13
    Last Post: 12th April 2007, 10:42 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
  •