Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7489181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:12:40+00:00 2026-05-29T15:12:40+00:00

I am writing an add-on for Windows Picture viewer that will need to send

  • 0

I am writing an “add-on” for Windows Picture viewer that will need to send commands to it (like “Show next/previous image”) and obtain file path to currently selected image. I managed to implement sending commands via SendMessage, but I don’t know how to request info from a process. Is this possible?
So far I can only extract filename from window title, but this restricts usage to just one folder, I need the full path.

[EDIT] I did some search and found, that there’s (undocumented?) possibility to find list of all handles used by process, using function NTQuerySystemInformation (As seen here Delphi – get what files are opened by an application).
The problem is, however, that the example provided there doesn’t show file handles for me at all (only non-harddrive device handles), and while I found working example here http://www.codeguru.com/Cpp/W-P/system/processesmodules/article.php/c2827/, seems like Picture Viewer doesn’t hold any handle to previewed file when launched from explorer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T15:12:41+00:00Added an answer on May 29, 2026 at 3:12 pm

    You can get the Process “Current Directory” (as shown in Process Explorer).
    Take a look at Two ways to get the command line of another process using Delphi by RRUZ.
    Based on that article, we could get the CurrentDirectory found in the RTL_USER_PROCESS_PARAMETERS (offset 36) structure:

    type
    Uint4B = Cardinal;
    Uint2B = Word;
    UChar  = Byte;
    Ptr32  = Pointer;
    
    TUNICODE_STRING = UNICODE_STRING;
    TCURDIR = packed record
      DosPath          : TUNICODE_STRING;
      Handle           : Ptr32;
    end;
    
    TRTL_USER_PROCESS_PARAMETERS = packed record
      MaximumLength    : Uint4B;
      Length           : Uint4B;
      Flags            : Uint4B;
      DebugFlags       : Uint4B;
      ConsoleHandle    : Ptr32;
      ConsoleFlags     : Uint4B;
      StandardInput    : Ptr32;
      StandardOutput   : Ptr32;
      StandardError    : Ptr32;
      CurrentDirectory : TCURDIR;
      DllPath          : TUNICODE_STRING;
      ImagePathName    : TUNICODE_STRING;
      CommandLine      : TUNICODE_STRING;
      Environment      : Ptr32;
      StartingX        : Uint4B;
      StartingY        : Uint4B;
      CountX           : Uint4B;
      CountY           : Uint4B;
      CountCharsX      : Uint4B;
      CountCharsY      : Uint4B;
      FillAttribute    : Uint4B;
      WindowFlags      : Uint4B;
      ShowWindowFlags  : Uint4B;
      WindowTitle      : TUNICODE_STRING;
      DesktopInfo      : TUNICODE_STRING;
      ShellInfo        : TUNICODE_STRING;
      RuntimeData      : TUNICODE_STRING;
      //   +0x090 CurrentDirectores : [32] _RTL_DRIVE_LETTER_CURDIR
    end;
    

    Here is how to obtain CurrentDirectory:

    function GetCurrentDirectoryFromPid(PID: THandle): string;
    const
      STATUS_SUCCESS             = $00000000;
      SE_DEBUG_NAME              = 'SeDebugPrivilege';
      OffsetProcessParametersx32 = $10; //16
      OffsetCurrentDirectoryx32  = $24; //36
    var
      ProcessHandle        : THandle;
      rtlUserProcAddress   : Pointer;
      CurrentDirectory          : TCURDIR;
      CurrentDirectoryContents  : WideString;
      ProcessBasicInfo     : PROCESS_BASIC_INFORMATION;
      ReturnLength         : Cardinal;
      TokenHandle          : THandle;
      lpLuid               : TOKEN_PRIVILEGES;
      OldlpLuid            : TOKEN_PRIVILEGES;
    begin
      Result:='';
      if OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, TokenHandle) then
      begin
        try
          if not LookupPrivilegeValue(nil, SE_DEBUG_NAME, lpLuid.Privileges[0].Luid) then
            RaiseLastOSError
          else
          begin
            lpLuid.PrivilegeCount := 1;
            lpLuid.Privileges[0].Attributes  := SE_PRIVILEGE_ENABLED;
            ReturnLength := 0;
            OldlpLuid    := lpLuid;
            //Set the SeDebugPrivilege privilege
            if not AdjustTokenPrivileges(TokenHandle, False, lpLuid, SizeOf(OldlpLuid), OldlpLuid, ReturnLength) then RaiseLastOSError;
          end;
    
          ProcessHandle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, false, PID);
          if ProcessHandle=0 then RaiseLastOSError
          else
          try
            // get the PROCESS_BASIC_INFORMATION to access to the PEB Address
            if (NtQueryInformationProcess(ProcessHandle,0{=>ProcessBasicInformation},@ProcessBasicInfo, sizeof(ProcessBasicInfo), @ReturnLength)=STATUS_SUCCESS) and (ReturnLength=SizeOf(ProcessBasicInfo)) then
            begin
              //get the address of the RTL_USER_PROCESS_PARAMETERS struture
              if not ReadProcessMemory(ProcessHandle, Pointer(Longint(ProcessBasicInfo.PEBBaseAddress) + OffsetProcessParametersx32), @rtlUserProcAddress, sizeof(Pointer), ReturnLength) then
                RaiseLastOSError
              else
              if ReadProcessMemory(ProcessHandle, Pointer(Longint(rtlUserProcAddress) + OffsetCurrentDirectoryx32), @CurrentDirectory, sizeof(CurrentDirectory), ReturnLength) then
              begin
                SetLength(CurrentDirectoryContents, CurrentDirectory.DosPath.length);
                //get the CurrentDirectory field
                if ReadProcessMemory(ProcessHandle, CurrentDirectory.DosPath.Buffer, @CurrentDirectoryContents[1], CurrentDirectory.DosPath.Length, ReturnLength) then
                 Result := WideCharLenToString(PWideChar(CurrentDirectoryContents), CurrentDirectory.DosPath.length div 2)
                else
                RaiseLastOSError;
              end;
            end
            else
            RaiseLastOSError;
          finally
            CloseHandle(ProcessHandle);
          end;
        finally
          CloseHandle(TokenHandle);
        end;
      end
      else
        RaiseLastOSError;
    end;    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently writing a Windows application in C# that will add documents to
I'm writing an application that will add users to Active Directory. I'm trying to
i'm writing an application that need to add some events to a calendar in
I'm writing some C++ code that will have to send data over TCP/IP. I
I'm writing an add-in for Media Center (the version that comes with Windows 7)
I am writing a FireFox add-on that displays webpages from my server as control
I am writing a C# Windows application program and I'm using an add-on for
I'm writing a windows service that's required to retrieve data from a database, build
I'm writing a windows application in c#,FW3.5 & Visual Studio 2008. I need to
I am writing a windows mobile application that uses SQL CE. It is not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.