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

  • Home
  • SEARCH
  • 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 8706097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:31:51+00:00 2026-06-13T03:31:51+00:00

I am trying to use handle.exe to discover which process owns a file. When

  • 0

I am trying to use handle.exe to discover which process owns a file. When I run handle on it’s own through the commandline it works as expected. However, when I exec it from within my code I always get back that no process is locking the file.

My code to run Handle.exe:

Process tool = new Process();
tool.StartInfo.FileName = "handle.exe";
tool.StartInfo.Arguments = theFileName;
tool.StartInfo.UseShellExecute = false;
tool.StartInfo.RedirectStandardOutput = true;
tool.Start();
tool.WaitForExit();
string outputTool = tool.StandardOutput.ReadToEnd();

string matchPattern = @"(?<=\s+pid:\s+)\b(\d+)\b(?=\s+)";
foreach (System.Text.RegularExpressions.Match match in 
         System.Text.RegularExpressions.Regex.Matches(outputTool, matchPattern)) {
    Process p = Process.GetProcessById(int.Parse(match.Value));
    Console.WriteLine("Holding Process: " + p.Id);
}

I’ve also tried some of the other ways to find file ownership suggest in this SO question:
Using C#, how does one figure out what process locked a file?
All still reporting that nothing has control of the file.

To test this stuff I have a separate test program basically just running this:

    using (FileStream theStream = new FileStream(theFileName, FileMode.Open, FileAccess.Read, FileShare.None)) {
        while (true) ;
    }

Edit:
I run Visual Studio as an administrator so any process I start through code gets the same privileges. Of course this is only while debugging, but I need to a least get it working in one environment before worrying about others.

After handle is run outputTool is

Handle v3.5
Copyright (C) 1997-2012 Mark Russinovich
Sysinternals - www.sysinternals.com

No matching handles found.
  • 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-06-13T03:31:52+00:00Added an answer on June 13, 2026 at 3:31 am

    I’ve figured it out. My file path had an extra ‘\’. Apparently this confuses handle, but not File.Open(...).

    theFileName = "C:\ProgramData\MyApp\\imagefile.tiff"
    

    Whenever I tried running handle.exe in the Windows cmd I didn’t include the extra ‘\’.

    I guess since I never included the file path in my question, it was impossible for anyone else to figure it out. Sorry SO users.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use IO::Handle to create a CSV file with Text::CSV . When
I'm pretty new to Java ME and i'm trying to use Microlog to handle
Heya, I'm trying to use Mono's SIMD to handle coordinates(X,Y,Z) in my project, but
I was trying use a set of filter functions to run the appropriate routine,
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I am trying to use paypal simply to handle my credit card transactions. I
I am trying to use Reactive Extensions to write code to handle an asynchronous
I'm trying to do the following in C#: Open a new process (notepad.exe) Enter
I'm trying to use msbuild with my sublime project. I created the build file
I'm trying to write a program which executes make.exe from MinGW distribution in the

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.