Jump to content

Help with Run and Command Line Switches


Recommended Posts

Hi everyone,

I want to run the following command:

C:\Program Files\TrueCrypt\TrueCrypt.exe /d "C:\Program Files\Agent\Data\Data"

This is my code:

$truecrypt = "C:\Program Files\TrueCrypt\TrueCrypt.exe"; Location of TrueCrypt installation
$volume = "C:\Program Files\Agent\Data\Data"; Location of TrueCrypt volume

Run ( $truecrypt "/d" $volume )

Exit

Can someone point out to me why this isn't working?

Thanks.

Edited by romulous
Link to comment
Share on other sites

Hi everyone,

I want to run the following command:

C:\Program Files\TrueCrypt\TrueCrypt.exe /d "C:\Program Files\Agent\Data\Data"

This is my code:

$truecrypt = "C:\Program Files\TrueCrypt\TrueCrypt.exe"; Location of TrueCrypt installation
$volume = "C:\Program Files\Agent\Data\Data"; Location of TrueCrypt volume

Run ( $truecrypt "/d" $volume )

Exit

Can someone point out to me why this isn't working?

Thanks.

Run ( $truecrypt & "/d" & $volume )

When the words fail... music speaks.

Link to comment
Share on other sites

Run ( $truecrypt & "/d" & $volume )
Thanks, I will try that out. A general question on passing command lines via AutoIt, if I wanted to issue the following command:

TrueCrypt.exe /l Z /c n /h n /q /m rm /m ts /v "C:\Program Files\Agent\Data\Data"

how would I do it? The comspec bit in the AutoIt helpfile is confusing and there is more than one command line switch, so I don't know if the above method would work on it.

Link to comment
Share on other sites

Thanks, I will try that out. A general question on passing command lines via AutoIt, if I wanted to issue the following command:

TrueCrypt.exe /l Z /c n /h n /q /m rm /m ts /v "C:\Program Files\Agent\Data\Data"

how would I do it? The comspec bit in the AutoIt helpfile is confusing and there is more than one command line switch, so I don't know if the above method would work on it.

Hm, ok - that bit of code didn't work. The volume is still mounted (/d un-mounts the volume in TrueCrypt).

Link to comment
Share on other sites

Thanks, I will try that out. A general question on passing command lines via AutoIt, if I wanted to issue the following command:

TrueCrypt.exe /l Z /c n /h n /q /m rm /m ts /v "C:\Program Files\Agent\Data\Data"

how would I do it? The comspec bit in the AutoIt helpfile is confusing and there is more than one command line switch, so I don't know if the above method would work on it.

ShellExecute() or _RunDOS().

When the words fail... music speaks.

Link to comment
Share on other sites

Thanks, I will try ShellExecute, and I will try it also for the /d parameter command to see if it works.

CM

Sigh - why oh why oh why can't AutoIt have a 'parameter' part of its commands like it does for working directory? ShellExecute doesn't work either because (I think) AutoIt is not passing the path to the volume to TrueCrypt.

ShellExecute ( $truecrypt, "/d" $volume )

doesn't work, and neither does

ShellExecute ( $truecrypt, "/d" & $volume )

What AutoIt needs is an addition like this:

RunWait ( "filename" [, "workingdir" [, "command line switches" [, flag]]] )

(and same addition to the Run command also.)

The only way I can get this to work by the looks of it is to create a batch file as such (just the single line):

TrueCrypt.exe /d "C:\Program Files\Agent\Data\Data"

save it as C:\Program Files\Agent\Data\Dismount.bat and then insert the following into the script:

Run ( "C:\Program Files\Agent\Data\Dismount.bat" )

What an awful, awful hack.

Edited by romulous
Link to comment
Share on other sites

Try this:

#include <Process.au3>
$truecrypt = "C:\Program Files\TrueCrypt\TrueCrypt.exe"
$volume = "C:\Program Files\Agent\Data\Data"
_RunDOS($truecrypt & " /d " & $volume)
Ok thanks, will do. One last (hopefully) stupid question:

ShellExecute ( $truecrypt, "/l Z /c n /h n /q /m rm /m ts /v" & $volume )

With the line above, is there any reason why the '& $volume' would not be being included as part of the command line AutoIt passes to TrueCrypt? I also tried the '$volume' inside the "", but that didn't work either.

CM

Link to comment
Share on other sites

You have this:

ShellExecute ( $truecrypt, "/l Z /c n /h n /q /m rm /m ts /v" & $volume )

Try this:

ShellExecute ( $truecrypt, "/l Z /c n /h n /q /m rm /m ts /v " & $volume )
Hm, when I run the script, the TrueCrypt 'enter volume password' dialog pops up (how it is supposed to be), I enter the password for the volume, and then I get a TrueCrypt error:

The system cannot find the path specified.

Unfortunately it doesn't say which path it is looking for. It must be the path to $volume I think - if I change the command to include the hardcoded path:

ShellExecute ( $truecrypt, "/l Z /c n /h n /q /m rm /m ts /v C:\Program Files\Agent\Data\Data" )

I get the same error. I think the spaces in "Program Files" might be the problem (that command line works fine if you run it from a Windows command prompt - I do put the " marks around the path when doing it this way though). Does ShellExecute accept double " marks (so instead of passing C:\Program Files\Agent\Data\Data on the command line, AutoIt passes "C:\Program Files\Agent\Data\Data")?

Link to comment
Share on other sites

I forgot about the quotes, but this should fix it.

ShellExecute ( $truecrypt, '/l Z /c n /h n /q /m rm /m ts /v "' & $volume & '"')
:P Yes, it certainly does - thank you!

Andreik: the volume line in my script was:

$volume = "C:\Program Files\Agent\Data\Data"; Location of TrueCrypt volume

That was the one where it wasn't working - was that what you meant?

Link to comment
Share on other sites

:P Yes, it certainly does - thank you!

Andreik: the volume line in my script was:

$volume = "C:\Program Files\Agent\Data\Data"; Location of TrueCrypt volume

That was the one where it wasn't working - was that what you meant?

Is exactly what TheDarkEngineer write but I said to put between ' ' $volume before use in function.

PS: If you solve your problem is ok.

When the words fail... music speaks.

Link to comment
Share on other sites

Is exactly what TheDarkEngineer write but I said to put between ' ' $volume before use in function.

PS: If you solve your problem is ok.

Ah, I understand now - thank you. Yes, things seem to be working ok now, thanks everybody :P

CM

Link to comment
Share on other sites

It seems that I spoke too soon. This is the entire script:

$agent = "C:\Program Files\Agent\Agent.exe"; Location of Forte Agent installation
$drive = DriveStatus ( "Z:\" ); Checks to see if TrueCrypt volume is mounted and assigns result to $var
$truecrypt = "C:\Program Files\TrueCrypt\TrueCrypt.exe"; Location of TrueCrypt installation
$volume = "C:\Program Files\Agent\Data\Data"; Location of TrueCrypt volume

; IF loop that checks $var status: if 'ready' it runs Agent, otherwise it mounts the TrueCrypt volume and then runs Agent
If $drive = "READY" Then
    RunWait ( $agent, "Z:\Data\" ); Runs Agent with Z:\Data as the working directory, and waits until Agent is closed
    ShellExecute ( $truecrypt, "/d Z /q" ); After Agent has closed, runs TrueCrypt to dismount volume
Else
    ShellExecute ( $truecrypt, '/l Z /c n /h n /q /m rm /m ts /v "' & $volume & '"'); Runs TrueCrypt to mount the volume
    RunWait ( $agent, "Z:\Data\" ); Runs Agent with Z:\Data as the working directory, and waits until Agent is closed
    ShellExecute ( $truecrypt, "/d Z /q" ); After Agent has closed, runs TrueCrypt to dismount volume
EndIf

Exit

When I run it, I simultaneously receive an error message from TrueCrypt that it can't dismount the volume (not surprising, as the volume is not mounted in the first place), and a prompt from TrueCrypt to mount the volume. So, running without the volume mounted, obviously the second part of the IF statement (under ELSE) is being run. Why then are the two ShellExecute's being run at the same time? I can't work it out, especially as the middle line (the line to run Agent) is not being run.

CM

Link to comment
Share on other sites

Strange. Script works fine if I change the first ShellExecute to ShellExecuteWait:

$agent = "C:\Program Files\Agent\Agent.exe"; Location of Forte Agent installation
$drive = DriveStatus ( "Z:\" ); Checks to see if TrueCrypt volume is mounted
$truecrypt = "C:\Program Files\TrueCrypt\TrueCrypt.exe"; Location of TrueCrypt installation
$volume = "C:\Program Files\Agent\Data\Data"; Location of TrueCrypt volume

; IF loop that checks $var status: if 'ready' it runs Agent, otherwise it mounts the TrueCrypt volume and then runs Agent
If $drive = "READY" Then
    RunWait ( $agent, "Z:\Data\" ); Runs Agent with Z:\Data as the working directory, and waits until Agent is closed
    ShellExecute ( $truecrypt, "/d Z /q" ); After Agent has closed, runs TrueCrypt to dismount volume
Else
    ShellExecuteWait ( $truecrypt, '/l Z /c n /h n /q /m rm /m ts /v "' & $volume & '"'); Runs TrueCrypt to mount the volume
    RunWait ( $agent, "Z:\Data\" ); Runs Agent with Z:\Data as the working directory, and waits until Agent is closed
    ShellExecute ( $truecrypt, "/d Z /q" ); After Agent has closed, runs TrueCrypt to dismount volume
EndIf

Exit

Bizarre.

Link to comment
Share on other sites

Your script runs so fast that the Truecrypt program is started and a couple of milliseconds go by and the next line is run. But the program hasn't loaded as it takes a second or so to start. So you have to wait for the shell to execute, then do the next line.

Trust me to make SkyNet with AutoIt...

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...