Sign in to follow this  
Followers 0
ndandy

How to retrieve shortcut name?

12 posts in this topic

If I launch a program by a shortcut (.lnk), how can I retrieve the shortcut name?

@scriptname return the .exe filename, not the .lnk

Share this post


Link to post
Share on other sites



How are you running it without knowing the shortcut name to begin with?

Share this post


Link to post
Share on other sites

How are you running it without knowing the shortcut name to begin with?

The user know the shortcut name,

but the application no :(

I need to retrieve the shortcut name that was used for launching the app.

Share this post


Link to post
Share on other sites

I'm not aware of an *easy* way to do what you are asking...

What are you seeking to accomplish in your program?

If you want to associate different actions of the same program between different shortcuts you can use "Command Line Parameters" in your shortcuts.

For example: a shortcut to "C:\pathto\program.exe" /dosomething

And in the script you can check $CmdLineRaw or $CmdLine[element]. See "Running Scripts" in the AutoIt Help File.


My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Share this post


Link to post
Share on other sites

Yes, this is the main problem!

I tried to use $CmdLineRaw, but probably it is for CUI, with my app(GUI) it returns

/AutoIt3ExecuteScript "filename.exe"

and I don't see params passed.

So I need to use the FileGetShortcut function to get params, but I need to know the .lnk filename

FileGetShortcut ( "lnk" )

Share this post


Link to post
Share on other sites

Hi,

you might use your app to let the user choose the LNK, and then launch it.

;only needed for _ArrayDisplay
#include <array.au3>
;Open Dialog with lnk filter
$lnk = FileOpenDialog ("Select Shortcut to run", @DesktopDir, "LNK (*.lnk)")
If $lnk <> "" Then
    ;if you need properties
    $arlnkprop = FileGetShortcut ($lnk)
    ;show properties
    _ArrayDisplay ($arlnkprop)
    ;Execute lnk
    ShellExecute ($lnk)
EndIf

Share this post


Link to post
Share on other sites

Why do you need it? As i know if you have Test.exe and create Shortcut, shortcut would just launch Test.exe and it would work from Test.exe dir. Shortcut is just a shorter way to your exe.

Share this post


Link to post
Share on other sites

Because with shortcut you can pass parameters to GUI app, but without have the shortcut name you cannot retrieve params with FileGetShortcut (probably).

Share this post


Link to post
Share on other sites

I'm pretty sure what you're asking for specifically can't be done.

Try this. Compile this script:

MsgBox(0, '', $CmdLineRaw)

Then run it from a shortcut with the target set as such ["c:\whatever the path to the file is\compiled.exe" "this is a parameter"]

The message box should say "this is a parameter" (including quotation marks).

Share this post


Link to post
Share on other sites

Ok, with your support I found the problem.

I used the AutoItErrorHandler_UDF, so when I include it $CmdLineRaw is:

/AutoIt3ExecuteScript "filename.exe"

instead without it, $CmdLineRaw returns the correct parameters.

Do I have to disable AutoItErrorHandler_UDF in order to read parameters?

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

It's possible, I'm not familiar with the AutoItErrorHandler_UDF.

*Edit: Although with a quick search I found this post: http://www.autoitscript.com/forum/index.php?showtopic=88420&st=0&p=635423&hl=AutoItErrorHandler_UDF%20&fromsearch=1&#entry635423

He seems to be handling the same issue you are, perhaps his tweak will help you?

Edited by RobSaunders

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