#206466 - 2012-12-13 04:35 PM
if exist within if exist statement
|
Robdutoit
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
if exist x = 0
? "do whatever"
else
Endif
Thats pretty straightforward
But what if you want to do this:
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:
;=============================================================================================
; 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
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.
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 ORIf 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
|
|
|
|
#206482 - 2012-12-13 10:43 PM
Re: if exist within if exist statement
[Re: Robdutoit]
|
Arend_
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:
;=============================================================================================
; 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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 2312 anonymous users online.
|
|
|