Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Check who has taken the handle of the text file.

Check who has taken the handle of the text file.

Scheduled Pinned Locked Moved C#
questioncsharp
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hi all, I have one text file. now i want to check who has taken the handle of the text file. How can i find the exe in C#? Reply ASAP. Thanking You, Sunil G.

    modified on Tuesday, February 23, 2010 2:10 AM

    C S 2 Replies Last reply
    0
    • L Lost User

      Hi all, I have one text file. now i want to check who has taken the handle of the text file. How can i find the exe in C#? Reply ASAP. Thanking You, Sunil G.

      modified on Tuesday, February 23, 2010 2:10 AM

      C Offline
      C Offline
      Calla
      wrote on last edited by
      #2

      To retrieve a list of running processes use: System.Diagnostics.Process.GetProcesses() which returns an array av Process objects.

      L 1 Reply Last reply
      0
      • C Calla

        To retrieve a list of running processes use: System.Diagnostics.Process.GetProcesses() which returns an array av Process objects.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        with this System.Diagnostics.Process.GetProcesses() i get all the running processes. but i want the process name who has taken the handle of particular text file. As in input parameter i will give textfile name and want the process who has taken the handle of the textfile.

        modified on Tuesday, February 23, 2010 3:35 AM

        C 1 Reply Last reply
        0
        • L Lost User

          with this System.Diagnostics.Process.GetProcesses() i get all the running processes. but i want the process name who has taken the handle of particular text file. As in input parameter i will give textfile name and want the process who has taken the handle of the textfile.

          modified on Tuesday, February 23, 2010 3:35 AM

          C Offline
          C Offline
          Calla
          wrote on last edited by
          #4

          Do you have the name of the text file and you want to retrieve the process which has the handle to that file? Could you please elaborate more?

          L 1 Reply Last reply
          0
          • C Calla

            Do you have the name of the text file and you want to retrieve the process which has the handle to that file? Could you please elaborate more?

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Yes you r on the track. I have the name of the text file and I want to retrieve the process which has the handle to that file.. If you want more explanation, i will explain the whole case. Thanking You, Sunil G.

            modified on Tuesday, February 23, 2010 3:46 AM

            C 1 Reply Last reply
            0
            • L Lost User

              Yes you r on the track. I have the name of the text file and I want to retrieve the process which has the handle to that file.. If you want more explanation, i will explain the whole case. Thanking You, Sunil G.

              modified on Tuesday, February 23, 2010 3:46 AM

              C Offline
              C Offline
              Calla
              wrote on last edited by
              #6

              I'm sorry Sunil - don't know how to achieve that. Hope someone else can help, and I'l make a post if I have a sudden stroke of genious.. Good luck anyway!

              M 1 Reply Last reply
              0
              • L Lost User

                Hi all, I have one text file. now i want to check who has taken the handle of the text file. How can i find the exe in C#? Reply ASAP. Thanking You, Sunil G.

                modified on Tuesday, February 23, 2010 2:10 AM

                S Offline
                S Offline
                Saksida Bojan
                wrote on last edited by
                #7

                This is inposible to do it completly in C#. You must not be afrait to use a lot of PInvoke I hope this a few articles help you: (I think the last link will be best) http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/9e2044c5-ae5d-4552-a335-01cc567dfc58[^] http://stackoverflow.com/questions/242882/how-can-i-unlock-a-file-that-is-locked-by-a-process-in-net[^] http://www.codeguru.com/Cpp/W-P/files/fileio/article.php/c1287/#more[^] http://www.vbforums.com/showthread.php?t=501992[^]

                L 1 Reply Last reply
                0
                • S Saksida Bojan

                  This is inposible to do it completly in C#. You must not be afrait to use a lot of PInvoke I hope this a few articles help you: (I think the last link will be best) http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/9e2044c5-ae5d-4552-a335-01cc567dfc58[^] http://stackoverflow.com/questions/242882/how-can-i-unlock-a-file-that-is-locked-by-a-process-in-net[^] http://www.codeguru.com/Cpp/W-P/files/fileio/article.php/c1287/#more[^] http://www.vbforums.com/showthread.php?t=501992[^]

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Thank u very much...

                  1 Reply Last reply
                  0
                  • C Calla

                    I'm sorry Sunil - don't know how to achieve that. Hope someone else can help, and I'l make a post if I have a sudden stroke of genious.. Good luck anyway!

                    M Offline
                    M Offline
                    Manoj_Leo
                    wrote on last edited by
                    #9

                    Hi Check this out it might help you..i hav'nt tried it but looks like this is what you are looking for.. fpound this solution while going thrw some blog :) posted by :-Gennady Zabrodsky It is very complex way to invoke Win32 from C#. You should use tool Handle.exe from http://technet.microsoft.com/en-us/sysinternals/bb896655.aspx After that your C# code have to be the following: string fileName = @"c:\aaa.doc";//Path to locked file Process tool = new Process(); tool.StartInfo.FileName = "handle.exe"; tool.StartInfo.Arguments = fileName; 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(Match match in Regex.Matches(outputTool, matchPattern)) { Process.GetProcessById(int.Parse(match.Value)).Kill(); }

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups