使用WMI安装网络驱动器

尝试编写WMI类函数,以使用登录计算机的凭据在任何计算机(远程或本地)上安装网络驱动器。

这是一个大型项目的类,我为帮助台员工在远程PC上进行一线修复而编写。 机器名称或IP地址和应用程序中的技术类型连接到它,并允许技术人员单击几个按钮并修复一些基本项目,而无需远程(VNC)进入PC。

我在互联网上看到它比WMI更简单,但是由于应用程序的远程特性,我宁愿不使用本地API调用,也不想担心上传脚本并通过进程执行它开始。 WMI中已经有其他function,所以我想保持代码库相同。

基本思想是将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");