VB.NET 管理对象帮助 [英] VB.NET ManagementObject Help

查看:32
本文介绍了VB.NET 管理对象帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个函数来将映射的驱动器路径转换为 ​​UNC 路径.我做了一些谷歌搜索,发现 几个 不同 页面 关于此事.我对第一个最感兴趣,但我似乎无法得到代码来配合.由于原帖是用 C# 写的,这里是我的 VB.NET 转换:

I am trying to create a function to convert a mapped drive path to a UNC path. I did some googling and found several different pages on the matter. I am most interested in the first one, but I cannot seem to get the code to cooperate. Since the original post was in C#, here is my VB.NET conversion:

Public Shared Function GetUniversalName(ByVal sFilePath As String) As String
    If sFilePath = String.Empty OrElse sFilePath.IndexOf(":") Then
        Return sFilePath
    End If
    If sFilePath.StartsWith("\") Then
        Return (New Uri(sFilePath)).ToString()
    End If

    Dim searcher As New ManagementObjectSearcher("SELECT RemoteName FROM win32_NetworkConnection WHERE LocalName = '" + sFilePath.Substring(0, 2) + "'")
    For Each managementObject As ManagementObject In searcher.[Get]()
        Dim sRemoteName As String = TryCast(managementObject("RemoteName"), String)
        sRemoteName += sFilePath.Substring(2)
        Return (New Uri(sRemoteName)).ToString()
    Next
    Return sFilePath
End Function

我已经导入了 System.Management,但是 VS2008 说 ManagementObjectSearcherManagementObject 没有定义.谁能把我推向正确的方向?

I have imported System.Management, but VS2008 says ManagementObjectSearcher and ManagementObject are not defined. Can anyone push me in the right direction?

推荐答案

您还需要在参考文献中添加 System.Management.

You need to add System.Management in your references as well.

这篇关于VB.NET 管理对象帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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