Error using Process.Start()

99封情书 提交于 2019-12-14 03:18:36

问题


I am trying to run sysprep from a vb.net application, and even though the path and file name are confirmed accurate, it is returning that it can not find the file. I've tried using process.start, declaring as a new process, declaring the path separate from the file name. Here is the code as I would like it to be written, maybe someone could try it out and see if they come up with a solution?

Private Sub btnsysp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsysp.Click
    Dim P As New System.Diagnostics.Process()
    P.StartInfo.UseShellExecute = True
    P.StartInfo.WorkingDirectory = "C:\Windows\System32\sysprep\"
    P.StartInfo.FileName = "sysprep.exe"
    P.Start()
End Sub

回答1:


I think you just stumbled uppon the http://msdn.microsoft.com/en-us/library/aa384187.aspx

The %windir%\System32 directory is reserved for 64-bit applications. Most DLL file names were not >changed when 64-bit versions of the DLLs were created, so 32-bit versions of the DLLs are stored in a >different directory. WOW64 hides this difference by using a file system redirector.

What happens is that your launch request (from a 32-bit process) is being redirected to %windir%\SysWOW64\sysprep\sysprep.exe. Since there's no 32-bit version of this particular executable on SysWOW64 the launch fails.

The easiest way to bypass this problem is using reference to %windir%\SysNative\sysprep\sysprep.exe instead of %windir%\System32\sysprep\sysprep.exe which is what you have.



来源:https://stackoverflow.com/questions/20708242/error-using-process-start

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!