Page 1 of 1 1
Topic Options
#206466 - 2012-12-13 04:35 PM if exist within if exist statement
Robdutoit Offline
Hey THIS is FUN
***

Registered: 2012-03-27
Posts: 363
Loc: London, England
Horribly Newbie question, but something that I have never really quite understood. How does one write an if exist within an if exist statement.

For example, one would write

 Code:
if exist x = 0
? "do whatever"
else
Endif

Thats pretty straightforward

But what if you want to do this:

 Code:
if exist x = 0
? "do not do anything"
Else
if exist y = 0
"Then we need to do this"
else
Endif

The code that I am using is this:

 Code:
;=============================================================================================
; remove picture icon on Windows 7 login only if BackgroundDefault.jpg picture actually exists
;=============================================================================================

If exist ("%windir%\system32\oobe\Info\Backgrounds\BackgroundDefault.jpg") = 0
? "do not change the Windows 7 Login Look"
Else
If exist ("%windir%\system32\authuiobsolete.dll") = 0
shell 'takeown /a /f %SystemRoot%\System32\authui.dll'
shell 'ICACLS %SystemRoot%\System32\authui.dll /Grant Administrators:F'
? "removing the Picture Icon on windows 7 login screen"
move ("%windir%\system32\authui.dll") ("%windir%\system32\authuiobsolete.dll")
copy ("\\" + $MyDomain + "\netlogon\patches\authui.dll") ("%windir%\system32\authui.dll")
Endif



What this does is the backgrounddefault picture does not exist, I don't want the script to do anything. However if the background picture does exist, then I want the script to check for the existence of a file. If that file does not exist, then I want the script to execute the functions.

My problem has always been that I have been forced to use goto to get around the problem of an if exist statement not working within an if exist statement. The documentation does not help as it does not seem to cover this problem. Using case is only useful if you are using 3 conditions or more which is not applicable in this instance.

So how does this dumb newbie (ME) write an if exist within an if exist statement and get it to work!
Thanks

Top
#206468 - 2012-12-13 04:43 PM Re: if exist within if exist statement [Re: Robdutoit]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
If I understand what you are wanting to do correctly, then either of the below options should work.
 Code:
If Exist("%windir%\system32\oobe\Info\Backgrounds\BackgroundDefault.jpg")
   If Not Exist("%windir%\system32\authuiobsolete.dll")
      shell 'takeown /a /f %SystemRoot%\System32\authui.dll'
      shell 'ICACLS %SystemRoot%\System32\authui.dll /Grant Administrators:F'
      ? "removing the Picture Icon on windows 7 login screen"
      move ("%windir%\system32\authui.dll") ("%windir%\system32\authuiobsolete.dll")
      copy ("\\" + $MyDomain + "\netlogon\patches\authui.dll") ("%windir%\system32\authui.dll")
   Endif
Endif
OR
 Code:
If Exist("%windir%\system32\oobe\Info\Backgrounds\BackgroundDefault.jpg") AND Not Exist("%windir%\system32\authuiobsolete.dll")
   shell 'takeown /a /f %SystemRoot%\System32\authui.dll'
   shell 'ICACLS %SystemRoot%\System32\authui.dll /Grant Administrators:F'
   ? "removing the Picture Icon on windows 7 login screen"
   move ("%windir%\system32\authui.dll") ("%windir%\system32\authuiobsolete.dll")
   copy ("\\" + $MyDomain + "\netlogon\patches\authui.dll") ("%windir%\system32\authui.dll")
Endif

Top
#206469 - 2012-12-13 04:52 PM Re: if exist within if exist statement [Re: ShaneEP]
Robdutoit Offline
Hey THIS is FUN
***

Registered: 2012-03-27
Posts: 363
Loc: London, England
I notice that you put it like this
if exist x
do whatever.

Are you not supposed to do

if exist x = 1

I always thought that you had to state whether the value was true or false i.e. 1 or 0?

Thanks for the very speedy reply

Top
#206470 - 2012-12-13 04:54 PM Re: if exist within if exist statement [Re: Robdutoit]
Robdutoit Offline
Hey THIS is FUN
***

Registered: 2012-03-27
Posts: 363
Loc: London, England
Ignore that question. I have just looked at the command reference and I see that you don't have to put the 0 or 1. I guess its only if you want to explicitly state that the script must do something if the condition is true or false.
Top
#206473 - 2012-12-13 05:12 PM Re: if exist within if exist statement [Re: Robdutoit]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4574
Loc: USA

if $value
;do stuff
endif

is equivalent to

if $value<>""
;do stuff
endif
_________________________
(... better days ahead)

Top
#206479 - 2012-12-13 07:45 PM Re: if exist within if exist statement [Re: Allen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
Or zero! Don't forget zero!! (It's already the lonliest number...) \:D

If $Value (is not a null string or a value of zero)
; then do this stuff...
EndIf

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#206480 - 2012-12-13 08:51 PM Re: if exist within if exist statement [Re: Glenn Barnas]
Robdutoit Offline
Hey THIS is FUN
***

Registered: 2012-03-27
Posts: 363
Loc: London, England
Thanks Shaneep your line of coding worked very well. I have used the second option as that looks neater. It does help knowing that one does not have to put the = 1 type statement.
Thanks guys. Now I am going to open up a new exciting thread which will hopefully challenge the finest brains out there lol !

Top
#206482 - 2012-12-13 10:43 PM Re: if exist within if exist statement [Re: Robdutoit]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Actually, it's much simpler. You're code was ok, but you forgot an EndIf:
 Code:
;=============================================================================================
; remove picture icon on Windows 7 login only if BackgroundDefault.jpg picture actually exists
;=============================================================================================

If exist ("%windir%\system32\oobe\Info\Backgrounds\BackgroundDefault.jpg") = 0
  ? "do not change the Windows 7 Login Look"
Else
  If exist ("%windir%\system32\authuiobsolete.dll") = 0
    shell 'takeown /a /f %SystemRoot%\System32\authui.dll'
    shell 'ICACLS %SystemRoot%\System32\authui.dll /Grant Administrators:F'
    ? "removing the Picture Icon on windows 7 login screen"
    move ("%windir%\system32\authui.dll") ("%windir%\system32\authuiobsolete.dll")
    copy ("\\" + $MyDomain + "\netlogon\patches\authui.dll") ("%windir%\system32\authui.dll")
  EndIf
EndIf ;<--- There's the puppy

Apart from that error, Shane's and Glenn's comments apply.
Funny how Shane fixed it but didn't mention it ;\)

Top
#206483 - 2012-12-13 11:24 PM Re: if exist within if exist statement [Re: Arend_]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
lol Probably because I didn't even use his original, just read his problem description and re-wrote it, copying and pasting the shell lines.
Top
#206484 - 2012-12-13 11:58 PM Re: if exist within if exist statement [Re: ShaneEP]
Robdutoit Offline
Hey THIS is FUN
***

Registered: 2012-03-27
Posts: 363
Loc: London, England
Hmm, maybe I should submit my code for syntax improvements. Perhaps one day when I have nothing to do, I will go over the script again and make the code a bit neater as it could do with some improvement.
I agree with Shane, it was just better to write the code neatly, as my coding was ok, but its not very neat and it makes it harder to read. Again thanks guys. I will remember that "not exist" option !

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2312 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.062 seconds in which 0.027 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org