无法运行位于映射网络驱动器上的批处理文件
问题描述:
我无法运行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
答
只需使用FileIO.FileSystem
并将其复制到临时文件。 然后使用Backgroundworker
运行。