Solved

Another VBSCRIPT Copy file request (with a twist)

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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 video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

717 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