获取网络上机器的系统盘符


获取本机的系统盘可以通过环境变量SystemDriver直接获取。
具体如下:
在cmd中为:echo %systemdrive%
在Powershell中:$env:SystemDrive
在c#中:Environment.GetEnvironmentVariable(“SystemDrive”);

如果要获取网络上极其的系统盘,可以使用WMI Object,前提条件是你有足够的权限。

static void Main(string[] args)
{
    string mgmtPath = @"NetworkComputerNamerootcimv2";

    ManagementClass mc = new ManagementClass(mgmtPath, @"Win32_LogicalDisk", null);
    Console.WriteLine(mc.GetInstances().Cast< ManagementBaseObject >().Where(
        mbo => mbo.Properties["DriveType"].Value.ToString() == "3").First().Properties["DeviceID"].Value.ToString());
}

上面的代码很容易转换成Powershell,这里就不赘述了。

本文链接: https://www.pstips.net/network-machine-system-drive.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!

关于 Mooser Lee

我是一个Powershell的爱好者,创建了PowerShell中文博客,热衷于Powershell技术的搜集和分享。本站部分内容来源于互联网,不足之处敬请谅解,并欢迎您批评指正。

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注