View Full Version : Re: Why Won't my Batch File run in Win 2K or XP?
guard
December 12th 03, 07:05 PM
"KC" wrote:
> My objective is to have a batch file that determines
> the computer's operating system...
See the Mount/\Command "GetOS", which is part of the FREE Advanced NT/2K/XP
Command Library (ntlib.cmd).
(http://TheSystemGuard.com/MtCmds/GetValue/GetOS.htm)
*******
Notes:
1. .Mount/\Commands are constructed using ONLY builtin
commands common to all four platforms (NT/2K/XP/K3).
2. .M/\C's are NOT case sensitive. Mixed case is used
for visual clarity only.
3. ntlib.cmd provides over 100 resources to assist with
writing and documenting cross-platform scripts.
You can obtain it (for FREE) at (http://ntlib.com).
*******
-tsg
__________________________________________________ __________
TheSystemGuard.com | BoomingOrFuming.com | MountCommands.com
Free and "Almost Free" Knowledge for Windows System Admins!
KC
December 12th 03, 07:10 PM
OK I amended my file - it reads as shown below. It works fine in Win 98.
Does not work in Win 2k or XP. Under those operating systems the script does
not perform the copy or deletes. Is this because I am not using the syntax
that Guard referred to in the previous post?
@echo off
set ver=Win95
ver | find /i "Windows 95" > nul
if not ErrorLevel 1 goto %ver%
set ver=Win98
ver | find /i "Windows 98" > nul
if not ErrorLevel 1 goto %ver%
set ver=Winxp
ver | find /i "Windows XP" > nul
if not ErrorLevel 1 goto %ver%
set ver=Win2000
ver | find /i "Windows 2000" > nul
if not ErrorLevel 1 goto %ver%
echo Unknown operating system!
pause
goto Exit
:Win95
copy c:\windows\desktop\olp.ico c:\windows\system
del c:\windows\desktop\olp_shortcut.exe
del c:\windows\desktop\olp.ico
goto Exit
:Win98
copy c:\windows\desktop\olp.ico c:\windows\system
del c:\windows\desktop\olp_shortcut.exe
del c:\windows\desktop\olp.ico
goto Exit
:Winxp
copy /Y "c:\documents and settings\all users\desktop\olp.ico" %SystemRoot%
del "c:\documents and settings\all users\desktop\olp_shortcut.exe"
del "c:\documents and settings\all users\desktop\olp.ico"
:Win2000
copy /Y "c:\documents and settings\all users\desktop\olp.ico" %SystemRoot%
del "c:\documents and settings\all users\desktop\olp_shortcut.exe"
del "c:\documents and settings\all users\desktop\olp.ico"
:Exit
cls
"guard" > wrote in message
...
> "KC" wrote:
> > My objective is to have a batch file that determines
> > the computer's operating system...
>
> See the Mount/\Command "GetOS", which is part of the FREE Advanced
NT/2K/XP
> Command Library (ntlib.cmd).
>
> (http://TheSystemGuard.com/MtCmds/GetValue/GetOS.htm)
>
> *******
> Notes:
>
> 1. .Mount/\Commands are constructed using ONLY builtin
> commands common to all four platforms (NT/2K/XP/K3).
> 2. .M/\C's are NOT case sensitive. Mixed case is used
> for visual clarity only.
> 3. ntlib.cmd provides over 100 resources to assist with
> writing and documenting cross-platform scripts.
> You can obtain it (for FREE) at (http://ntlib.com).
>
> *******
>
> -tsg
> __________________________________________________ __________
> TheSystemGuard.com | BoomingOrFuming.com | MountCommands.com
> Free and "Almost Free" Knowledge for Windows System Admins!
>
>
Pegasus \(MVP\)
December 12th 03, 07:11 PM
"KC" > wrote in message
...
> OK I amended my file - it reads as shown below. It works fine in Win 98.
> Does not work in Win 2k or XP. Under those operating systems the script
does
> not perform the copy or deletes. Is this because I am not using the syntax
> that Guard referred to in the previous post?
>
>
> @echo off
> set ver=Win95
> ver | find /i "Windows 95" > nul
> if not ErrorLevel 1 goto %ver%
>
> set ver=Win98
> ver | find /i "Windows 98" > nul
> if not ErrorLevel 1 goto %ver%
>
> set ver=Winxp
> ver | find /i "Windows XP" > nul
> if not ErrorLevel 1 goto %ver%
>
> set ver=Win2000
> ver | find /i "Windows 2000" > nul
> if not ErrorLevel 1 goto %ver%
>
> echo Unknown operating system!
> pause
> goto Exit
>
> :Win95
> copy c:\windows\desktop\olp.ico c:\windows\system
> del c:\windows\desktop\olp_shortcut.exe
> del c:\windows\desktop\olp.ico
> goto Exit
>
> :Win98
> copy c:\windows\desktop\olp.ico c:\windows\system
> del c:\windows\desktop\olp_shortcut.exe
> del c:\windows\desktop\olp.ico
> goto Exit
>
> :Winxp
> copy /Y "c:\documents and settings\all users\desktop\olp.ico" %SystemRoot%
> del "c:\documents and settings\all users\desktop\olp_shortcut.exe"
> del "c:\documents and settings\all users\desktop\olp.ico"
>
> :Win2000
> copy /Y "c:\documents and settings\all users\desktop\olp.ico" %SystemRoot%
> del "c:\documents and settings\all users\desktop\olp_shortcut.exe"
> del "c:\documents and settings\all users\desktop\olp.ico"
>
> :Exit
> cls
Your batch file ran quite nicely on my Win2000 machine.
At the same time there is room for some improvement.
- Your file lacks a "goto Exit" just before the :Win2000 label
- Much of your code is duplicated
Here is a condensed and updated version of your batch file:
@echo off
ver | find /i "Windows 95" > nul
if not ErrorLevel 1 goto Win9x
ver | find /i "Windows 98" > nul
if not ErrorLevel 1 goto Win9x
ver | find /i "Windows XP" > nul
if not ErrorLevel 1 goto WinNT
ver | find /i "Windows 2000" > nul
if not ErrorLevel 1 goto WinNT
echo Unknown operating system!
pause
goto Exit
:Win9x
echo Win9x code
copy c:\windows\desktop\olp.ico c:\windows\system
del c:\windows\desktop\olp_shortcut.exe
del c:\windows\desktop\olp.ico
goto Exit
:WinNT
echo WinNT code
copy /Y "c:\documents and settings\all users\desktop\olp.ico" %SystemRoot%
del "c:\documents and settings\all users\desktop\olp_shortcut.exe"
del "c:\documents and settings\all users\desktop\olp.ico"
:Exit
Now if you still have problems, please follow the advice
I gave in my first reply:
- Get rid of the CLS statement during the testing phase
- Get rid of the "@echo off" statement during the testing phase
And please: When reporting that "it does not work", it is
absolutely essential that you provide full details. My fortune
teller's cloack is currently at the dry cleaners, hence I do
not know what's wrong with your code unless you report it
in detail.
Ignore the comments made by "Guard". He likes to push
his "Mount" commercial product in this forum.
KC
December 12th 03, 07:11 PM
> And please: When reporting that "it does not work", it is
> absolutely essential that you provide full details. My fortune
> teller's cloack is currently at the dry cleaners, hence I do
> not know what's wrong with your code unless you report it
> in detail.
Pegasus - thanks for the reply, and thanks for the humorous reminder! I hate
to admit it, but I support users of various internal applications at work,
and I'm always reminding them that "It isn't working" doesn't give me enough
to go on.
I'm using this script together with a self extracting archive. When the user
clicks on the self extracting archive, it places a shortcut to a url along
with a custom icon on their desktop.
Then the script takes over, copying the icon from the desktop to the
system32 folder (the url shortcut is saved with a path to the icon in the
system 32 folder). The script then is to delete the self extracting archive
and the icon on the desktop.
End result, the user has a shortcut on their desktop with a custom icon. The
shortcut takes them to a web application used in their work.
I'll give it another try.
"Pegasus (MVP)" > wrote in message
...
>
> "KC" > wrote in message
> ...
> > OK I amended my file - it reads as shown below. It works fine in Win 98.
> > Does not work in Win 2k or XP. Under those operating systems the script
> does
> > not perform the copy or deletes. Is this because I am not using the
syntax
> > that Guard referred to in the previous post?
> >
> >
> > @echo off
> > set ver=Win95
> > ver | find /i "Windows 95" > nul
> > if not ErrorLevel 1 goto %ver%
> >
> > set ver=Win98
> > ver | find /i "Windows 98" > nul
> > if not ErrorLevel 1 goto %ver%
> >
> > set ver=Winxp
> > ver | find /i "Windows XP" > nul
> > if not ErrorLevel 1 goto %ver%
> >
> > set ver=Win2000
> > ver | find /i "Windows 2000" > nul
> > if not ErrorLevel 1 goto %ver%
> >
> > echo Unknown operating system!
> > pause
> > goto Exit
> >
> > :Win95
> > copy c:\windows\desktop\olp.ico c:\windows\system
> > del c:\windows\desktop\olp_shortcut.exe
> > del c:\windows\desktop\olp.ico
> > goto Exit
> >
> > :Win98
> > copy c:\windows\desktop\olp.ico c:\windows\system
> > del c:\windows\desktop\olp_shortcut.exe
> > del c:\windows\desktop\olp.ico
> > goto Exit
> >
> > :Winxp
> > copy /Y "c:\documents and settings\all users\desktop\olp.ico"
%SystemRoot%
> > del "c:\documents and settings\all users\desktop\olp_shortcut.exe"
> > del "c:\documents and settings\all users\desktop\olp.ico"
> >
> > :Win2000
> > copy /Y "c:\documents and settings\all users\desktop\olp.ico"
%SystemRoot%
> > del "c:\documents and settings\all users\desktop\olp_shortcut.exe"
> > del "c:\documents and settings\all users\desktop\olp.ico"
> >
> > :Exit
> > cls
>
> Your batch file ran quite nicely on my Win2000 machine.
> At the same time there is room for some improvement.
>
> - Your file lacks a "goto Exit" just before the :Win2000 label
> - Much of your code is duplicated
>
> Here is a condensed and updated version of your batch file:
>
> @echo off
> ver | find /i "Windows 95" > nul
> if not ErrorLevel 1 goto Win9x
>
> ver | find /i "Windows 98" > nul
> if not ErrorLevel 1 goto Win9x
>
> ver | find /i "Windows XP" > nul
> if not ErrorLevel 1 goto WinNT
>
> ver | find /i "Windows 2000" > nul
> if not ErrorLevel 1 goto WinNT
>
> echo Unknown operating system!
> pause
> goto Exit
>
> :Win9x
> echo Win9x code
> copy c:\windows\desktop\olp.ico c:\windows\system
> del c:\windows\desktop\olp_shortcut.exe
> del c:\windows\desktop\olp.ico
> goto Exit
>
> :WinNT
> echo WinNT code
> copy /Y "c:\documents and settings\all users\desktop\olp.ico" %SystemRoot%
> del "c:\documents and settings\all users\desktop\olp_shortcut.exe"
> del "c:\documents and settings\all users\desktop\olp.ico"
>
> :Exit
>
> Now if you still have problems, please follow the advice
> I gave in my first reply:
> - Get rid of the CLS statement during the testing phase
> - Get rid of the "@echo off" statement during the testing phase
>
> And please: When reporting that "it does not work", it is
> absolutely essential that you provide full details. My fortune
> teller's cloack is currently at the dry cleaners, hence I do
> not know what's wrong with your code unless you report it
> in detail.
>
> Ignore the comments made by "Guard". He likes to push
> his "Mount" commercial product in this forum.
>
>
Wilfried Hennings
December 12th 03, 07:12 PM
"KC" > wrote:
> I'm using this script together with a self extracting archive. When the user
> clicks on the self extracting archive, it places a shortcut to a url along
> with a custom icon on their desktop.
>
> Then the script takes over, copying the icon from the desktop to the
> system32 folder (the url shortcut is saved with a path to the icon in the
> system 32 folder). The script then is to delete the self extracting archive
> and the icon on the desktop.
Which permissions does your "user" have?
On my system, ordinary users don't have write permission on the
....\all users\desktop
Which way is your script invoked? Maybe it runs under a different
account. To see which, include an "echo %username%" in the script.
--
email me: change "nospam" to "w.hennings"
Dipl.-Ing.(=M.Sc.Eng.) Wilfried Hennings c./o.
Forschungszentrum (Research Center) Juelich GmbH, MUT
<http://www.fz-juelich.de/mut/index.php?index=3>
All opinions mentioned are strictly my own, not my employer's.
guard
December 12th 03, 07:14 PM
"Pegasus (MVP)" wrote:
> "Mount" commercial product...
Clarification:
The Mount/\Command "GetOS" mentioned previously
in this thread is included in the FREE Advanced
NT/2K/XP/K3 Command Library. This product is
Copyrighted Freeware with NO RESTRICTIONS on
personal or commercial use.
For info, see (http://ntlib.com).
*******
-tsg
__________________________________________________ __________
TheSystemGuard.com | BoomingOrFuming.com | MountCommands.com
Free and "Almost Free" Knowledge for Windows System Admins!
vBulletin® v3.6.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.