安装网络驱动器与WMI [英] Mount Network Drive with WMI

查看:154
本文介绍了安装网络驱动器与WMI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想写一个WMI类功能使用的登录计算机的凭据安装任何一台电脑(远程或本地),在网络驱动器。

这是一类,我写了帮助台人员做远程PC的第一线修复一个更大的项目。在计算机名或IP地址和应用程序的技术类型的连接,并允许高科技点击几个按钮,并修正了一些基本的东西,而无需遥控器(VNC)到PC。

我读遍,它比WMI更容易上网方式,但是由于应用程序的远程性质我宁可不使用本地的API调用,也不想担心上传脚本并执行它虽然一个过程的开始。另外,其它功能都已经在WMI所以我想保持code碱基相同。

其基本思路是,以安装 H: // fileserver.example.com/$username

NetFixer已经在生产中使用,所以我试图让我的code漂亮和整洁

 使用系统;
使用System.Collections.Generic;
使用System.Linq的;
使用System.Text;
使用System.Management;

命名空间WMIcontrols
{
  公共类远程
  {

   公共字符串的目标;

   //有些code跳过这里为了简单起见...

   公共BOOL MountNetDrive(串驱动器号,串MountLocation)
    {
      尝试
      {
          //安装网络驱动器
          返回true;
      }
      抓住
      {
          //安装失败
          返回false;
      }
    }
  }
}
 

解决方案

这是不使用WMI,但会完成你想要什么,很简单

  System.Diagnostics.Process.Start(CMD,/ C网使用的是X:\\ fileserver.example.com /用户:用户名密码);
 

Trying to write a WMI class function to mount a network drive on any computer (remote or local) using the credentials of the logged in computer.

This is a class for a larger project that I wrote for help desk staff to do first line fixes on remote PC's. The tech types in the the machine name or ip address and the app connects to it and allows to tech to click a couple of buttons and fix some basic items without having to remote(VNC) into the PC.

I've read all over the internet that it is much easier ways than WMI, but due to the remote nature of the app I would rather not use local API calls, nor do I want to worry about uploading script and executing it though a process start. Also other functions are already in WMI so I'd like to keep the code base the same.

The basic idea is to mount H: to //fileserver.example.com/$username

NetFixer is already in production use so I'm trying to keep my code nice and neat

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;
      }
    }
  }
}

解决方案

This is not using WMI but will accomplish what you want and is very simple

System.Diagnostics.Process.Start("cmd", "/c net use x: \\fileserver.example.com /user:Username Password");

这篇关于安装网络驱动器与WMI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆