Jump to content

_WinAPI_GetStartupInfo() and getting the data from pointers


Go to solution Solved by Nine,

Recommended Posts

Posted (edited)

In _WinAPI_GetStartupInfo() one gets the data from $tagSTARTUPINFO ( in <WinAPISys.au3> ) and the structure is at https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/ns-processthreadsapi-startupinfow

typedef struct _STARTUPINFOW {
  DWORD  cb;
  LPWSTR lpReserved;
  LPWSTR lpDesktop;
  LPWSTR 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;
} STARTUPINFOW, *LPSTARTUPINFOW;

I'd like to read the "LPWSTR lpTitle;" but don't know how to read the string from the pointer. Help.

Quote
STARTF_TITLEISLINKNAME
0x00000800
The lpTitle member contains the path of the shortcut file (.lnk) that the user invoked to start this process. This is typically set by the shell when a .lnk file pointing to the launched application is invoked. Most applications will not need to set this value.

This flag cannot be used with STARTF_TITLEISAPPID.

This description above is what am after. I'd like to know if my script loaded from a .lnk or not.

Edited by argumentum
more

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

  • Solution
Posted (edited)

Try:

#include <WinAPISys.au3>

$t = _WinAPI_GetStartupInfo()
$tP = DllStructCreate("wchar title[255]", $t.Title)
ConsoleWrite($tP.title & @CRLF)

 

I was too slow...

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted (edited)
#include <WinAPISys.au3>
#include <WinAPIShellEx.au3>
#include <WinAPIMisc.au3>

Global $g_ScriptLnk = StringTrimRight(@ScriptFullPath, 4) & " (script) - Shortcut.lnk"
Global $g_ScriptIco = StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 0, -1)) & "Icons\au3.ico"
TraySetIcon($g_ScriptIco)

If Not IsFromLNK() Then _WinAPI_SetCurrentProcessExplicitAppUserModelID(@ScriptName & '-' & TimerInit())

EnsureScriptLnk() ; this will create the shortcut.lnk for you in the same folder

MsgBox(262144, @ScriptName, "was loaded from link ??? " & IsFromLNK(), 5)

; #FUNCTION# ====================================================================================================================
; Name...........: IsFromLNK
; Description....: Determine if the current application was launched from a shortcut (.lnk file).
; Syntax.........: IsFromLNK()
; Parameters.....: None
; Return values .: Success: Returns 1 if the application was launched from a .lnk shortcut, otherwise returns 0.
;                  Failure: 
;                  @error = 1: An error occurred retrieving startup information.
;                  @error = 2: The title string could not be retrieved.
; Author ........: 
; Modified ......: 
; Remarks .......: This function uses the _WinAPI_GetStartupInfo and _WinAPI_GetString functions to determine if the application was launched from a shortcut.
; Related .......: 
; Link ..........: https://www.autoitscript.com/forum/index.php?showtopic=212920&view=findpost&p=1543594
; Example .......: If IsFromLNK() Then MsgBox(0, "Information", "This script was launched from an .lnk shortcut.")
; ===============================================================================================================================
Func IsFromLNK()
    Local $tInfo = _WinAPI_GetStartupInfo()
    If @error Then Return SetError(1, 0, -1)
    Local $sTitle = _WinAPI_GetString($tInfo.title)
    If @error Then Return SetError(2, 0, -2)
    Return Int(StringRight($sTitle, 4) = ".lnk")
EndFunc   ;==>IsFromLNK

Func CreateScriptLnk($sLinkFileName = $g_ScriptLnk, $sFileDescription = "My awesome script", $sIcon = $g_ScriptIco)
    If Not FileCreateShortcut(@AutoItExe, $sLinkFileName, @ScriptDir, '/AutoIt3ExecuteScript "' & _
            @ScriptFullPath & '"', $sFileDescription, $sIcon) Then
        ConsoleWrite('FileCreateShortcut FAILED' & @CRLF)
        Return SetError(1, 0, 1)
    EndIf
    FileCopy($sLinkFileName, StringTrimRight($sLinkFileName, 4) & " - Copy.lnk") ; so you can play with that and see the implicit CurrentProcessExplicitAppUserModelID
EndFunc   ;==>CreateScriptLnk

Func EnsureScriptLnk($sLinkFileName = $g_ScriptLnk)
    ConsoleWrite('EnsureScriptLnk("' & $sLinkFileName & '")' & @CRLF)
    Local $aDetails = FileGetShortcut($sLinkFileName)
    If Not @error And $aDetails[0] = @AutoItExe Then
        ConsoleWrite('EnsureScriptLnk, All good.' & @CRLF)
        Return 0
    EndIf
    ConsoleWrite('EnsureScriptLnk() FAILED, calling CreateScriptLnk()' & @CRLF)
    Local $vRet = CreateScriptLnk($sLinkFileName)
    ConsoleWrite('CreateScriptLnk() returned val,error,extended = ' & $vRet & ',' & @error & ',' & @extended & @CRLF)
    Return SetError(@error, @extended, $vRet)
EndFunc   ;==>EnsureScriptLnk

 

Edited by argumentum
better

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

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
×
×
  • Create New...