Page 1 of 1 1
Topic Options
#53370 - 2001-01-24 10:24 AM Suggestions required about this script
kncowans Offline
Getting the hang of it

Registered: 2000-11-11
Posts: 98
Loc: Doncaster, UK
Hello all

I have written this script (shown below) that checks if an application is running and displays a dialog box to inform the user to close the application down.

Everything works fine except that I want to find a way to compact the part of the script that checks for each Application.

Does anybody have any suggestions as to how I could achieve this?

Thanks in advance

Kevin

Del "C:\Apps.txt"

Shell "%ComSpec% /c %WinDir%\Kill.exe >C:\Apps.txt"

$Programs = ""

$Result = Close(1)

If Open(1,"C:\Apps.txt") = 0

$App = ReadLine(1)

While @Error = 0

$App = Readline(1)

If Instr( $App , "WinWord.exe" )

$Programs = "$Programs" + "Microsoft Word" + $LineBreak

Endif


If Instr( $App , "Excel.exe" )

$Programs = "$Programs" + "Microsoft Excel" + $LineBreak

Endif


If Instr( $App , "PowerPnt.exe" )

$Programs = "$Programs" + "Microsoft PowerPoint" + $LineBreak

Endif


If Instr( $App , "MSAccess.exe" )

$Programs = "$Programs" + "Microsoft Access" + $LineBreak

Endif


If Instr( $App , "IExplore.exe" )

$Programs = "$Programs" + "Microsoft Internet Explorer" + $LineBreak

Endif


If Instr( $App , "msimn.exe" )

$Programs = "$Programs" + "Microsoft Outlook Express" + $LineBreak

Endif

Loop

Endif

$Result = Close(1)

If $Programs <> ""

$Result = MessageBox("All programs must be Closed before Logging Off!" + $LineBreak + $LineBreak + "Close the following programs before Clicking on 'OK'" + $LineBreak + $LineBreak + "When you have finished, Click on OK and Select " + $LineBreak + "Logoff from the Start Menu" + $LineBreak + $LineBreak + "$Programs","System Information" , 4160)

Exit

Else

$Result = MessageBox("You will now be Logged Off the Network","System Information" , 4160 , 10)

Endif

_________________________
Kevin Cowans Senior ICT Technician The Armthorpe School

Top
#53371 - 2001-01-24 11:04 AM Re: Suggestions required about this script
DrillSergeant Offline
MM club member
*****

Registered: 2004-07-09
Posts: 1164
Loc: Eijsden, the Netherlands
How about this:

code:

Del "C:\Apps.txt"

Shell "%ComSpec% /c %WinDir%\Kill.exe >C:\Apps.txt"

$Programs = ""

$Result = Close(1)

If Open(1,"C:\Apps.txt") = 0
$App = ReadLine(1)
while @ERROR = 0
select
case instr( $App , "WinWord.exe" )
$Programs = "$Programs" + "Microsoft Word" + $LineBreak
case instr( $App , "Excel.exe" )
$Programs = "$Programs" + "Microsoft Excel" + $LineBreak
case instr( $App , "PowerPnt.exe" )
$Programs = "$Programs" + "Microsoft PowerPoint" + $LineBreak
case instr( $App , "MSAccess.exe" )
$Programs = "$Programs" + "Microsoft Access" + $LineBreak
case instr( $App , "IExplore.exe" )
$Programs = "$Programs" + "Microsoft Internet Explorer" + $LineBreak
case instr( $App , "msimn.exe" )
$Programs = "$Programs" + "Microsoft Outlook Express" + $LineBreak
case 1
; none of the above, no addition to $programs
endselect
$App = Readline(1)
Loop
Endif

$Result = Close(1)

If $Programs <> ""
$Result = MessageBox("All programs must be Closed before Logging Off!" +
$LineBreak + $LineBreak + "Close the following programs before Clicking on 'OK'" +
$LineBreak + $LineBreak + "When you have finished, Click on OK and Select " +
$LineBreak + "Logoff from the Start Menu" +
$LineBreak + $LineBreak + "$Programs","System Information" , 4160)
Exit
Else
$Result = MessageBox("You will now be Logged Off the Network","System Information" , 4160 , 10)
Endif


I have changed all the IF statements to a SELECT-CASE statement. Also the $apps=readline(1) should be at the end of the WHILE @ERROR=0 - LOOP loop.

The condition is checked when the LOOP command is reached. If you do a IF-ENDIF statement AFTER you do the READLINE, the @ERROR code returned will be the error code of the IF-ENDIF statement and NOT of the READLINE statement.

If you want to test this code, click on the edit-icon (pencil and paper) above this post and cut-and-paste the lines between CODE and /CODE.

------------------
Greetz,

Roger the Young
------------------------
The code is out there...
------------------------
http://home.wanadoo.nl/r.s.m.s.dejong/Kixtart

------------------------

[This message has been edited by DrillSergeant (edited 24 January 2001).]

_________________________
The Code is out there

Top
#53372 - 2001-01-24 11:09 AM Re: Suggestions required about this script
kncowans Offline
Getting the hang of it

Registered: 2000-11-11
Posts: 98
Loc: Doncaster, UK
Hello

Thanks for the tips, that is just what I was looking for.

I have not really got into using 'Case' as yet.

Bye for now

Kevin

_________________________
Kevin Cowans Senior ICT Technician The Armthorpe School

Top
Page 1 of 1 1


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

Who's Online
1 registered (Allen) and 581 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.049 seconds in which 0.023 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