Solved

Another VBSCRIPT Copy file request (with a twist)

Posted on 2011-02-25
5
1,244 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In-place Upgrading Dirsync to Azure AD Connect
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
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 …

790 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