Windows API: Resolve Execution Target
Windows API: Resolve Execution Target
Is there a Windows API function callable via DllCall() that resolves a target the way it would be if passed to the ShellExecute() API function (without running it)?
Re: Windows API: Resolve Execution Target
One thing that may be relevant is ExpandEnvironmentStrings.
Code: Select all
q:: ;expand environment variables
vTarget := "C:\Users\%username%\Desktop"
vChars := 20000
VarSetCapacity(vTarget2, vChars*2)
DllCall("kernel32\ExpandEnvironmentStrings", "Str",vTarget, "Str",vTarget2, "UInt",vChars, "UInt")
MsgBox, % vTarget2
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Windows API: Resolve Execution Target
It is not relevant at all. ShellExecute does not resolve environment variables.
I am not aware of any relevant API.
I am not aware of any relevant API.
Re: Windows API: Resolve Execution Target
- @1100++: Could you say more about what you're trying to?
- Can't you just infer the pattern by executing something and looking at the resulting command-line string in Task Manager?
- @lexikos: Relevant to the thread title.
- Also, useful as a search term. E.g. the MSDN page for ExpandEnvironmentStrings lists related Winapi functions.
- Can't you just infer the pattern by executing something and looking at the resulting command-line string in Task Manager?
- @lexikos: Relevant to the thread title.
- Also, useful as a search term. E.g. the MSDN page for ExpandEnvironmentStrings lists related Winapi functions.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Windows API: Resolve Execution Target
Here are various code snippets re. file to target, and exe files.
Code: Select all
;==================================================
;New Process Notifier - Scripts and Functions - AutoHotkey Community
;https://autohotkey.com/board/topic/56984-new-process-notifier/
;q:: ;test ShellExecute (and observe via New Process Notifier)
hWnd := 0
vOp := "edit"
vPath := A_ScriptFullPath
vPath := A_Desktop "\New Text Document.txt"
vArgs := ""
vWorkingDir := A_WorkingDir
vShowCmd := 3 ;SW_MAXIMIZE := 3
vShowCmd := 5 ;SW_SHOW := 5
DllCall("shell32\ShellExecute", "Ptr",hWnd, "Str",vOp, "Str",vPath, "Str",vArgs, "Str",vWorkingDir, "Int",vShowCmd)
return
;==================================================
;w:: ;test ShellExecute (and observe via New Process Notifier)
hWnd := 0
vOp := ""
vPath := "notepad.exe"
vArgs := ""
vWorkingDir := A_WorkingDir
vShowCmd := 3 ;SW_MAXIMIZE := 3
vShowCmd := 5 ;SW_SHOW := 5
DllCall("shell32\ShellExecute", "Ptr",hWnd, "Str",vOp, "Str",vPath, "Str",vArgs, "Str",vWorkingDir, "Int",vShowCmd)
return
;==================================================
;ProgID mentioned here:
;File Types - Windows applications | Microsoft Docs
;https://docs.microsoft.com/en-gb/windows/desktop/shell/fa-file-types
;w:: ;get extension target/extension edit target
vText := ".txt" ;extension
vText := "Folder"
vText := "txtfile" ;ProgID for txt
vText := "AutoHotkeyScript" ;ProgID for ahk
vVerb := "edit"
;verb not specified:
vChars := 0
;ASSOCSTR_COMMAND := 1
DllCall("shlwapi\AssocQueryString", "Int",0, "Int",1, "Str",vText, "Ptr",0, "Ptr",0, "UInt*",vChars) ;vChars includes the null
VarSetCapacity(vTarget, vChars << !!A_IsUnicode, 0)
DllCall("shlwapi\AssocQueryString", "Int",0, "Int",1, "Str",vText, "Ptr",0, "Str",vTarget, "UInt*",vChars)
MsgBox, % vTarget
;verb specified:
vChars := 0
;ASSOCSTR_COMMAND := 1
DllCall("shlwapi\AssocQueryString", "Int",0, "Int",1, "Str",vText, "Str",vVerb, "Ptr",0, "UInt*",vChars) ;vChars includes the null
VarSetCapacity(vTarget, vChars << !!A_IsUnicode, 0)
DllCall("shlwapi\AssocQueryString", "Int",0, "Int",1, "Str",vText, "Str",vVerb, "Str",vTarget, "UInt*",vChars)
MsgBox, % vTarget
return
;==================================================
;note: consider AssocQueryString instead
;q:: ;extension get info
vExt := "txt"
vExt := "ahk"
vRegKey := "HKEY_CLASSES_ROOT\." vExt
RegRead, vProgID, % vRegKey
MsgBox, % vProgID
if (vProgID = "")
return
vRegKey := "HKEY_CLASSES_ROOT\" vProgID "\Shell\Open\Command"
RegRead, vTarget, % vRegKey
MsgBox, % vTarget
return
;==================================================
;note: consider AssocQueryString instead
;q:: ;file - get target
vPath := A_ScriptFullPath
;vPath := A_ScriptDir
vAttrib := FileExist(vPath)
if InStr(vAttrib, "D")
{
MsgBox, % vPath
return
}
SplitPath, vPath, vName, vDir, vExt, vNameNoExt, vDrive
if (vExt = "")
{
MsgBox, % vPath
return
}
vRegKey := "HKEY_CLASSES_ROOT\." vExt
RegRead, vProgID, % vRegKey
if (vProgID = "")
{
MsgBox, % vPath
return
}
vRegKey := "HKEY_CLASSES_ROOT\" vProgID "\Shell\Open\Command"
RegRead, vTarget, % vRegKey
vTarget2 := StrReplace(vTarget, "%1", vPath)
MsgBox, % vProgID "`r`n" vTarget "`r`n" vTarget2
return
;==================================================
;query: are there any Winapi functions re. handling %1 and %*
;something worth considering:
if A_Is64bitOS && !(A_PtrSize=8)
DllCall("kernel32\Wow64DisableWow64FsRedirection", "Ptr*",0)
;also of note re. registry keys:
;REG_SZ, REG_EXPAND_SZ, REG_MULTI_SZ
;==================================================
;w:: ;path get exe associated with file type
vPath := A_AhkPath
VarSetCapacity(vPath2, 260*2, 0)
DllCall("shell32\FindExecutable", "Str",vPath, "Ptr",0, "Str",vPath2, "Ptr")
MsgBox, % vPath
return
;==================================================
;q:: ;exe name to path
vPath := A_AhkPath
SplitPath, vPath, vName, vDir, vExt, vNameNoExt, vDrive
vName := "chrome.exe"
vOutput := ""
vOutput .= A_WorkingDir "\" vName "`r`n"
vOutput .= A_WinDir "\" vName "`r`n"
vOutput .= A_WinDir "\System32" vName "`r`n"
vOutput .= "`r`n"
EnvGet, vList, PATH
Loop, Parse, vList, ";"
vOutput .= RTrim(A_LoopField, "\") "\" vName "`r`n"
vOutput .= "`r`n"
vRegKey := "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" vName
RegRead, vPath, % vRegKey
if !(vPath = "")
vOutput .= vPath "`r`n"
vOutput := RTrim(vOutput, "`r`n") "`r`n"
Clipboard := vOutput
MsgBox, % "done"
return
;==================================================
;w:: ;extension get info
vExt := "txt"
vExt := "ahk"
;ASSOCSTR (shlwapi.h) | Microsoft Docs
;https://docs.microsoft.com/en-gb/windows/win32/api/shlwapi/ne-shlwapi-assocstr
vExt := "." vExt
vOutput := ""
Loop, 24
{
vNum := A_Index
vChars := 0
DllCall("shlwapi\AssocQueryString", "Int",0, "Int",vNum, "Str",vExt, "Ptr",0, "Ptr",0, "UInt*",vChars)
VarSetCapacity(vText, vChars << !!A_IsUnicode, 0)
DllCall("shlwapi\AssocQueryString", "Int",0, "Int",vNum, "Str",vExt, "Ptr",0, "Str",vText, "UInt*",vChars)
vOutput .= vText "`r`n"
}
Clipboard := vOutput
MsgBox, % vOutput
return
;==================================================
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Who is online
Users browsing this forum: Google [Bot], Theda and 141 guests