Jump to content

executing and killing two processses with this script.


 Share

Recommended Posts

Hi There,

So, I'm not an expert when it comes to coding and I have been using AutoIT with a basic script given by one of my friend. I was using it with only one application execution at a time. Now I'm struggling to set two. 

For example, below scripts checks and mounts my secure partition by assigning a drive letter (upon typing my password at the prompt). Once the partition is mounted, the script will run the Google drive application (this is to avoid application turning on before partition is available). 

Mount Script

#AutoIt3Wrapper_icon=lock.ico
#include"_TC.au3"
_TC_Path("C:\Program Files\TrueCrypt\TrueCrypt.exe")

$result=True
if DriveStatus("S:\")<> "INVALID" Then ;Check if we're already mounted
    $result=True
else
    $result =_TC_Mount("C:\SecureDrive\SecDrive.tc","S")
EndIf

If $result = True Then

    $PID = ProcessExists("googledrivesync.exe") ; Will return the PID or 0 if the process isn't found.
    If not $PID Then
        $result= Run ("C:\Program Files\Google\Drive\googledrivesync.exe")
        if not $result then MsgBox(0,"Error", "Could not load GoogleDrive",5)
    EndIf

Else
   MsgBox(0,"Mount Cancelled","Secure Partition has not been mounted.",1)
EndIf

Unmount Script

#include"_TC.au3"
_TC_Path("C:\Program Files\TrueCrypt\TrueCrypt.exe")

$result=True

$PID = ProcessExists("googledrivesync.exe") and ; Will return the PID or 0 if the process isn't found.
If $PID Then $result=ProcessClose($PID)

If not $result Then
   MsgBox(0,"Unmount Aborted","Could not shutdown properly")
Else
    ;Stop the indexing service as we use this primarily for items on secure drive
    $result = RunWait(@ComSpec & " /c " & 'sc stop wsearch', "", @SW_HIDE)

   if DriveStatus("S:\")<> "INVALID" Then
      $result =_TC_UnMount("S",1)
      if not $result then MsgBox(0,"Error Unmounting","An error occured unmounting the secure drive")
   Else
      MsgBox(0,"Secure Partition Not Found","It appears as if the secure partition is not mounted",2)
   EndIf
EndIf

What I'm trying to achieve here is, add one more .exe process execute during mount and kill during unmount... with the current script above, I will add dropbox as my second process.

I'm quiet unsure how to add this. Appreciate any help on this.

Link to comment
Share on other sites

Link to comment
Share on other sites

On 1/1/2021 at 8:12 PM, Nine said:

What is the full path/name of the drop box exe ?

Add a run and an error handling after the run statement.  Try something, and post full code if that does not work.

I'm not sure if I'm following you... I'm trying to add two apps on the same code... above is what I use...

Link to comment
Share on other sites

For Google Drive the full path/name is "C:\Program Files\Google\Drive\googledrivesync.exe"

I am asking you the same thing for Drop Box, what is it ?  Because if you want to check if the process exists, you need the name of the exe, right ?

Link to comment
Share on other sites

Maybe this :

#AutoIt3Wrapper_icon=lock.ico
#include"_TC.au3"
_TC_Path("C:\Program Files\TrueCrypt\TrueCrypt.exe")

$result = True
If DriveStatus("S:\") <> "INVALID" Then ;Check if we're already mounted
  $result = True
Else
  $result = _TC_Mount("C:\SecureDrive\SecDrive.tc", "S")
EndIf

If $result Then
  $PID = ProcessExists("googledrivesync.exe")   ; Will return the PID or 0 if the process isn't found.
  If Not $PID Then
    $result = Run("C:\Program Files\Google\Drive\googledrivesync.exe")
    If Not $result Then Exit MsgBox(0, "Error", "Could not load GoogleDrive", 5)
  EndIf
  $PID = ProcessExists("SkyDrive.exe")
  If Not $PID Then
    $result = Run("C:\Users\Admin\AppData\Local\Microsoft\OneDrive\SkyDrive.exe")
    If Not $result Then Exit MsgBox(0, "Error", "Could not load OneDrive", 5)
  EndIf
Else
  MsgBox(0, "Mount Cancelled", "Secure Partition has not been mounted.", 1)
EndIf

I will leave you the pleasure of doing the unmount counterpart.  

Link to comment
Share on other sites

Hey.. thank you so much, that worked. however I tried unmount part as below but it only closes the onedrive not the googledrivesync... any idea why?

#include"_TC.au3"
_TC_Path("C:\Program Files\TrueCrypt\TrueCrypt.exe")





$result=True


$PID = ProcessExists("googledrivesync.exe") ;
If $PID Then $result=ProcessClose($PID)

$PID = ProcessExists("OneDrive.exe") ;
If $PID Then $result=ProcessClose($PID)

If not $result Then
   MsgBox(0,"Unmount Aborted","Could not shutdown properly")
Else
    ;Stop the indexing service as we use this primarily for items on secure drive
    $result = RunWait(@ComSpec & " /c " & 'sc stop wsearch', "", @SW_HIDE)

   if DriveStatus("S:\")<> "INVALID" Then
      $result =_TC_UnMount("S",1)
      if not $result then MsgBox(0,"Error Unmounting","An error occured unmounting the secure drive")
   Else
      MsgBox(0,"Secure Partition Not Found","It appears as if the secure partition is not mounted",2)
   EndIf
EndIf

 

Link to comment
Share on other sites

You got the process name wrong.  Check carefully my code...

Also the first $result is erased by the second, careful about that you are missing a possible error there !

Finally you do not check result of RunWait, you should to get a robust script.

Edited by Nine
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...