Sign in to follow this  
Followers 0
OiMunk

NewbQ: launching files with AutoIT:

11 posts in this topic

I'm trying to write a script that will automate WinRAR, but I'd like the Script to launch automatically when I click on a .rar file and then process that file. Ideally, Windows will use MyAU3WinRar.exe as the default for opening .rar file types, but I don't know if this is possible, since MyAU3WinRar.exe isn't actually a decompression program, but will itself launch WinRAR...

Is there a way to pass the name of the file opened to my script?

Any help starting out is much appreciated,

cheers

Share this post


Link to post
Share on other sites



This really isn't an AutoIt question but...

You could use (Search for this!) the _FileRegister UDF here on the forums to register .rar files to your executable. But its slightly tricky.

Or, you could check to see if WinRAR is active using If WinActive, close WinRar, and open your script.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I'm trying to write a script that will automate WinRAR, but I'd like the Script to launch automatically when I click on a .rar file and then process that file. Ideally, Windows will use MyAU3WinRar.exe as the default for opening .rar file types, but I don't know if this is possible, since MyAU3WinRar.exe isn't actually a decompression program, but will itself launch WinRAR...

Is there a way to pass the name of the file opened to my script?

Any help starting out is much appreciated,

cheers

Go into your control panel and click on Default Programs....change the default opening files type to your AutoIT program. There is a way to pass the file information from your script to WinRar. Goto the online documentation on AutoIT and read the File functions.

VR,

Div

Edited by Div

Share this post


Link to post
Share on other sites

Change the registry entries. Open Regedit, navigate to HKCR\.rar and see what you can see... Probaly would be under run, just change the default path, export them, and your script can do it using the native registry functions.

Share this post


Link to post
Share on other sites

Thanks for the replies, I might be a little over my head with this one.

Bert: this is very interesting, though I'm not clear on how to get the file name of the .rar into my script.

RegRead() is easy enough to use, but I'm not sure which key to read or use. Here's a few that looked promising, but I probably need to add some flags or something. I'll have to do a lot of research on the registry...

HKEY_CLASSES_ROOT\.rar "C:\Program Files\WinRAR\MyAU3WinRar.exe" "%1"

HKEY_CLASSES_ROOT\Applications\MyAU3WinRar.exe\shell\open\command "C:\Program Files\WinRAR\MyAU3WinRar.exe" "%1"

HKEY_CLASSES_ROOT\Applications\WinRAR.exe

HKEY_CLASSES_ROOT\WinRAR\shell\open\command "C:\Program Files\WinRAR\MyAU3WinRar.exe" "%1"

Div: the problem is that the script doesn't know which file launched it, I don't need to send data from the script to WinRAR (other than ControlSends, which is easy). Every time I launch the script, it's going to be a different .rar file.

Justin: I tried searching for _FileRegister , but it doesn't exist on the forums or on google. WinWaitActive is the easy way, but I need to minimize running processes, so something more elegant is in order.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I am in the process of creating a File Register/Associate UDF, but it will be months before it sticks it's head out. Way too long till I get it finished. But for now:

$key = "HKEY_CLASSES_ROOT\WinRAR"
$shelloption = "automate"
$shellcommand = '"D:\My Documents\MyProgram.exe "%1'
$shellname = "Automate WinRAR"

RegWrite ($key & "\Shell\" & $shelloption, "", "REG_SZ", $shellname)
RegWrite ($key & "\Shell\" & $shelloption & "\command", "", "REG_SZ", $shellcommand)

That will add Automate WinRAR to the context menu of a RAR file, still more to come on .zip and the like... :)

Edit:

Here you go! :)

Done!

$key = "HKEY_CLASSES_ROOT\WinRAR.ZIP"
$shelloption = "automate"
$shellcommand = '"D:\My Documents\MyProgram.exe "%1'
$shellname = "Automate WinRAR"

RegWrite ($key & "\Shell\" & $shelloption, "", "REG_SZ", $shellname)
RegWrite ($key & "\Shell\" & $shelloption & "\command", "", "REG_SZ", $shellcommand)

$key = "HKEY_CLASSES_ROOT\WinRAR.REV"
$shelloption = "automate"
$shellcommand = '"D:\My Documents\MyProgram.exe "%1'
$shellname = "Automate WinRAR"

RegWrite ($key & "\Shell\" & $shelloption, "", "REG_SZ", $shellname)
RegWrite ($key & "\Shell\" & $shelloption & "\command", "", "REG_SZ", $shellcommand)
Edited by Bert

Share this post


Link to post
Share on other sites

Those work nicely, I'll definitely use that for some of my apps.

I'm still hoping someone knows how to pass the filename of a clicked file to my script. When my script launches WinRAR to decompress, it needs to know what file triggered everything. Maybe because my script launches AFTER the .rar that triggered the script, there's no way to retroactively get this information.

I tried accessing HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\LastVisitedMRU but this gets the most recent dialog, not the most recent file.

Alas.

Share this post


Link to post
Share on other sites

Those work nicely, I'll definitely use that for some of my apps.

I'm still hoping someone knows how to pass the filename of a clicked file to my script. When my script launches WinRAR to decompress, it needs to know what file triggered everything. Maybe because my script launches AFTER the .rar that triggered the script, there's no way to retroactively get this information.

I tried accessing HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\LastVisitedMRU but this gets the most recent dialog, not the most recent file.

Alas.

As you can see, in the above examples. there is a "%1". That is the file being launched. Now, just use command line params to open your script (Look in the helpfile. :))

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

your patience is appreciated :)

that's the detail I was missing,

cheers

Edited by OiMunk

Share this post


Link to post
Share on other sites

Depending on what you're doing with your RAR files (I assume you're going after something fairly simple like just decompressing it into a folder) look at the commandline rar.exe in your WinRAR folder. It might be quicker to pass options directly to it then through the GUI.

Share this post


Link to post
Share on other sites

Good idea. For the moment, I need the GUI because the script does different things depending on what it 'sees' with PixelGetColor()

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  
Followers 0