Vb.net Win32Exception“;系统找不到指定的文件";

Vb.net Win32Exception“;系统找不到指定的文件";,vb.net,file,exception,win32exception,Vb.net,File,Exception,Win32exception,这已经困扰了我6个小时了 它究竟是如何解决的。我希望程序运行一个批处理文件(IP),它位于资源和应用程序路径(即bin/debug和/release)中 批处理文件在自身双击时工作 我做错了什么?这是我的密码。我在网上什么都试过了 **Private Sub Button3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim OK = MessageBox.Sh

这已经困扰了我6个小时了

它究竟是如何解决的。我希望程序运行一个批处理文件(IP),它位于资源和应用程序路径(即bin/debug和/release)中

批处理文件在自身双击时工作

我做错了什么?这是我的密码。我在网上什么都试过了

**Private Sub Button3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim OK = MessageBox.Show("Are you sure you want to renew the computer's IP?", "IP Renew?", MessageBoxButtons.OKCancel)
If OK = DialogResult.OK Then
Dim IP As New ProcessStartInfo
IP.FileName = Application.StartupPath & "\IP.bat"
IP.WindowStyle = ProcessWindowStyle.Hidden
Process.Start(IP)
End If
End Sub**
以下是异常详细信息:

System.ComponentModel.Win32Exception was unhandled
ErrorCode=-2147467259
Message=The system cannot find the file specified
NativeErrorCode=2
Source=System
StackTrace:
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at Internet_Connection_Availability.Form1.Button3_Click_1(Object sender, EventArgs e) Form1.vb:line 228
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at Internet_Connection_Availability.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:

有人告诉我这个论坛是最好的一个

Process.Start(IP)


我也遇到了同样的问题,原因是应用程序中的文件夹名中有空格。StartupPath

系统找不到您指定的文件,我打赌如果您能看到IP.FileName是什么,您可以找到它。尝试在设置MessageBox.Show(IP.FileName…)后立即放置它。尝试使用SysInternal的ProcMon监视进程运行。将向您显示进程要查找的确切位置
IP.bat
。知道这一点可能会使您更容易解决问题。它实际上是在显示文件的正确位置,因此问题不在于文件!是否已验证权限是否正确?请尝试使用断点。
Process.Start("""" & IP & """")