在命令行中它可以正常工作: net USE T:\ 123.45.67.89 \ TEST mytestuser / user:MYTESTUSER
但是使用asp.net,使用以下代码,始终抛出带有以下错误的异常:映射驱动器时“本地设备名称已被使用”
我首先尝试从所有驱动器断开连接,映射到不同的驱动器号。我从不同的服务器完成了,到不同的服务器
问题肯定与驱动器号有关吗?
temp = MapDrive("T", "\\123.45.67.89\TEST", "MYTESTUSER", "mytestuser")
Public Shared Function MapDrive(ByVal DriveLetter As String, ByVal Path As String, ByVal Username As String, ByVal Password As String) As Boolean
Dim ReturnValue As Boolean = False
Dim p As New System.Diagnostics.Process()
p.StartInfo.UseShellExecute = False
p.StartInfo.CreateNoWindow = True
p.StartInfo.RedirectStandardError = True
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.FileName = "net.exe"
p.StartInfo.Arguments = " use " & DriveLetter & ": " & Path & " /user:" & Username & " " & Password & " /persistent:yes"
p.Start()
p.WaitForExit()
Dim ErrorMessage As String = p.StandardError.ReadToEnd()
Dim OuputMessage As String = p.StandardOutput.ReadToEnd()
Dim StoreFile As System.IO.Directory
Dim Files As String()
Dim File As String
If ErrorMessage.Length > 0 Then
Throw New Exception("Error:" & ErrorMessage)
Else
ReturnValue = True
End If
Files = StoreFile.GetFiles("T:\FINDTHIS\", "*")
For Each File In Files
HttpContext.Current.Trace.Warn(File)
Next
Return ReturnValue
End Function
答案 0 :(得分:0)
映射驱动器是否特定于运行net
命令的用户?
您的asp.net页面通常以与当前用户不同的身份运行。这意味着您的代码可能在第一次运行时成功映射网络路径。然后当你第二次运行它时会出现错误。
但是,您在cmd
窗口中删除该字母的映射是徒劳的,因为驱动器未通过您的用户身份进行映射(毕竟您的cmd
窗口正在运行)
然后还有运行net
命令所需的权限,尽管这可能会引发不同的错误。