Eric Stewart
(Fresh Scripter)
2005-10-05 01:30 AM
Run batch file if file missing

Hello all,

I am trying to add to my login script a check to see if a file exist on the users desktop. If the file is not there, I need it to run a batch file. I assume this would be some sort of IF statement but I am unsure of how to reference the file I am looking for (RsiKron.ws) in the current users' desktop.

Thanks
Eric


StarwarsKid
(Seasoned Scripter)
2005-10-05 01:42 AM
Re: Run batch file if file missing

Eric,

There is a great How To by Kent Dyer on common file and directory locations.
http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=81615&an=0&page=2#81615

In order to check the existance of your desktop file you would want to do something like this.
Code:
 
$CUdesktop = READVALUE("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Desktop") ; For current user desktop
$LMdesktop = READVALUE("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Common Desktop") ; for Common desktop

IF NOT EXIST($CUDesktop+'\RsiKron.ws')
SHELL "%COMSPEC% /E:1024 /C " + @LDRIVE + "\SOMEBATCH.BAT" ; @LDRIVE or other location
ENDIF




I haven't tested this code yet.


Eric Stewart
(Fresh Scripter)
2005-10-05 06:47 PM
Re: Run batch file if file missing

Thanks. I'll take a look at the link.

NTDOCAdministrator
(KiX Master)
2005-10-05 07:11 PM
Re: Run batch file if file missing

Here is an example for you.

Break On
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('NoMacrosInStrings','On')

Dim $HKCUShell,$UDesktop,$FileToFind
$HKCUShell = 'HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders'
$UDesktop = ExpandEnvironmentVars(ReadValue($HKCUShell,'Desktop'))
$FileToFind = 'RsiKron.ws'

If Exist($UDesktop+'\'+$FileToFind)
;File found so nothing to do
Else
;File not found so we will now launch the batch file
RUN '%COMSPEC% /c /e:1024 C:\UTILS\MYBATCH.BAT'
EndIf



Les
(KiX Master)
2005-10-05 08:00 PM
Re: Run batch file if file missing

Hmmm... not sure about the SHELL line.

Why the extra enviro space?
Would it not need the /c switch?

Also, he said he wanted to RUN a BATch file.


NTDOCAdministrator
(KiX Master)
2005-10-05 08:47 PM
Re: Run batch file if file missing

Okay, updated. Yes, missed the /c
The extra environment space may or may not be needed. Some DOS items are hogs and this can help overcome an out of environment space error. No harm, no foul by using it but my guess is that just about anything they're running with this batch file can be run just as well if not better using KiXtart coding instead.
 


Eric Stewart
(Fresh Scripter)
2005-10-05 09:03 PM
Re: Run batch file if file missing

Thanks for all the help! It is working perfectly now.

Eric