Autor Beitrag
kostonstyle
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 94



BeitragVerfasst: Di 20.07.10 13:34 
Hallo miteinander
wie kann ich die Laufwerke von einen externe Rechner anbinden, also Informationen auslesen?
Für lokal habe ich folgendes gefunden
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
System.IO.DriveInfo[] allDrives = System.IO.DriveInfo.GetDrives();

            foreach (System.IO.DriveInfo d in allDrives)
            {
                Console.WriteLine("Drive {0}", d.Name);
                Console.WriteLine("  File type: {0}", d.DriveType);
                if (d.IsReady == true)
                {
                    Console.WriteLine("  Volume label: {0}", d.VolumeLabel);
                    Console.WriteLine("  File system: {0}", d.DriveFormat);
                    Console.WriteLine(
                        "  Available space to current user:{0, 15} bytes",
                        d.AvailableFreeSpace);

                    Console.WriteLine(
                        "  Total available space:          {0, 15} bytes",
                        d.TotalFreeSpace);

                    Console.WriteLine(
                        "  Total size of drive:            {0, 15} bytes ",
                        d.TotalSize);
                }
            }

            Console.ReadLine();


Danke kostonstyle


Moderiert von user profile iconChristian S.: Topic aus C# - Die Sprache verschoben am Di 20.07.2010 um 15:54
Trashkid2000
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 561
Erhaltene Danke: 137



BeitragVerfasst: Sa 24.07.10 11:08 
Hallo kostonstyle,

ich denke, der einfachste Weg ist der mit WMI. Ob das aber der schnellste Weg ist, um Informationen abzufragen, weiss ich nicht. Bei Verweise in deinem Projekt musst Du ein Verweis auf System.Management hinzufügen.

Ansonsten, dort, wo nun bei ManagementScope "localhost" steht, muss entweder die IP oder der Hostname des entfernten Rechners stehen.

Viel erfolg damit, Marko

ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
class Program
{
  private enum DriveType
  {
    unbekannt, 
    kein_Hauptverzeichnis, 
    Wechselmedium, 
    Festplatte, 
    Netzwerklaufwerk, 
    CD_DVD, 
    RAMDisk 
  }

  static void Main(string[] args)
  {  
    ConnectionOptions opt = new ConnectionOptions();
    ObjectQuery oQuery = new ObjectQuery("SELECT Size, FreeSpace, Name, FileSystem, DriveType " + 
                                         "FROM Win32_LogicalDisk");
  
    ManagementScope scope = new ManagementScope("\\\\localhost\\root\\cimv2", opt);
    ManagementObjectSearcher moSearcher = new ManagementObjectSearcher(scope, oQuery);
    ManagementObjectCollection collection = moSearcher.Get();

    foreach (ManagementObject res in collection)
    {
        decimal size = Convert.ToDecimal(res["Size"]) / 1024 / 1024 / 1024;
        decimal freeSpace = Convert.ToDecimal(res["FreeSpace"]) / 1024 / 1024 / 1024;

        Console.WriteLine(string.Format("Laufwerk: {0}", res["Name"]));
        Console.WriteLine(string.Format("LaufwerksTyp: {0}", Enum.GetName(typeof(DriveType), res["DriveType"])));
        Console.WriteLine(string.Format("Dateisystem: {0}", res["FileSystem"]));
        Console.WriteLine(string.Format("Laufwerksgröße: {0} GB", Decimal.Round(size, 2)));
        Console.WriteLine(string.Format("Freier Speicher: {0} GB", Decimal.Round(freeSpace, 2)));
        Console.WriteLine("-------------------------------------------------");
    }
    Console.ReadKey();
  }
}
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19314
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 24.07.10 11:23 
Immer vorausgesetzt du hast die notwendigen Zugriffsrechte für den WMI-Zugriff auf den anderen PC.

Wenn du als Ziel vorhast auch Daten auszutauschen, rate ich dazu gleich ein Serverprogramm für den anderen PC zu schreiben.
kostonstyle Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 94



BeitragVerfasst: Mo 26.07.10 07:50 
Hallo miteinander
erstmal vielen dank für euer Hilfe.
@jaenicke
wie du erraten hast, möchte ich mit externe Rechner Daten austauschen. Mein Ziel ist es, auf Ordner
\\Rechner\c$\order1\unterorder1 zuzugreifen und von meinem Rechner Daten hinüber kopieren.

Danke kostonstyle
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19314
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 26.07.10 19:18 
Dann brauchst du aber immer noch ein Programm auf dem Server, dass diese Freigabe einrichtet. Bei Windows 95 und 98 war diese Standardfreigabe oft sogar direkt zu erreichen, bei heutigen Betriebssystemen ist der Zugriff darauf auf den Rechner selbst beschränkt.

Deshalb wäre ein kleines Serverprogramm oder eine andere als diese Freigabe sinnvoller zu verwenden.

Nebenbei: Wenn du diese Freigaben ohnehin schon einrichten willst, warum schaust du dann nicht einfach welche es gibt? ;-)
kostonstyle Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 94



BeitragVerfasst: Di 27.07.10 08:35 
wo kann ich solches Programm finden? Habe im Netz gesucht, aber leider nichts gefunden....

Gruss kostonstyle
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19314
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 27.07.10 19:04 
Ich meinte eher ein selbst geschriebenes. ;-)

Aber es gibt auch diverse Fernwartungsprogramme wie UltraVNC, die solche und viele weitere Funktionen bieten. Und es ist grundsätzlich auch möglich auf den UVNC Server mit einem eigenen Programm zuzugreifen.