Solved

Another VBSCRIPT Copy file request (with a twist)

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Companies that have implemented Microsoft’s Active Directory need to ensure that the Active Directory is configured and operating properly. If there are issues found and not resolved, it eventually leads the components to fail or stop working and fi…
Do you have users whose passwords are expiring and they are constantly calling you?  Well I sure did and needed a way to put an end to this.  We have a lot of remote users which would not be notified that their passwords were expiring since they wer…
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 transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now