Jump to content

Recommended Posts

Posted

Hi, I want to get the directory of a running window or process.

I cant seem to find any way of doing this.

For example:

$Var = wingethandle("Example")
$Var2 = Wingetdir($Var); Not working
MsgBox(0,"Example", "The Directory of " & $Var & " is " & $Var2)
Func Wingetdir()
;;Code
EndFunc

Thanks

Posted

Search WinAPIEx.au3 by Yashied and look for the following _WinAPI_GetProcessFileName or _WinAPI_GetProcessWorkingDirectory.

Example:

#include <WinAPIEx.au3>

Run("notepad.exe")
Local $hWnd = WinWait("[CLASS:Notepad]")
ConsoleWrite(_WinAPI_GetProcessWorkingDirectory(WinGetProcess($hWnd)) & @LF)

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

Or if you don't want to get the working directory but the folder of where the process is installed then use this >>

#include <WinAPIEx.au3>

Run("notepad.exe")
Local $hWnd = WinWait("[CLASS:Notepad]")
ConsoleWrite(_GetDirectory(_WinAPI_GetProcessFileName(WinGetProcess($hWnd))) & @LF)

Func _GetDirectory($sFilePath)
    Return StringLeft($sFilePath, StringInStr($sFilePath, "", 0, -1)) ; SRE would be better.
EndFunc   ;==>_GetDirectory

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

@enaiman i wasn't trying to find the directory of my script but thanks for the reply :)

@guinness Thankss! _WinAPI_GetProcessFileName is exactly what I am looking for ;)

Posted

You're welcome.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...