1
我無法運行VB.Net中使用System.Diagnostics.Process位於映射網絡驅動器中的批處理文件。我得到:無法運行位於映射網絡驅動器上的批處理文件
'<batchfilename>.bat' is not recognized as an internal or external command, operable program or batch file.
Press any key to continue...
當瀏覽到包含此批處理文件並雙擊它的文件夾(使用資源管理器)我得到同樣的錯誤。通過命令提示符將目錄更改爲該文件夾,即可成功運行該批處理文件。我無法弄清楚爲什麼會發生這種情況。我認爲問題是Process的Start()函數像雙擊那樣工作,而不是運行批處理文件。我已經把我的代碼放在下面。任何有關這方面的幫助將不勝感激。
Private WithEvents batchProcObj As New Process
Private Const SLEEP_AMOUNT As Integer = 100
Public Event Exited As EventHandler
Private eventHandled As Boolean
Public Sub startBatchProcess(ByVal batchProcFilePath As String, ByVal batchParams As String, ByVal domainName As String, ByVal loginName As String, ByVal passwd As String)
' Initialise process start info with batch process path and the parameters
Dim startInfoObj As New ProcessStartInfo()
Dim parentDir As New IO.DirectoryInfo(batchProcFilePath)
' Initialise event to false
eventHandled = False
' Get the batch file name without the extension
batchName = batchProcFilePath
Try
' Assign the batch process properties
startInfoObj.FileName = batchProcFilePath
startInfoObj.Arguments = batchParams
startInfoObj.UseShellExecute = False
startInfoObj.WindowStyle = ProcessWindowStyle.Normal
startInfoObj.WorkingDirectory = "C:\Windows\System32\"
startInfoObj.Domain = domainName
startInfoObj.UserName = loginName
startInfoObj.Password = appHandler.getSecureString(passwd)
startInfoObj.LoadUserProfile = True
batchProcObj.StartInfo = startInfoObj
batchProcObj.EnableRaisingEvents = True
' Start the batch file
batchProcObj.Start()
' Get the start time of the batch process
procStartTime = batchProcObj.StartTime
' Insert audit log
appHandler.writeAuditLog("RunBatchProcess", "START - Batch Process [" & batchName & "]")
Catch ex As Exception
appHandler.writeErrorLog("Start Batch Process: " & batchProcFilePath, ex)
End Try
' Continue running the batch process till it exits
Do While Not eventHandled
elapsedTime += SLEEP_AMOUNT
Thread.Sleep(SLEEP_AMOUNT)
Loop
End Sub