Link to home
Start Free TrialLog in
Avatar of Todd W
Todd WFlag for United States of America

asked on

Another VBSCRIPT Copy file request (with a twist)

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?
ASKER CERTIFIED SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

Or the APPDATA varialbe, as I used above....oops....
Avatar of Tuyau2poil
Tuyau2poil

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
Avatar of Todd W

ASKER

Awesome!
Detailed and organized structure.  More than I expected to receive

Thanks for your assistance