Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Mit C# auslesen wer gerade Zugriff auf dll's hat

Empfohlene Antworten

Überprüfen ob eine Datei geöffnet ist, ist ja einfach.

Geht es ein bisschen genauer? Habe leider keine Ahnung wie. Ausserdem muss ich rausfinden, von welchem Prozess die Datei geöffnet ist, denn es tritt auch auf, wenn kein Programm geöffnet ist.

Im Taskmanager ist kein Programm zu finden, was auch nur annähernd in der Lage wäre diese Dateien zu öffnen. Es handelt sich nicht immer um die selbe Datei, sondern eine zufällige aus ca. 80, die sich alle auf einer Festplatte und im selben Ordner befinden oder dessen Unterordner befinden.

Also muss es irgendeinen versteckten Prozess geben, der diese Dateien blockiert. Diesen möchte ich ausfindig machen und endgültig von meinem System entfernen.

EDIT:

sorry...hatte deinen post nicht gelesen DeMue. Das werde ich später mal ausprobieren

Bearbeitet von Shadowman

hmm...

Ich hab jetzt mal ein Bisschen mit der API bzw. WQL rumgespielt, Folgendes funktioniert soweit ganz gut:


class Program

    {

        static void Main(string[] args)

        {

            ReadProcessOnFile(@"C:\\Program Files\\Mozilla Firefox\\firefox.exe");

        }


        static void ReadProcessOnFile(string path)

        {


            string x = string.Empty;


            SelectQuery query = new SelectQuery("SELECT * FROM CIM_DataFile WHERE Name = '" + path + "'");


            using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query))

            {

                foreach (ManagementObject mo in searcher.Get())

                {


                    x = "File Name: " + mo.Properties["Name"].Value + "\nIs currently opened by:\n";

                    foreach (ManagementBaseObject b in mo.GetRelated("Win32_Process"))

                    {

                        string p = ShowProcessProperties(b.ToString());

                        b.Dispose();

                        x += p + "\n";

                    }

                }

            }

            Console.WriteLine(x);

        }


        static string ShowProcessProperties(string objectClass)

        {


            using (ManagementObject process = new ManagementObject(objectClass))

            {


                process.Get();

                PropertyDataCollection processProperties = process.Properties;

                string x = null;

                x = "ProcessID := " + processProperties["ProcessID"].Value + " Command Line = " + processProperties["CommandLine"].Value + "\n";

                return x;

            }


        }

    }

Kann man natürlich noch hübscher machen, aber zumindest bekomm ich alle Prozesse angezeigt, die die betreffende Datei verwenden.

Da du ja evtl. noch den Benutzernamen haben willst, hier die neuere Version:


static void ReadProcessOnFile(string path)

        {


            string x = string.Empty;


            SelectQuery query = new SelectQuery("SELECT * FROM CIM_DataFile WHERE Name = '" + path + "'");


            using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query))

            {

                foreach (ManagementObject mo in searcher.Get())

                {

                    Dictionary<string, string> properties = new Dictionary<string,string>();

                    x = "File Name: " + mo.Properties["Name"].Value + "\nIs currently opened by:\n";

                    foreach (ManagementBaseObject b in mo.GetRelated("Win32_Process"))

                    {

                        properties = GetProcessProperties(b.ToString());

                        Dictionary<string, string>.KeyCollection keys = properties.Keys;

                        foreach (string key in keys)

                        {

                            x += key + ":" + properties[key]+"\n";

                        }

                        b.Dispose();

                    }

                }

            }

            Console.WriteLine(x);

        }


        static Dictionary<string, string> GetProcessProperties(string objectClass)

        {

            Dictionary<string, string> properties = new Dictionary<string, string>();

            using (ManagementObject process = new ManagementObject(objectClass))

            {

                process.Get();

                Process p = Process.GetProcessById(Convert.ToInt32(process.Properties["ProcessID"].Value.ToString()));

                properties.Add("ProcessID", p.Id.ToString());

                properties.Add("HandleCount", p.HandleCount.ToString());

                properties.Add("HasExited", p.HasExited.ToString());

                properties.Add("MachineName", p.MachineName);

                properties.Add("Owner", GetUserByProcess(p));

                properties.Add("MainModule", p.MainModule.ToString());

                properties.Add("MainWindowTitle", p.MainWindowTitle);

                properties.Add("PriorityBoostEnabled", p.PriorityBoostEnabled.ToString());

                properties.Add("ProcessName", p.ProcessName);

                properties.Add("SessionId", p.SessionId.ToString());

            }

            return properties;

        }


        static string GetUserByProcess(Process process)

        {

            string query = "Select * From Win32_Process Where ProcessID = " + process.Id;

            string ret = "none";

            using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query))

            {

                ManagementObjectCollection processList = searcher.Get();

                foreach (ManagementObject obj in processList)

                {

                     string[] argList = new string[] { string.Empty };

                     int returnVal = Convert.ToInt32(obj.InvokeMethod("GetOwner", argList));

                     if (returnVal == 0)

                          ret = argList[0];

                }

            }

            return ret;

        }

Hey TDM,

sehr schöne Funktion !

Kann ich auch sehr gut gebrauchen..

leider bekomme ich das ganze nicht so zum laufen :(

Hab mir nen OpenFiledialog gemacht und die geöffnete .exe als string path übergeben,

ReadProcessOnFile(openFileDialog.FileName);

Leider bekomme ich ne Exepcetion mit "Die Anfrage ist ungültig."

eventuell ne idee was ich falsch mache oO ?

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.