Sign in to follow this  
Followers 0
TMXOD

Retrieve External Process' current/working directory

6 posts in this topic

When writing a script, I can retrieve the script's working directory by using the following macro:

@WorkingDir

When launching an application from within a script, I can set its initial working directory by using the following syntax for the 'Run' function:

Run("x:\path\to\application.exe","x:\working\directory")

The question is:

How do I retrieve the working directory of an application that was already started when my script began execution?

I looked in the PSAPI documentation in MSDN, the Win32_Process WMI class, as well as multiple forum searches for variations on 'current/working directory existing/running process' without positive results... Any help getting this working would be greatly appreciated...

Share this post


Link to post
Share on other sites



When writing a script, I can retrieve the script's working directory by using the following macro:

@WorkingDir

When launching an application from within a script, I can set its initial working directory by using the following syntax for the 'Run' function:

Run("x:\path\to\application.exe","x:\working\directory")

The question is:

How do I retrieve the working directory of an application that was already started when my script began execution?

I looked in the PSAPI documentation in MSDN, the Win32_Process WMI class, as well as multiple forum searches for variations on 'current/working directory existing/running process' without positive results... Any help getting this working would be greatly appreciated...

This _ProcessListProperties function by PsaltyDS might help.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

That UDF uses the Win32_Process WMI class, which does not provide the working directory.

I know it's possible, since Technet's Process Explorer can do it, but it seems like something that would be documented/known... (i.e. don't feel like setting up a reverse engineering setup to dig up a single API call)...

Share this post


Link to post
Share on other sites

TMXOD, The only way I know of doing this is to open and read the process memory - there's a pointer in the PEB block to 'Process Parameters' where you can read Current directory, DLL search path pattern, full exe path, Command line, Invokation method, and a number of other interesting strings. Doing this unfortunately means you'll need to have proper privileges to open a handle to read the process memory.

I have code for it, but its not very pretty and has limited error checking, but I just thought I'd try pointing you in the right direction

Share this post


Link to post
Share on other sites

I'd love to see that code (pretty or not :( )

Share this post


Link to post
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
Sign in to follow this  
Followers 0