B
Broggy69
Guest
So I have code that runs exe files. However any time I have a space in the path of the file I get an error file not found.
I tried the following
Dim procStartInfo As New ProcessStartInfo
Dim procExecuting As New Process
With procStartInfo
.UseShellExecute = True
.FileName = "C:\My Folder\File.exe"
.WindowStyle = ProcessWindowStyle.Normal
.Verb = "runas" 'add this to prompt for elevation
End With
procExecuting = Process.Start(procStartInfo)
procExecuting.WaitForExit()
'Also tried the following
'.FileName = "C:\" & "'" & "My Folder\" & "'" & "File.exe"
'.FileName = "C:\" & """"My Folder\"""" & "File.exe"
'.FileName = "C:\" & ""My Folder\"" & "File.exe"
The only work around I found so far is:
Dim filebat As String = "C:" & vbCrLf &
"cd.." & vbCrLf &
"cd.." & vbCrLf &
"cd.." & vbCrLf &
"cd.." & vbCrLf &
"cd.." & vbCrLf &
"cd ""My Folder""" & vbCrLf &
"File.exe"
My.Computer.FileSystem.WriteAllText("C:\file.bat", filebat, False, System.Text.Encoding.ASCII)
Threading.Thread.Sleep(200) 'wait for file
Dim procStartInfo As New ProcessStartInfo
Dim procExecuting As New Process
With procStartInfo
.UseShellExecute = True
.FileName = "C:\file.bat"
.WindowStyle = ProcessWindowStyle.Normal
.Verb = "runas" 'add this to prompt for elevation
End With
procExecuting = Process.Start(procStartInfo)
procExecuting.WaitForExit()
But I know I should have to do this. It is weird because I know I have executed files with spaces in folder name.
I did upgrade to visual studio 2019 so wondering if this is a bug.
Continue reading...
I tried the following
Dim procStartInfo As New ProcessStartInfo
Dim procExecuting As New Process
With procStartInfo
.UseShellExecute = True
.FileName = "C:\My Folder\File.exe"
.WindowStyle = ProcessWindowStyle.Normal
.Verb = "runas" 'add this to prompt for elevation
End With
procExecuting = Process.Start(procStartInfo)
procExecuting.WaitForExit()
'Also tried the following
'.FileName = "C:\" & "'" & "My Folder\" & "'" & "File.exe"
'.FileName = "C:\" & """"My Folder\"""" & "File.exe"
'.FileName = "C:\" & ""My Folder\"" & "File.exe"
The only work around I found so far is:
Dim filebat As String = "C:" & vbCrLf &
"cd.." & vbCrLf &
"cd.." & vbCrLf &
"cd.." & vbCrLf &
"cd.." & vbCrLf &
"cd.." & vbCrLf &
"cd ""My Folder""" & vbCrLf &
"File.exe"
My.Computer.FileSystem.WriteAllText("C:\file.bat", filebat, False, System.Text.Encoding.ASCII)
Threading.Thread.Sleep(200) 'wait for file
Dim procStartInfo As New ProcessStartInfo
Dim procExecuting As New Process
With procStartInfo
.UseShellExecute = True
.FileName = "C:\file.bat"
.WindowStyle = ProcessWindowStyle.Normal
.Verb = "runas" 'add this to prompt for elevation
End With
procExecuting = Process.Start(procStartInfo)
procExecuting.WaitForExit()
But I know I should have to do this. It is weird because I know I have executed files with spaces in folder name.
I did upgrade to visual studio 2019 so wondering if this is a bug.
Continue reading...