Batch to check OS version and then copy a file to All Users Desktop

Since the All Users Desktop is located in different places I am looking to create a batch file to check the OS version and copy a shortcut to the C:\Documents and Settings\All Users\Desktop on XP and C:\Users\Public\Desktop on Vista. Is the C:\Users\Public\Desktop the same location on Win 7?
jmoodyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

George KhairallahCTOCommented:
You can use this batch file to find the different OSs, and fill in the blanks to copy whatever you want in the appropriate sections. Hope this helps.

(this script can be found at the following site:
http://malektips.com/xp_dos_0025.html)


@echo off

ver | find "2003" > nul
if %ERRORLEVEL% == 0 goto ver_2003

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

ver | find "2000" > nul
if %ERRORLEVEL% == 0 goto ver_2000

ver | find "NT" > nul
if %ERRORLEVEL% == 0 goto ver_nt

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

echo %vers% | find "Windows Server 2008" > nul
if %ERRORLEVEL% == 0 goto ver_2008

echo %vers% | find "Windows Vista" > nul
if %ERRORLEVEL% == 0 goto ver_vista

goto warnthenexit

:ver_7
:Run Windows 7 specific commands here.
echo Windows 7
goto exit

:ver_2008
:Run Windows Server 2008 specific commands here.
echo Windows Server 2008
goto exit

:ver_vista
:Run Windows Vista specific commands here.
echo Windows Vista
goto exit

:ver_2003
:Run Windows Server 2003 specific commands here.
echo Windows Server 2003
goto exit

:ver_xp
:Run Windows XP specific commands here.
echo Windows XP
goto exit

:ver_2000
:Run Windows 2000 specific commands here.
echo Windows 2000
goto exit

:ver_nt
:Run Windows NT specific commands here.
echo Windows NT
goto exit

:warnthenexit
echo Machine undetermined.

:exit

Open in new window

oBdACommented:
The script below will determine the correct location of the "All Users" desktop, even if it's redirected; it checks the registry to find the defined path and sets the variable "CommonDesktop" to it.
This should work from XP to W2k8 R2 (and even on W2k if reg.exe is in the same folder as the script).

@echo off
setlocal
for /f "tokens=3*" %%a in ('reg query "HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "Common Desktop" ^| find /i "Common Desktop"') do (
  if /i "%%a"=="REG_EXPAND_SZ" (call :Expand CommonDesktop "%%b") else (set CommonDesktop=%%b)
)
echo Common Desktop folder: [%CommonDesktop%]
copy "\\SomeServer\SomeShare\SomeShortcut.lnk" "%CommonDesktop%"


:: *** Leave the main script, only subroutines from here.
goto :eof
:Expand
set %1=%~2

Open in new window

jmoodyAuthor Commented:
Thanks for the replies. One more question though. I have a few 64 bit OSs out there so the program installs to Program Files(x86) on those. How do I check for 32 and 64 bit so that I can move a file in there?
oBdACommented:
Use the code below to set the environment variable "ProgramFiles32" to the 32bit program files folder, even on an x64 Windows, then use this variable to access the program files folder:

REM *** Force 32bit program files folder:
if defined ProgramFiles(x86) (set ProgramFiles32=%ProgramFiles(x86)%) else (set ProgramFiles32=%ProgramFiles%)
echo 32bit program files folder: %ProgramFiles32%

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Legacy OS

From novice to tech pro — start learning today.