Solved

Another VBSCRIPT Copy file request (with a twist)

Posted on 2011-02-25
5
1,240 Views
Last Modified: 2012-05-11
I have a unique situation (I think)

I have a ton of Windows XP Pro machines floating around the network
I have a ton of Windows 7 machines floating around the network
Obviously the user profiles are in different locations depending on the OS installed.

I have a need to copy a single Excel file from an app server to the following directory on the machine depending on the OS.

Windows 7 machines - C:\Users\username\AppData\Roaming\Microsoft\AddIns
Windows XP machines - C:\Documents and Settings\username\Application Data\Microsoft\AddIns


I've been fighting with how to determine the OS and copy the file to the correct location based on the OS version.

So basically, when the user logs in, the script runs, copies abc.xls file from \\appserver\sharename\ to either the Windows 7 user profile or the Windows XP profile



Can anyone help?
0
Comment
Question by:Todd Wedlake
5 Comments
 
LVL 33

Accepted Solution

by:
it_saige earned 500 total points
ID: 34983871
Well to start you would need to determine the os.  After you determine the os then your logic can do the rest.  Perhaps something like:
strComputer = "."
Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMI.ExecQuery("SELECT * FROM Win32_OperatingSystem",,48)

For Each objItem in colItems
	vInfo = Left(objItem.Version,3)
Next

Select Case vInfo
	Case "6.1" OSys = "Windows 7"
		' You can do your work here
	Case "6.0" OSys = "Vista"
		' You can do your work here
	Case "5.2" OSys = "Windows 2003"
		' You can do your work here
	Case "5.1" OSys = "XP"
		' You can do your work here
	Case "5.0" OSys = "W2K"
		' You can do your work here
	Case "4.0" OSys = "NT 4.0**"
		' You can do your work here
	Case Else OSys = "Undefined Operating System"
		' You can do your work here
End Select

Wscript.Echo "Version No : " & vInfo & vbCrlf & "Operating System : " & OSys

Open in new window

HTH,

-saige-
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 34983923
Why just use the %USERPROFILE% variable?

Regards,

Rob.
strSource = "\\appserver\sharename\abc.xls"

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strDestination = objShell.ExpandEnvironmentStrings("%APPDATA%") & "\Microsoft\Addins\"
If objFSO.FileExists(strDestination & Mid(strSource, InStrRev(strSource, "\") + 1)) = False Then objFSO.CopyFile strSource, strDestination

Open in new window

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 34983931
Or the APPDATA varialbe, as I used above....oops....
0
 
LVL 4

Expert Comment

by:Tuyau2poil
ID: 34983997
that script can help :

@echo off

ver | find "XP" > nul
if %ERRORLEVEL% == 0 goto ver_xp

echo %vers% | find "Windows 7" > nul
if %ERRORLEVEL% == 0 goto ver_7

goto notfound

:ver_7
xcopy  \\appserver\sharename\abc.xls C:\Users\username\AppData\Roaming\Microsoft\AddIns /d
goto exit

:ver_xp
xcopy  \\appserver\sharename\abc.xls "C:\Documents and Settings\username\Application Data\Microsoft\AddIns" /d
goto exit

:notfound
echo Machine undetermined.

:exit
0
 
LVL 2

Author Closing Comment

by:Todd Wedlake
ID: 35001800
Awesome!
Detailed and organized structure.  More than I expected to receive

Thanks for your assistance
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question