Jump to content
Sign in to follow this  
royalmarine

run program until multiple conditions are met

Recommended Posts

royalmarine

Hi guys,

quick explanation on what im doing.

my program will run a program called securityApp.exe all the time.

when a usb is inserted with a certain ID, and when a ping response from an ip address of 192.168.1.2 is received,

the securityApp.exe is shutdown until either the usb device is removed or the ping response fails.

when the usb device is plugged in, a file on it is decrypted and text read and verified with that stored in the code.

it works at present in the sense that I plug the usb key in, it decrypts the file, pings the ip address, and when all 3 conditions are met, it will do something.

and likewise when the usb key is removed,

or when the ip address is no longer reachable.

how can i get the securityApp.exe to run all the time until these conditions are met?

ive tinkered with it long enough to come asking for help :/

code below

#include <Crypt.au3>
#include <USBDevice.au3>
While 1
   $aDrives = DriveGetDrive("Removable")
    For $i = 1 To UBound ( $aDrives ) -1
        $_Drive = $aDrives[$i]
        $id = _GetPNPDeviceID($aDrives[$i])
    Next
    Sleep ( 500 )
if WinExists("AutoPlay","Removable Disk") then WinClose("AutoPlay")
   ; auto closes the AutoPlay window from USB insertion
WEnd
; when device is inserted
Func sink_OnObjectReady($objObject, $objAsyncContext)
    Local $choice

    If $objObject.TargetInstance.DriveType = 2 Then
        Select
        Case $objObject.Path_.Class () = "__InstanceCreationEvent"
    
    
            if $id = "UNIQUEIDOFUSB" Then   
; if correct device
    
      Local $var = Ping("192.168.1.2", 250)
      If @error = 0 Then
; ping succesful
    
         _Crypt_DecryptFile("E:encrypt", "E:decrypt", "passowrd", $CALG_AES_256)
         ; decrypts the file called "encrypt", outputs to decrypt, using password and AES_256 algorithmn
         Local $file = FileOpen("E:decrypt", 0)
         ; reads the decrypt file into buffer
         local $line2 = "this line is required to match"
         ; variable to match the read file to
         Local $line = FileReadLine($file)
         ; Read in lines of text until the EOF is reached
    
;** Variables Match **;
         If $line == $line2 Then
         ;MsgBox(0, "Success", "Ping succesful, Correct Device Inserted, variables match")
         ;debug info
         Consolewrite("Drive " & $objObject.TargetInstance.DeviceId & " has been added." & @CR)
         Consolewrite("Ping succesful" & @CR)
         ConsoleWrite("file succesfully decrypted and variables match")
         processclose("securityApp.exe")
         FileClose($file)
         ; removes file from buffer
         FileDelete("E:decrypt")
         ; deletes the decrypted file
         FileRecycleEmpty("C:")
         ; empties the recycle bin
         sleep(500)
    
    
;** Variables Dont Match **;
         Else
         FileClose($file)
         ; removes file from buffer
         FileDelete("E:decrypt")
         ; deletes the decrypted file
         FileRecycleEmpty("C:")
         FileRecycleEmpty("E:")
         ; empties the recycle bin
         sleep(500)
    
         EndIf
      Else
; ping un-succesful
       sleep(500)
      EndIf 
; end if correct device
            Else
; if wrong device
       sleep(500)  
; end if wrong device  
            EndIf
; when device is removed
   Case $objObject.Path_.Class () = "__InstanceDeletionEvent"
  
   ;MsgBox(0, "device", "device removed")
   If (Not ProcessExists("securityApp.exe")) Then
      Run("securityApp.exe")
   Else
      Sleep(500)
   EndIf
   Case Else
   EndSelect
    EndIf
EndFunc
Edited by royalmarine

Share this post


Link to post
Share on other sites
royalmarine

would a do/until loop make the program open over and over until the condition is met?

e.g.

do

run("notepad.exe")

until

; condition is met.

Share this post


Link to post
Share on other sites
JohnQSmith

would a do/until loop make the program open over and over until the condition is met?

Yes


Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Share this post


Link to post
Share on other sites
Blinky

u can make 3 functions that veryfi usb id , data on the usb and ping and structure your script like this

Global $status=0
while 1
while $status=0
  if usb_id()=1 And key_file()=1 And pc_ping()=1 Then
   $status=1
  Else
   If (Not ProcessExists("securityApp.exe")) Then Run("securityApp.exe")
   Sleep(500) 
  EndIf
WEnd


while $status=1
  If ProcessExists("securityApp.exe") Then ProcessClose("securityApp.exe")
  if usb_id()=0 Or pc_ping()=0 Then $status=0
  Sleep(500)
WEnd
WEnd

Func usb_id()
If True Then
  Return 1
Else
  Return 0
EndIf
EndFunc

Share this post


Link to post
Share on other sites
Blinky

u can also use _StringEncript|() function to avoid use of other files

Share this post


Link to post
Share on other sites
BrewManNH

You wouldn't want to use the _StringEncrypt function, the encryption is pretty weak with it. Besides, you can't use the _StringEncrypt function without including the File.au3 UDF.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Blinky

@BrewManNH the _StringEncrypt is in the string.au3 and he can remove the crypt.au3 :)

i dont know very well these functions but i gues they use the same type of key encription and at the very best the stringEncript is way slower.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×