Page 1 of 1 1
Topic Options
#149238 - 2005-10-05 01:30 AM Run batch file if file missing
Eric Stewart Offline
Fresh Scripter

Registered: 2003-04-16
Posts: 9
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

Top
#149239 - 2005-10-05 01:42 AM Re: Run batch file if file missing
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
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.
_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
#149240 - 2005-10-05 06:47 PM Re: Run batch file if file missing
Eric Stewart Offline
Fresh Scripter

Registered: 2003-04-16
Posts: 9
Thanks. I'll take a look at the link.
Top
#149241 - 2005-10-05 07:11 PM Re: Run batch file if file missing
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11589
Loc: CA
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



Edited by NTDOC (2005-10-05 08:45 PM)

Top
#149242 - 2005-10-05 08:00 PM Re: Run batch file if file missing
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#149243 - 2005-10-05 08:47 PM Re: Run batch file if file missing
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11589
Loc: CA
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.
 

Top
#149244 - 2005-10-05 09:03 PM Re: Run batch file if file missing
Eric Stewart Offline
Fresh Scripter

Registered: 2003-04-16
Posts: 9
Thanks for all the help! It is working perfectly now.

Eric

Top
Page 1 of 1 1


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

Who's Online
0 registered and 134 anonymous users online.
Newest Members
eltonfaturetto, janvda, OBIns, kookken, larisa
17706 Registered Users

Generated in 0.04 seconds in which 0.016 seconds were spent on a total of 12 queries. Zlib compression enabled.

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