TMXOD Posted April 3, 2010 Posted April 3, 2010 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...
martin Posted April 3, 2010 Posted April 3, 2010 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.
TMXOD Posted April 3, 2010 Author Posted April 3, 2010 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)...
Ascend4nt Posted April 3, 2010 Posted April 3, 2010 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 My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)
mojomatt Posted February 13, 2014 Posted February 13, 2014 I know this is an old thread but nonetheless... You can use the Sysinternals tool called handle.exe to get the working directory of an external process. http://technet.microsoft.com/en-us/sysinternals/bb896655.aspx
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now