Zohar Posted March 8, 2021 Share Posted March 8, 2021 (edited) 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 August 11, 2021 by Zohar Link to comment Share on other sites More sharing options...
Deye Posted March 8, 2021 Share Posted March 8, 2021 i believe _WinAPI_GetStartupInfo() can be a lead to what you are looking to do here Zohar 1 Link to comment Share on other sites More sharing options...
Nine Posted March 8, 2021 Share Posted March 8, 2021 Simply pass a parameter to the au3 script. Read it with CmdLine array. Zohar and Musashi 1 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Zohar Posted March 8, 2021 Author Share Posted March 8, 2021 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 More sharing options...
Musashi Posted March 8, 2021 Share Posted March 8, 2021 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 Zohar 1 "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 More sharing options...
Nine Posted March 8, 2021 Share Posted March 8, 2021 @Musashi You are just great at explaining the subject Musashi 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
rudi Posted March 10, 2021 Share Posted March 10, 2021 @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; Deye 1 Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
Nine Posted March 10, 2021 Share Posted March 10, 2021 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) Musashi, Deye, Zohar and 1 other 2 2 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Deye Posted March 10, 2021 Share Posted March 10, 2021 @rudi * just create a shortcut for this example's compiled exe * run from shortcut and you will see the full path to the shortcut Just tried Nine's example and it worked flawlessly Deye Link to comment Share on other sites More sharing options...
rudi Posted March 10, 2021 Share Posted March 10, 2021 (edited) @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 March 10, 2021 by rudi Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
Nine Posted March 10, 2021 Share Posted March 10, 2021 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 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Zohar Posted March 10, 2021 Author Share Posted March 10, 2021 Fantastic Thank you so much Deye Nine and Musashi Link to comment Share on other sites More sharing options...
Zohar Posted March 10, 2021 Author Share Posted March 10, 2021 Deye is it possible that you had an older account in autoitscript.com, inwhich the nick also had the word "eye" in it, and also started with D? Link to comment Share on other sites More sharing options...
rudi Posted March 10, 2021 Share Posted March 10, 2021 (edited) 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 March 10, 2021 by rudi Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
Nine Posted March 10, 2021 Share Posted March 10, 2021 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)) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Deye Posted March 10, 2021 Share Posted March 10, 2021 @Zohar I've been around for quite a while now, didn't check from when .. Had no former accounts Thanks Link to comment Share on other sites More sharing options...
Zohar Posted March 10, 2021 Author Share Posted March 10, 2021 OK. You reminded me of someone. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now