Jump to content

Pass a variable


Recommended Posts

Hi,

I'd like to create a shell context menu command to create a desktop shortcut to a selected file. Here's what I have for an au3 script:

$target = "C:\users\paul\desktop\" & %1

FileCreateShortcut($target, %1)

And here's the command in the Registry:

"C:\utilities\AutoIt3\AutoIt3_x64.exe c:\systools\test.au3" %1

Win7 asks me what program I want to use to start the Selected file. Does anyone have a way to do this, or a better way to achieve what I want?

Thanks

p.

Link to comment
Share on other sites

Hi paul1149,

$i_pos = StringInStr(StringReplace($CmdLineRaw, '"', ""), "\",0,-1)
$file = StringMid(StringReplace($CmdLineRaw, '"', ""), $i_pos + 1)
$rc = FileCreateShortcut(StringReplace($CmdLineRaw, '"', ""), @DesktopDir & "\" & StringTrimRight($file,3) & "lnk")

First two lines are used to find only the filename from the full path.

With "%1" as parameter it seems I have a quote at the beginning of the string but not at the end. Maybe I#m doing it wrong or there's a better way to do it at all. :unsure:

Alternatively to $CmdLineRaw you could use $CmdLine[1] or $CmdLine[$cmdLine[0]].

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Link to comment
Share on other sites

Hi Hannes,

Thanks for that. I understand the string manipulation intuitively, but unfortunately, I'm not following the rest - specifically, how to get the file name into the $CmdLineRaw variable.

p.

Hi Paul,

The $CmdLineRaw and $CmdLine[x] variables / Constants are filled automatically when your script is started. You can look the helpfile under "Running Scripts" for further information.

:unsure:

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
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...