Jump to content

Recommended Posts

Posted

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?

Posted

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?

Posted
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.
Posted (edited)

OK so I've been having a play (and a headache) and I've come up with this.

 

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.

Edited by Stuart_C
Posted
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.
Posted

Because I'm a cretin who didn't really think about doing it that way? :getmecoat:

 

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.

Posted

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:

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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...