Batch File to copy a file based upon OS

Microsoft Windows 7 professional 32-bit
July 20, 2010 at 16:37:10
Specs: Windows 7
Hello, I was wondering if there was anyone who could please help in writing a batch file. What I am trying to achieve is fairly simple but I'm having trouble getting all the code together to make it work. What I am trying to do is simply copy a file off a network share and place it into a specific location on quite a number of PCs (around 200-300). Now the specific location I am referring to on the users PC will differ depending on what OS they are on. We only use XP or Win 7 so I want the batch file to first determine is the user a member of a certain AD security group (which is called 'Teachers') and if the user is using Win 7 then copy the file else if the user is a member of the 'Teachers' security group and is the user is using XP then copy the file to a different location. I have written 2 batch files which accomplish what I need to do however there are no if else statements in there. Here is my 2 batch files:

Windows 7 -
@ECHO OFF

ECHO.

xcopy "\\cgkewsccm01\necprojector\user.lst" "\\%COMPUTERNAME%\C$\Users\%USERNAME%\AppData\Roaming\NEC Projector User Supportware\Communication Settings\" /C /R /H /K /Y

Windows XP -
@ECHO OFF

ECHO.

xcopy "\\cgkewsccm01\necprojector\user.lst" "\\%COMPUTERNAME%\c$\Documents and Settings\%USERNAME%\Application Data\NEC Projector User Supportware\Communication Settings" /C /R /H /K /Y

The file I am copying is a small config file needed to update some networked NEC Projectors and must go into the 2 locations I have specified above. Thank you all for your help and assistance.


See More: Batch File to copy a file based upon OS

Report •

#1
July 20, 2010 at 21:00:41
Ok I have managed to write a batch file to accomplish most of what I need (see below) I just need this to now only copy to member of a certain distribution list. I will keep working on it so if anyone has any ideas please share.

@echo off

ver | find "XP" > nul
if %ERRORLEVEL% == 0 goto ver_xp

if not exist %SystemRoot%\system32\systeminfo.exe goto warnthenexit

systeminfo | find "OS Name" > %TEMP%\osname.txt
FOR /F "usebackq delims=: tokens=2" %%i IN (%TEMP%\osname.txt) DO set vers=%%i

echo %vers% | find "Windows 7" > nul
if %ERRORLEVEL% == 0 goto ver_7

goto warnthenexit

:ver_7
xcopy "\\cgkewsccm01\necprojector\user.lst" "\\%COMPUTERNAME%\C$\Users\%USERNAME%\AppData\Roaming\NEC Projector User Supportware\Communication Settings\" /C /R /H /K /Y
echo Windows 7
goto exit

:ver_xp
xcopy "\\cgkewsccm01\necprojector\user.lst" "\\%COMPUTERNAME%\c$\Documents and Settings\%USERNAME%\Application Data\NEC Projector User Supportware\Communication Settings" /C /R /H /K /Y
echo Windows XP
goto exit

:warnthenexit
echo Machine undetermined.

:exit


Report •

#2
July 21, 2010 at 01:54:32
You should post Programming queries here:

http://www.computing.net/forum/prog...


Report •

#3
July 21, 2010 at 16:51:55
ok i will post there sorry about that 1st time posting on this site

Report •
Related Solutions


Ask Question