2manyhats
(Fresh Scripter)
2005-09-07 12:55 AM
display progress or activity while installing or running a program

I have been having a heck of a time trying to figure out how to break a loop that displays information to the user that something is installing or running at a particular point in the login script. The ideal outcome would be to have the loop terminate upon the program finishing and then continue through the login script. Below is an example that I created when spybot is running or installing. Any help would be appreciated. If this has come up before then my apologies.

Kevin

do

$ = SetTitle ("/ ...Please Wait Spybot - Search & Destroy is Scanning for spyware! /")
Sleep (1)
$ = SetTitle ("- ...Please Wait Spybot - Search & Destroy is Scanning for spyware! -")
Sleep (1)
$ = SetTitle ("\ ...Please Wait Spybot - Search & Destroy is Scanning for spyware! \")
Sleep (1)
$ = SetTitle ("| ...Please Wait Spybot - Search & Destroy is Scanning for spyware! |")
Sleep (1)
AT (12,10) " ...Please Wait, @FULLNAME "
AT (14,10) " / Spybot - Search & Destroy is Scanning for spyware! /"

Sleep (1)
AT (12,10) " "
AT (14,10) "- Spybot - Search & Destroy is Scanning for spyware! -"

;Sleep (1)
AT (12,10) " "
AT (14,10) "\ Spybot - Search & Destroy is Scanning for spyware! \"

;Sleep (1)
AT (12,10) " "
AT (14,10) "| Spybot - Search & Destroy is Scanning for spyware! |"
Sleep (1)


Until $spybotfinished=1


LonkeroAdministrator
(KiX Master Guru)
2005-09-07 01:04 AM
Re: display progress or activity while installing or running a program

well...
first, I think the best way to deal with this is to display no info whatsoever.
let the install go on on itself hidden.
and even better, even keep your logonscript hidden.

now, if you really must have the console window open and you really really wanna show the user something...
you need to find out how to call the installer in such manner that it halts the script execution.
for many installers, simple shell line will do:
shell "%comspec% /c start /wait installer.exe"

but, for spybot, search the board or spybot technical articles.
think it's descriped in both.


Kdyer
(KiX Supporter)
2005-09-07 04:08 AM
Re: display progress or activity while installing or running a program

If you want to show a progress meter, there are examples using KiXForms (http://kixforms.org ) that should work fine.

Kent


2manyhats
(Fresh Scripter)
2005-09-07 04:37 AM
Re: display progress or activity while installing or running a program

Believe me I would rather run the program in the background and just go silent. The problem is these users don't want to wait for spybot to finish or think the script is locked up so they control alt delete and end the kix script. My users ar too smart for their own good! I need to have spybot finish the scan before the script completes since it draws near 100 cpu utilization. When I used the run command instead of the shell command spybot would lock up the pc if the user clicked on an app during the scan. The scan can take up to 3 minutes or longer on the old machines so there lies the problem. I thought about a logoff script but have no idea how to make it work with windows 98.

2manyhats
(Fresh Scripter)
2005-09-07 04:58 AM
Re: display progress or activity while installing or running a program

I appreciate the advice but I couldn't find anything on the site that pertained. Maybe they trimmed the fat since you were there last

Sealeopard
(KiX Master)
2005-09-07 05:48 AM
Re: display progress or activity while installing or running a program

Run the scan asynchroneously.

Richard H.Administrator
(KiX Supporter)
2005-09-07 09:07 AM
Re: display progress or activity while installing or running a program

There are three options that spring to mind:
  • Detach the spybot process and let it run in the background don't bother to inform the user.
  • Detach the spybot process and let it run, give the user something to watch while it it running.
  • Don't detach the spybot process, give the user something to watch while it is running.


Of these the first is the best option of course. To detach a process use "RUN", not "SHELL". You might also need to use the DOS shell "START" command to force the process to detach.

If you want to detach the process and display information to your user, you will need to use one of the process tracking UDFs to monitor it.

If you want to halt the main script, then you must start a seperate "progress" script before you call the spybot process. Your main script will then need to signal the progress script to stop by using the registry or a file or it might simply kill the progress script.


Chris S.
(MM club member)
2005-09-07 02:01 PM
Re: display progress or activity while installing or running a program

Quote:

The problem is these users don't want to wait for spybot to finish or think the script is locked up so they control alt delete and end the kix script.




Leave "Break Off" and your users won't be doing the end task thing too many times.


Radimus
(KiX Supporter)
2005-09-07 02:35 PM
Re: display progress or activity while installing or running a program

display "Spybot is currently scanning your computer, yada yada"
and detach it with a RUN statement

then use a While Loop around EnumProcess() around a 3-5 second delay. During each loop have it display a "." so it looks like progress.

It would look something like this: (not real code)

? "Spybot is currently scanning your computer"
run '"path to spybot.exe" /switches'
while enumprocess('spybot.exe')
'.'
sleep 5
loop


LonkeroAdministrator
(KiX Master Guru)
2005-09-07 02:45 PM
Re: display progress or activity while installing or running a program

anyways, the smartest thing I see here is to hide the sh*t.

use wkix32 instead of kix32 and keep it hidden.
I have ran hidden logonscripts with office installs and crap for years and my users never even realized it was a logonscript that did all the screwing around.


2manyhats
(Fresh Scripter)
2005-09-07 05:35 PM
Re: display progress or activity while installing or running a program

Thanks for the great idea but I must be missing something. The loop works but does not terminate when spybot finishes. Any ideas.

Kevin


LonkeroAdministrator
(KiX Master Guru)
2005-09-07 09:41 PM
Re: display progress or activity while installing or running a program

I would say you don't have enumprocess.

2manyhats
(Fresh Scripter)
2005-09-08 04:36 AM
Re: display progress or activity while installing or running a program

Lonkero' this is what I got. Also 'I am testing this code on a win9x machine. Does this make a difference? Anyway what do you think could be wrong? Spybotsd.exe is the process name under xp.

run "'C:\Progra~1\Spybot~1\SpybotSD.exe' /taskbarhide /autocheck /autofix /autoclose"
while enumprocess('spybotsd.exe')

AT (13,10) " ...Please Wait, @FULLNAME "
AT (15,10) " / Spybot - Search & Destroy is Scanning for spyware! / "

Sleep (1)
AT (13,10) " "
AT (15,10) "- Spybot - Search & Destroy is Scanning for spyware! - "

Sleep (1)
AT (13,10) " "
AT (15,10) "\ Spybot - Search & Destroy is Scanning for spyware! \ "

Sleep (1)
AT (13,10) " "
AT (15,10) "| Spybot - Search & Destroy is Scanning for spyware! | "
Sleep (1)

Loop


NTDOCAdministrator
(KiX Master)
2005-09-08 05:03 AM
Re: display progress or activity while installing or running a program

I would work on getting solid code working for Windows 2000/XP first. Then if required work and PRAY you can get it working as well on NT and Windows 9x which have much more limitations.

Mart
(KiX Supporter)
2005-09-08 09:33 AM
Re: display progress or activity while installing or running a program

You use enumprocess in your code so you would have to embed the EnumProcess() - enum specific process PIDs and/or terminate them UDF or at least do a call to it in your code. Did not see that happening up until now.

Without this UDF the While loop is not working cause enumprocess is not used properly.


Richard H.Administrator
(KiX Supporter)
2005-09-08 10:18 AM
Re: display progress or activity while installing or running a program

Win9x? You're not likely to have too much success with Win9x.

I've tidied your code up a little:
Code:
Break ON
Dim $sProgressChars,$iEnumProcess, $sSpybot

$sProgressChars="/-\|"
$sSpybot="spybotsd.exe"

At(13,10) " ...Please Wait, "+@FULLNAME

Run "'C:\Progra~1\Spybot~1\"+$sSpybot+"' /taskbarhide /autocheck /autofix /autoclose"
$iEnumProcess=EnumProcess($sSpybot)
While 0<$iEnumProcess
At(15,10) " "+Left($sProgressChars,1)+" ["+$iEnumProcess+"] Spybot - Search & Destroy is Scanning for spyware! "+Left($sProgressChars,1)+" "
Sleep(0.3)
$sProgressChars=SubStr($sProgressChars,2)+Left($sProgressChars,1)
$iEnumProcess=EnumProcess($sSpybots)
Loop



When running you should see the spybot.exe process number between the "[]" characters on the screen.

The problem with Win9x is that it has a completely different kernel, so it doesn't support all the process control that NT+ does.

You will need WMI installed on each machine as well for enumprocess() to work - WMI is not available on NT or Win9x as standard, you need to install an add-on.

If you cannot be sure of your clients, then here is a method which should work for all of them.

This requires two scripts. A progress script which just displays a progress bar on the screen and your main script which calls the progress script.

The main script will stop when it calls the SpybotSD, but the progress script will continue to update the screen.

When SpybotSD finished you main script will continue, at which point it tells the progress script to close down.

Here is an example:

PROGRESS.KIX
Code:
Break ON
Dim $sProgressChars,$vDiscard

; NB, $sKey, $sValue, $iX, $iY and $sTitle are passed on the command line

$sProgressChars="/-\|"

While ReadValue($sKey,$sValue)<>"STOP"
At($iX,$iY) Left($sProgressChars,1)+$sTitle+Left($sProgressChars,1)
Sleep(0.25)
$sProgressChars=SubStr($sProgressChars,2)+Left($sProgressChars,1)
Loop

; Remove value - lets main script know we've closed
$vDiscard=DelValue($sKey,$sValue)
Exit 0



MAIN.KIX
Code:
Break ON
$=SetOption("Explicit","ON")
CLS

Dim $sKeyPress,$vDiscard
Dim $sKey, $sValue, $sTitle, $iX, $iY

$sKey="HKCU\Software\KiXtart\ProgressBar"
$sValue=@TIME+"."+@MSECS
$sTitle="Spybot Seach & Destroy Scan in Progress"
$iX=15
$iY=(80-2-Len($sTitle))/2

; Start progress bar
RUN 'Kix32.exe "'+@SCRIPTDIR+'/progress.kix"'
+' $$sKey="'+$sKey+'"'
+' $$sValue="'+$sValue+'"'
+' $$iX="'+$iX+'"'
+' $$iY="'+$iY+'"'
+' $$sTitle="'+$sTitle+'"'

At(0,1) "Main script will now pause until you hit a key:" Get $sKeyPress

; Tell progress script to stop.
$vDiscard=WriteValue($sKey,$sValue,"STOP","REG_SZ")
While ReadValue($sKey,$sValue)="STOP" Sleep 0.1 Loop

CLS "Main script completed." ?



NTDOCAdministrator
(KiX Master)
2005-09-08 09:01 PM
Re: display progress or activity while installing or running a program

Richard,

Thanks for the code cleanup and explanations for Kevin.

I'm so glad we chose to add you as a Moderator. Think you're doing a great job.


2manyhats
(Fresh Scripter)
2005-09-09 04:53 AM
Re: display progress or activity while installing or running a program

Richard, I want to thank you for all the great advice and time you spent on my post. I did not have time to implement the code for main.kix or progress.kix yet but I did try the version of my originally submitted code that you cleaned up for me. The enumprocess part of the script worked since the loop started and stopped properly but, for some reason the name of the process immediately trails the end of the first line displayed on the screen listed below. Is this normal?

-------------------------------------------------
Code:
-------------------------------------------------


Lastly, the line below did not show at all. Wierd.

-------------------------------------------------
Code:
At(15,10) " "+Left($sProgressChars,1)+" ["+$iEnumProcess+"] Spybot - Search & Destroy is Scanning for spyware! "+Left($sProgressChars,1)+" "
-------------------------------------------------




Richard H.Administrator
(KiX Supporter)
2005-09-09 10:12 AM
Re: display progress or activity while installing or running a program

In that case you don't have EnumProcess() in your script.

EnumProcess() is a udf, not a KiXtart built-in.

You can find EnumProcess() here

You will need to copy it and paste it into your script - you can just tack it to the bottom of the script.

The process name is appearing on the screen because that is the default behaviour for KiXtart when it gets data it doesn't know how else to handle - like when a user defined function is not properly defined.

The message isn't displaying because the EnumProcess() call fails and the result is "empty" - this is effectively the same result as when the process you are monitoring has stopped.


2manyhats
(Fresh Scripter)
2005-09-25 06:26 AM
Re: display progress or activity while installing or running a program

Well I finally got back to this little project. I think mart must have been right. I must have done something wrong with enumprocess(). I just started over in a clean script. This snippit works, but is not as nice as your code, Richard. I had problems getting your code to work and am still trying to figure out why. I will eventually.

I had to terminate cmd.exe since I guess enumprocess passes the window from kix32 to a dos shell. At least that's what it looks like. I tried to call other scripts after the enumprocess and the called scripts did execute but I still needed to terminate cmd.exe. This is what I came up with.

Code:
  
run "C:\Program Files\Spybot - Search & Destroy\spybotsd.exe /taskbarhide /autoupdate /autoclose"
cls
While enumprocess('spybotsd.exe')
$ = SetTitle ("/ ...Please Wait Spybot - Search & Destroy is Scanning for
spyware! /")
AT (13,10) " ...Please Wait, @FULLNAME "
AT (15,10) "/ Spybot - Search & Destroy is Scanning for spyware! / "
Sleep(0.1)
$ = SetTitle ("- ...Please Wait Spybot - Search & Destroy is Scanning for
spyware! -")
AT (13,10) " "
AT (15,10) "- Spybot - Search & Destroy is Scanning for spyware! - "
Sleep(0.1)
$ = SetTitle ("\ ...Please Wait Spybot - Search & Destroy is Scanning for
spyware! \")
AT (13,10) " "
AT (15,10) "\ Spybot - Search & Destroy is Scanning for spyware! \ "
Sleep(0.1)
$ = SetTitle ("| ...Please Wait Spybot - Search & Destroy is Scanning for
spyware! |")
AT (13,10) " "
AT (15,10) "| Spybot - Search & Destroy is Scanning for spyware! | "
Sleep(0.1)
loop
enumprocess(cmd.exe,1)



Sealeopard
(KiX Master)
2005-09-25 03:25 PM
Re: display progress or activity while installing or running a program

Instead of repeating the whole string over and over again, you should only display the |/-\|/-\ characters.

Shaba1
(Fresh Scripter)
2005-10-24 10:27 PM
Re: display progress or activity while installing or running a program

Could this script use the $progressbar function of kixforms

Mart
(KiX Supporter)
2005-10-24 10:33 PM
Re: display progress or activity while installing or running a program

Not outside kixforms. You'll need to build a kixforms GUI and inplement it in it.

Shaba1
(Fresh Scripter)
2005-10-25 12:46 AM
Re: display progress or activity while installing or running a program

Quote:

Not outside kixforms. You'll need to build a kixforms GUI and inplement it in it.



Of course that is what I mean. If I understood you correctly. My question would be how would one send "messages" (If that is the correct word/term) between spybot as it scans and the progress bar to make it increment. I know spybot display a ratio of a kind with the number of malware items that it has scanned vs. the number that it can detect on its status bar. But I could see no way of getting those number to the progress bar.