Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Another VBSCRIPT Copy file request (with a twist)

Posted on 2011-02-25
5
Medium Priority
?
1,256 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 34

Accepted Solution

by:
it_saige earned 2000 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
A hard and fast method for reducing Active Directory Administrators members.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
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 …

610 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