我需要在.NET应用程序中映射networking驱动器。 我将需要使用AD用户名和密码进行身份validation。 通常我只是使用net use命令来使用batch file。 我如何从C#或VB.NET代码中做到这一点?
为什么打电话给PerformanceCounter很慢?
在IIS 7.5 / Windows 7家庭高级版RavendB错误
C# – 与if语句使用正则expression式
DotNetZip – 如何提取到工作目录
用C#重命名捕获设备,有可能吗?
你看过吗?
http://www.codeguru.com/csharp/csharp/cs_network/windowsservices/article.PHP/c12357
另外,您可以通过Process.Start()使用net.exe并将其传递给您始终使用的参数。
System.Diagnostics.Process.Start("net.exe","use K: \serverURIpathhere");
看到这个网站: http : //www.blackwasp.co.uk/MapDriveLetter.aspx
它将向您展示如何以编程方式映射来自C#的驱动器,包括用户名和密码等凭据
下面是一些你应该发现的代码,比仅仅在控制台上进行shelling更可靠。
''' <summary> ''' ''' </summary> ''' <param name="driveLetter"></param> ''' <param name="uncName"></param> ''' <remarks>This was hand tested. We cannot automate because it messes with the OS</remarks> Sub MapDrive(ByVal driveLetter As Char,ByVal uncName As String) Dim driveLetterFixed = Char.ToLower(driveLetter) If driveLetterFixed < "a"c OrElse driveLetterFixed > "z"c Then Throw New ArgumentOutOfRangeException("driveLetter") If uncName Is nothing Then Throw New ArgumentNullException("uncName") If uncName = "" Then Throw New ArgumentException("uncName cannot be empty","uncName") Dim fixedUncName As String = uncName 'This won't work if the unc name ends with a If fixedUncName.EndsWith("") Then fixedUncName = fixedUncName.Substring(0,fixedUncName.Length - 1) Dim oNetWork As New IWshRuntimeLibrary.IWshNetwork_Class Try 'This usually isn't necessary,but we can't detect when it is needed. oNetWork.RemoveNetworkDrive(driveLetter,True,True) Catch ex As Runtime.InteropServices.COMException 'Ignore errors,it just means it wasn't necessary End Try oNetWork.MapNetworkDrive(driveLetter,fixedUncName,True) End Sub
http://clrextensions.codeplex.com/SourceControl/changeset/view/55677#666894
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。