Page 1 of 1

Keep the app always active

Posted: Tue Nov 25, 2008 8:49 am
by alemrantareq
Hi everybody,

I wanna make a script that, while the stack is running, it always delete a text file named "test.txt" from C: drive any time if the text file is created into that drive. What message i've to use to do that? Is any other solution of it?

Posted: Tue Nov 25, 2008 10:15 am
by malte
Hi Tareq,

you will need to write a timer and poll for the existence of that file.

in a button

Code: Select all

on mouseUp
  set the flag of me to not the flag of me
  if the flag of me then startpolling
end mouseUp

on startPolling
  if there is a file "c:/path/to/your/file" then
    delete file "c:/path/to/your/file"
  end if
  if the flag of me then send "startPolling" to me in 100 millisecs
end startPolling
Hth,

Malte

Posted: Thu Nov 27, 2008 9:38 am
by alemrantareq
Hi malte,

Thanks for your reply. It really works. Now I face another problem & that is, the app always running in process even after closing. So I made a new stack with a button to close that application. I made a script of the new btn-

kill process "test.exe"

"test.exe" is the 1st app name. But i cant kill that process. How to do that?

Posted: Thu Nov 27, 2008 12:42 pm
by Janschenkel
The problem is that while your 'send in time' construct is still running, the application can only close the stack but won't quit the whole application, resulting in a faceless app eating up resources.
The technical term is 'the pendingMessages is not empty'

The easiest solution is to add the following bit to your stack script

Code: Select all

on closeStackRequest
  answer "Are you sure you want to close this application?" with "OK" or "Cancel"
  if it is "OK" then quit
end closeStackRequest
HTH,

Jan Schenkel.

Posted: Thu Dec 04, 2008 7:00 am
by alemrantareq
Hi Janschenkel,
Thanks for your reply. I've made a app for my pen drive with your script. As the app is always running, if any "autorun.inf" exists in my pen drive, it automatically delete it showing a message. It acts as a anti-virus for my pen drive. I really feel glad and thanks you again.

But I'm facing a little problem and that is, after safely removing of my pen drive, it shows a error message "There is no disk into the drive. Please insert a disk into the drive I:". Drive I: is my pen drive's letter. I can't cancel this error message as it always running.
I just try to find the way not to close my app but it'll never shows any error message after removing of that drive. Pls, I need your help....

Posted: Thu Dec 04, 2008 1:23 pm
by Janschenkel
You can always test 'the volumes' first to see if the 'I:' drive is still in there, and you should probably test first with 'if there is a file' before you try to read it.
So disable your own anti-virus executable for a minute and make a test stack with a button with the following script

Code: Select all

on mouseUp
  answer the volumes
  answer there is a file "I:autorun.inf"
end mouseUp
Plug in your stick and click on the button.
Then unplug your stick and click the button again.

If the second click doesn't result in a "There is no disk..." error message, then you can gleen a solution from the above test script.

HTH,

Jan Schenkel.

Posted: Fri Dec 05, 2008 12:46 pm
by alemrantareq
Hi Janschenkel,
Thanks for your reply. After making script with "If there is a file" for my pen drive, it works good and doesn't show the error message.. I've made a another script for my cd rom as there is also autorun.inf file exists some of the cds, they may hold virus. I've made the script -

Code: Select all

on mouseUp
set the flag of me to not the flag of me
  if the flag of me then startpolling
end mouseUp


on startPolling
  put "H:/autorun.inf" into tfile
  if there is a file tfile then
   answer "found"
  end if
 if the flag of me then send "startPolling" to me in 100 millisecs
end startPolling
H: is my cd drive. Porblem is that, after ejecting any cd, it continously shows that error message "There is no disk into the drive. Please insert a disk into the drive H:". In case of pen drive, as after safely removing the drive shows no more, it doesn't show that error message; but in case of cd drive, I face that problem again. Is there any solution to you? Thanks in advance....

Posted: Fri Dec 05, 2008 1:39 pm
by Janschenkel
A quick test on my machine doesn't show the same message. Perhaps someone with VBScript knowledge can find a better test to check if there is a CD in the drive...

Jan Schenkel.

Posted: Fri Dec 05, 2008 3:32 pm
by SparkOut
You can use a modified form of the WMI script from the other thread about interrogating drives:


set the following code as the custom property cVBScript of the button

Code: Select all

strComputer = "."
result = ""
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery ("SELECT * FROM Win32_LogicalDisk where drivetype = 5")
For Each objDisk in colDisks
  if objDisk.volumename <> "" or objDisk.volumeserialnumber <> "" then
    result = result & objDisk.DeviceID & vblf
  end if
Next
Set colDisks = nothing
Set objWMIService = nothing
That will return a drive letter for any onboard CD ROM or DVD ROM drives, if they have a disk inserted, which has a volume name or volume serial number (so an unreadable or blank recordable disk will not return a drive - but then they won't have an autorun.inf file to check for).

Code: Select all

on mouseUp 
   set the flag of me to not the flag of me 
   if the flag of me then startpolling 
end mouseUp 


on startPolling
   local tFile, tLoadedDriveList
   do the cVBScript of me as "vbscript"
   put the result into tLoadedDriveList
   repeat for each line tDrive in tLoadedDriveList
      put tDrive & "/autorun.inf" into tFile
      if there is a file tFile then
         answer "found"
         -- at this point, you may also want to
         set the flag of me to false
         -- to stop polling while you take action on finding an autorun.inf file
      end if
   end repeat
   if the flag of me then send "startPolling" to me in 100 millisecs 
end startPolling
Also bear in mind that this will not actually intercept the autorun.inf file and prevent it running, and if the autorun file is on the disk, then you won't be able to delete it, either, so this script is really a proof of concept in interrogation of drive contents, not a brute-force antivirus.

To globally prevent CD/DVD ROMS from autorunning, you can set the following registry key:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\CDRom with the value 0 to disable autorun (or 1 to re-enable it)