Jump to content

Determine from what shortcut or process a script was started


rudi
 Share

Recommended Posts

Hello,

I'd like to determine, "from what shortcut" a compiled autoit script was run.

 

The background is, that several script versions shall be consolidated, an I have no clue, where the users might have placed fileshortcuts to oboslete old script verion names.

 

eg. MyScript.exe, MyScript-1.exe MyScript-2.5.exe

And shortcuts might be placed on the userdesktop, alluserdesktop, startup folder or somewhere else in the Start Menu.

What I've found so far is the function _WinAPI_GetStartupInfo(). The helpfile is just pointing to MSDN without giving any examples... it's returning a "DLLstruct" -- howto retrieve further info from that type of variable?

 

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

$StartupInfo=_WinAPI_GetStartupInfo()
$VarType=VarGetType($StartupInfo)
if IsArray($StartupInfo) Then
    _DebugArrayDisplay($StartupInfo,$VarType)
Else
    MsgBox(0,$VarType,"""" & $StartupInfo & """")
EndIf

 

Or maybe there is a better, different approach to get what shortcut from a compiled autoit script was started from?

 

 

Regards, Rudi.

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

Link to comment
Share on other sites

Hello,

 

thanks for your replies.

 @FrancescoDiMuro

FileGetShortcut() doesn't help, as I don't need to extract information from a known LNK file, but I need to retrieve the unknown location of the link file, that was used to start a compiled script.

@Danp2

That might be the right direction:

 

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

$tStartupInfo=_WinAPI_GetStartupInfo()
$VarType=VarGetType($tStartupInfo)
$StartupInfoString=""
For $i = 1 To 18
    $StartupInfoString &= $i & " = " & DllStructGetData($tSTARTUPINFO, $i) & @CRLF
Next

MsgBox(0,"startup info",$StartupInfoString)

How did your know that there are 18 elements in the returned DLLStuct variable?

 

The information I can retrieve with this function unfortunately doesn't help to know, where the "calling LNK file" is located:

 

image.png.efc68c6a641ef594b7ab47d2b4ee6fbf.png

Regards, Rudi.

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

Link to comment
Share on other sites

Hello,

I've just seen the function DllStructGetSize() it's returning "68", but just the 1st 18 seem to hold valid data?

 

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

$tStartupInfo=_WinAPI_GetStartupInfo()
$VarType=VarGetType($tStartupInfo)
$StructSize=DllStructGetSize($tStartupInfo)
$StartupInfoString="DllStructGetSize = " & $StructSize & @CRLF & "-----------------------------"
For $i = 1 To $StructSize
    $StartupInfoString &= @CRLF &  $i & " = " & DllStructGetData($tSTARTUPINFO, $i)
    if @error Then $StartupInfoString &= " @error = " & @error
Next

MsgBox(0,"startup info",$StartupInfoString)

image.thumb.png.56b8256524cdc925cf43a6b33a6a0dfd.png

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

Link to comment
Share on other sites

yes, I did read that in the help file.

 

Seems the "Elements" are not the bytes, but some kind of "sub-structure"?

 

So how to know the number of elements and *THEIR* size and type?

 

Regards, Rudi.

 

<edit>

Type should be this one?

 

Size? Howto resolve the values pointer elements point to?

 

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

$tStartupInfo=_WinAPI_GetStartupInfo()
$VarType=VarGetType($tStartupInfo)
$StructSize=DllStructGetSize($tStartupInfo)
$StartupInfoString="DllStructGetSize = " & $StructSize & @CRLF & "-----------------------------"
For $i = 1 To 18 ; $StructSize
    $NextElement=DllStructGetData($tSTARTUPINFO, $i)

    $StartupInfoString &= @CRLF &  $i & " = " & $NextElement & ", VarType = " & VarGetType($NextElement)
    if @error Then $StartupInfoString &= " @error = " & @error
Next

MsgBox(0,"startup info",$StartupInfoString)

image.png.eedd2ee26f3ed8c8a5b19f84310a52eb.png

Edited by rudi

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

Link to comment
Share on other sites

Hi Dan.

thanks for your reply.

 

Honestly, the description at docs.microsoft.com doesn't help me at all to figure out, how to grab the information I'm looking for, that's basically to know, what "call" started "this instance of a compiled autoit script. Especially what was the LNK (FileShortcut) used to do so.

 

And once more, the question, how to get hold of the information the poiters within the elements of the DllStruct point to?

 

Regards, Rudi.

 

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

Bump:

 

Any further suggestions, howto determine, *WHAT LNK FILE* was used to start "this-instance-of-a-running-autoit-script" ??? (compiled)

 

TIA, Rudi.

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

Link to comment
Share on other sites

How about _WinAPI_GetProcessFileName ?  It needs the PID but returns the fully-qualified path to the file.  *EDIT* :L just realized you may need the actual shortcut as opposed to where the exe is located.  

Edited by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
Share on other sites

@Jfish

Exactly.

Maybe the function ...

_WinAPI_GetStartupInfo()

... is the right approach, it's returning a DLLSTRUCT, holding several pointer elements, as @Danp2 pointed out some posts above.

 

Well, I fail to figure out how to address the data these pointers point to.

 

 

Regards, Rudi.

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

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