尝试编写 WMI 类函数以使用已登录计算机的凭据在任何计算机(远程或本地)上安装网络驱动器。
这是我为帮助台员工编写的一个大型项目的类,用于在远程 PC 上进行第一线修复。机器名称或 IP 地址中的技术类型和应用程序连接到它并允许技术单击几个按钮并修复一些基本项目,而无需远程(VNC)到 PC。
我在互联网上读到它比 WMI 更简单,但由于应用程序的远程性质,我宁愿不使用本地 API 调用,也不想担心上传脚本和执行它虽然一个过程开始。此外,其他功能已经在 WMI 中,所以我想保持代码库不变。
基本思路是挂载H:
到//fileserver.example.com/$username
NetFixer 已经在生产环境中使用,所以我正在努力使我的代码保持整洁
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;
namespace WMIcontrols
{
public class Remote
{
public string target;
//Some code skipped here for simplicity sake...
public bool MountNetDrive(string DriveLetter, string MountLocation)
{
try
{
//Mount the network drive
return true;
}
catch
{
//Mount Failed
return false;
}
}
}
}
最佳答案
这不是使用 WMI,但可以完成您想要的并且非常简单
System.Diagnostics.Process.Start("cmd", "/c net use x: \\fileserver.example.com /user:Username Password");
关于c# - 使用 WMI 挂载网络驱动器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11665197/