This repository has been archived by the owner on Aug 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
lld.cs
91 lines (74 loc) · 3.17 KB
/
lld.cs
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Source: https://stackoverflow.com/questions/14442960/getting-drive-info-from-a-remote-computer
// To Compile:
// C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe /t:exe /out:lld.exe lld.cs
using System;
using System.Management;
class ListLogicalDrives
{
public static int PrintUsage()
{
Console.WriteLine(@"List logical drives on local or remote host
USAGE:
lld [system]");
return 1;
}
public static int Main(string[] args)
{
try
{
string[] DRIVE_TYPES = { "Unknown", "No Root Directory", "Removable Disk", "Local Disk", "Network Drive", "Compact Disc", "RAM Disk" };
string system = ".";
foreach (string arg in args)
{
switch (arg.ToUpper())
{
case "/?":
return PrintUsage();
default:
system = args[0].Trim(new Char[] { '\\', ' ' });
break;
}
}
ManagementPath path = new ManagementPath()
{
NamespacePath = @"root\cimv2",
Server = system
};
ManagementScope scope = new ManagementScope(path);
string[] selectedProperties = new string[] { "DeviceID", "DriveType", "ProviderName", "FreeSpace", "Size", "VolumeName" };
SelectQuery query = new SelectQuery("Win32_LogicalDisk", "", selectedProperties);
// Execute query within scope and iterate through results
using (var searcher = new ManagementObjectSearcher(scope, query))
{
foreach (ManagementObject volume in searcher.Get())
{
Console.WriteLine("\nDrive {0}\\", volume.GetPropertyValue("DeviceID"));
if (String.Format("{0}", volume.GetPropertyValue("VolumeName")) != "")
{
Console.WriteLine(" Name: {0}", volume.GetPropertyValue("VolumeName"));
}
Console.WriteLine(" Type: {0}", DRIVE_TYPES[Convert.ToInt32(volume.GetPropertyValue("DriveType"))]);
if (Convert.ToInt32(volume.GetPropertyValue("DriveType")) == 4)
{
Console.WriteLine(" Provider: {0}", volume.GetPropertyValue("ProviderName"));
}
if (Convert.ToInt64(volume.GetPropertyValue("Size")) > 0)
{
Console.WriteLine(" Free Space: {0}", String.Format("{0:n0}", Convert.ToInt64(volume.GetPropertyValue("FreeSpace"))) + " bytes");
Console.WriteLine(" Size: {0}", String.Format("{0:n0}", Convert.ToInt64(volume.GetPropertyValue("Size"))) + " bytes");
}
}
}
return 0;
}
catch (Exception e)
{
Console.Error.WriteLine("[-] ERROR: {0}", e.Message.Trim());
return 1;
}
finally
{
Console.WriteLine("\nDONE");
}
}
}