62,046
社区成员
发帖
与我相关
我的任务
分享
Dim objProc As New System.Diagnostics.Process
Try
objProc.StartInfo.FileName = "CMD.EXE"
objProc.StartInfo.UseShellExecute = False
objProc.StartInfo.RedirectStandardInput = True
objProc.StartInfo.RedirectStandardOutput = True
objProc.StartInfo.RedirectStandardError = True
objProc.StartInfo.CreateNoWindow = True
objProc.Start()
Dim strCmd As String = String.Empty
'strCmd = String.Format("NET USE {0} ""{1}"" /USER:""{2}"" ", strDir, strPWD, strUser)
strCmd = String.Format("NET USE {0} ""{1} /USER:{2}"" ", strDir strPWD, strUser)
objProc.StandardInput.WriteLine(strCmd)
objProc.StandardInput.WriteLine("EXIT")
While Not objProc.HasExited
objProc.WaitForExit(1000)
End While
Dim strErrorMsg As String = objProc.StandardError.ReadToEnd
objProc.StandardError.Close()
If strErrorMsg Is Nothing Or strErrorMsg = String.Empty Then
Else
Throw New Exception(strErrorMsg)
End If
Catch ex As Exception
Return False
Finally
objProc.Close()
objProc.Dispose()
End Try