Jump to content

[Solved] Is It Possible to Get The Name of the Shortcut that Called the .au3 Script?


Recommended Posts

Hi all


Assume that I created a Script called NiceScript.au3.

If I want to get the name of the script in Runtime, I can use @ScriptName,
and it will return "NiceScript.au3" in this case.


Now assume that I created a Shortcut, pointing to NiceScript.au3,
and I clicked the Shortcut.

Is it possible for my script to get the Name of the Shortcut that called the script?


Thank you

Edited by Zohar
Link to comment
Share on other sites

Thank you very much to both of you,
I will check these 2 options now.

It seems that AutoIt also has a FileCreateShortcut() function,
so If I go the second route (Nine's way), then FileCreateShortcut() can help me programatically create the Shortcuts that I need, with the different Parameters in them.

 

BTW:

1 hour ago, Nine said:

Simply pass a parameter to the au3 script.  Read it with CmdLine array.

Is it possible to pass Parameters even to a .au3 script? (not only to Compiled to .EXE scripts?)

Link to comment
Share on other sites

25 minutes ago, Zohar said:

Is it possible to pass Parameters even to a .au3 script?

Yes !

In your shortcut, set :

[Path to your AutoIt3.exe] [Path to your .au3] ["Parameter"]

Example : C:\AutoIt\AutoIt3\AutoIt3.exe "C:\AutoIt\Projekte\Test.au3"  "Parameter1"

Test.au3 :

If $CMDLINE[0] Then
    MsgBox(0, "","Parameter 1 = " & $CMDLINE[1] & @CRLF)
Else
    MsgBox(0, "","no parameters" & @CRLF)
EndIf

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

@Deye

interesting approach.

Returns an $tagSTARTUPINFO structure that contains the startup information.

But how to grab the content returend by that function _WinAPI_GetStartupInfo() ?

#include <WinAPISys.au3>

$STARTUPINFO = _WinAPI_GetStartupInfo()
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $tagSTARTUPINFO = ' & $tagSTARTUPINFO & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
ConsoleWrite("VarType = " & VarGetType($STARTUPINFO) & @CRLF)
ConsoleWrite("$STARTUPINFO = '" & $STARTUPINFO & "'" & @CRLF)
>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\temp\Get-my-startingLNK.au3" /UserParams    
+>13:18:10 Starting AutoIt3Wrapper v.18.708.1148.0 SciTE v.4.1.0.0   Keyboard:00000407  OS:WIN_10/  CPU:X64 OS:X64  Environment(Language:0407)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\admin.AD\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\admin.AD\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:C:\temp\Get-my-startingLNK.au3
+>13:18:10 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\temp\Get-my-startingLNK.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
@@ Debug(6) : $tagSTARTUPINFO = dword Size;ptr Reserved1;ptr Desktop;ptr Title;dword X;dword Y;dword XSize;dword YSize;dword XCountChars;dword YCountChars;dword FillAttribute;dword Flags;word ShowWindow;word Reserved2;ptr Reserved3;handle StdInput;handle StdOutput;handle StdError
>Error code: 0
VarType = DLLStruct
$STARTUPINFO = ''
+>13:18:10 AutoIt3.exe ended.rc:0
+>13:18:10 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 0.8752

 

VarType = "DLLStruct" 🤔

 

MSDN is giving this information, no clue, how to make use of this info:

https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/ns-processthreadsapi-startupinfoa

Syntax
C++

Copy
typedef struct _STARTUPINFOA {
  DWORD  cb;
  LPSTR  lpReserved;
  LPSTR  lpDesktop;
  LPSTR  lpTitle;
  DWORD  dwX;
  DWORD  dwY;
  DWORD  dwXSize;
  DWORD  dwYSize;
  DWORD  dwXCountChars;
  DWORD  dwYCountChars;
  DWORD  dwFillAttribute;
  DWORD  dwFlags;
  WORD   wShowWindow;
  WORD   cbReserved2;
  LPBYTE lpReserved2;
  HANDLE hStdInput;
  HANDLE hStdOutput;
  HANDLE hStdError;
} STARTUPINFOA, *LPSTARTUPINFOA;

 

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

14 minutes ago, rudi said:

But how to grab the content returend by that function

#include <WinAPISys.au3>
#include <WinAPIDiag.au3>

$tInfo = _WinAPI_GetStartupInfo()
_WinAPI_DisplayStruct($tInfo, $tagSTARTUPINFO, "Startup Info")
$tTitle = DllStructCreate("wchar string[256]", $tInfo.Title)
MsgBox ($MB_SYSTEMMODAL, "", $tTitle.string)

 

Link to comment
Share on other sites

@Nine I see, that it's working, but I miss what's going on behind the scenes, and I have no clue at all how I could have found the information how to do that code.

 

#include <Debug.au3>
#include <WinAPISys.au3>
#include <WinAPIDiag.au3>

$tInfo = _WinAPI_GetStartupInfo()
_WinAPI_DisplayStruct($tInfo, $tagSTARTUPINFO, "Startup Info")
$tTitle = DllStructCreate("wchar string[256]", $tInfo.Title)
; Q1: How do you know that "wchar string[256]" is the appropriate 1st parameter?

_WinAPI_DisplayStruct($tTitle)
; Q2: what does this display? every "even" element # is "0", and all "odd" element numbers, except offset 510, hold numbers !=0 ?
; Q3: how to figure out, what is here the right 2nd paramter for _WinAPI_DisplayStruct, like $tagSTARTUPINFO ?

MsgBox($MB_SYSTEMMODAL, "", $tTitle.string)

$aMembers = StringSplit("Size|Reserved1|Desktop|Title|X|Y|XSize|YSize|XCountChars|YCountChars|FillAttribute|Flags|ShowWindow|Reserved2|Reserved3|StdInput|StdOutput|StdError", "|", 2)
_DebugArrayDisplay($aMembers)


#cs ; this doesn't work: 
    ; Q3: Howto loop through "Object-Member-Elements" by using variables?
    for $Member in $aMembers
    ConsoleWrite("$Member = " & $Member & @CRLF)
    $tTitle=DllStructCreate("wchar string[256]", $tInfo.$Member)
    _WinAPI_DisplayStruct($tTitle)
    Next
#ce

 

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

Q1 :  as you posted, title is LPSTR, which mean a ptr to a string.  Wchar is usually what we use and 256 is just a usual lenght.  Anyway all strings are ended by a 0 character.

Q2 : it shows the content of a struct to learn more easily what is in it

Q3 : you need to provide the structure definition as the second parameter otherwise it will show (almost) useless info

Since title is wchar, it uses 16 bits per char

Link to comment
Share on other sites

ad Q1: Tx for the explanation. Why is that string holdig far more 2-byte-characters, than the length of the path presented by $tTitle.string ?

 

ad Q3: this doesn't work. but from the info retrieved earlier I *DO* know at least a bit of the structure:

 

$aMembers = StringSplit("Size|Reserved1|Desktop|Title|X|Y|XSize|YSize|XCountChars|YCountChars|FillAttribute|Flags|ShowWindow|Reserved2|Reserved3|StdInput|StdOutput|StdError", "|", 2)
_DebugArrayDisplay($aMembers)


; this does not work: 
; Q3: Howto loop through "Object-Member-Elements" by using variables?
for $Member in $aMembers
    ConsoleWrite("$Member = " & $Member & @CRLF)
    $tTitle=DllStructCreate("wchar string[256]", $tInfo.$Member) ; is there a possibility to address "Object members" by using variables to address them?
    _WinAPI_DisplayStruct($tTitle)
Next

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

adQ1 Like I already said, actual strings are terminated by null char.  I don't understand adQ3.  Not all members of the struct are LPSTR.  So your loop does not make sense. 

You can use this, although benefits of doing it are not obvious to me...

$sMember = "Flags"
MsgBox ($MB_SYSTEMMODAL, "", Execute("$tInfo." & $sMember))

 

Link to comment
Share on other sites

  • Zohar changed the title to [Solved] Is It Possible to Get The Name of the Shortcut that Called the .au3 Script?

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