简体   繁体   English

C#Windows应用程序可以在Visual Studio中正常启动外部exe,但安装后无法启动

[英]c# windows application launches external exe's fine in visual studio but not when installed

I have a program which is a authoring tool for making courses. 我有一个程序,它是制作课程的创作工具。 I decided to create a screen recording feature for it using camstudio. 我决定使用camstudio为它创建一个屏幕录制功能。 The code I used to launch the exe is: 我用来启动exe的代码是:

Process process = new Process();
process.StartInfo.FileName = "Recorder.exe";
process.StartInfo.Arguments = "";
process.Start();

When I am running the program in visual studio and step through the code it works fine and launches the recorder.exe with no errors. 当我在Visual Studio中运行该程序并逐步执行代码时,它可以正常工作,并且没有任何错误地启动recorder.exe。 BUT when I make an installer for the project in visual studio 2010 and install the program, the program crashes when I press the button which should launch the recorder.exe. 但是,当我在Visual Studio 2010中为该项目制作安装程序并安装该程序时,当我按下应该启动recorder.exe的按钮时,程序崩溃。

I checked the windows error log and here is what it told me: 我检查了Windows错误日志,这是它告诉我的内容:

Application: Perform.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. 应用程序:Perform.exe Framework版本:v4.0.30319说明:该进程由于未处理的异常而终止。 Exception Info: System.ComponentModel.Win32Exception Stack: at System.Diagnostics.Process.StartWithShellExecuteEx(System.Diagnostics.ProcessStartInfo) at System.Diagnostics.Process.Start() at P2Designer.Window1.scriptUpdatePerform(System.Object, System.Windows.RoutedEventArgs) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean) at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs) at System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs) at DevComponents.WpfRibbon.ButtonDropDown.OnClick() at DevComponents.WpfRibbon.ButtonDropDown.x984587de9d70aaba(System.Object) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, In 异常信息:System.ComponentModel.Win32Exception堆栈:在System.Diagnostics.Process.StartWithShellExecuteEx(System.Diagnostics.ProcessStartInfo)在System.Diagnostics.Process.Start()在P2Designer.Window1.scriptUpdatePerform(System.Object,System.Windows。 System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object,System.Windows.RoutedEventArgs)上的System.Windows.EventRoute.InvokeHandlersImpl(System.Object,System.Windows.RoutedEventArgs,Boolean)上的System.Windows.UIElement.RaiseEventImpl (DevComponents.WpfRibbon.ButtonDropDown.OnClick()处的System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs)处的System.Windows.DependencyObject,System.Windows.RoutedEventArgs)DevComponents.WpfRibbon.ButtonDropDown.x984587de9d70aaba(System.Object )在System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate,System.Object,Int32)在MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object,System.Delegate,System.Object,在 t32, System.Delegate) at System.Windows.Threading.DispatcherOperation.InvokeImpl() at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object) at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) at System.Windows.Threading.DispatcherOperation.Invoke() at System.Windows.Threading.Dispatcher.ProcessQueue() at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef) at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delega t32,位于System.Windows.Threading.DispatcherOperation.InvokeImpl()位于System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)位于System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext,System。 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object,Boolean)处的Threading.ContextCallback,System.Object,Boolean)在System.Threading.ExecutionContext.Run(System.Threading。 System.Windows.Threading.DispatcherOperation.Invoke()在System.Windows.Threading.Dispatcher.ProcessQueue()在System.Windows.Threading.Dispatcher.WndProcHook(IntPtr,Int32)上的ExecutionContext,System.Threading.ContextCallback,System.Object) ,MS.Win32.HwndWrapper.WndProc(IntPtr,Int32,IntPtr,IntPtr,布尔ByRef)的MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)的System.Windows.Threading.ExceptionWrapper。 InternalRealCall(System.Delega te, System.Object, Int32) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate) at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr) at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef) at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame) at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame) at System.Windows.Threading.Dispatcher.Run() at System.Windows.Application.RunDispatcher(System.Object) at System.Windows.Application.RunInternal(System.Windows.Window) at System.Windows.Application.Run(System.Windows.Window) at System.Windows.Application.Run() at P2Designer.App.Main() 在MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object,System.Delegate,System.Object,Int32,System.Delegate)在System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System。 Windows.Threading.DispatcherPriority,System.TimeSpan,System.Delegate,System.Object,Int32,位于MS.Win32.HwndSubclass.SubclassWndProc(IntPtr,Int32,IntPtr,IntPtr),位于MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows。 System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)中的Interop.MSG ByRef)。 System.Windows.Application.Run.Dispatcher.Run()(系统.System.Windows.Application.RunInternal(System.Windows.Window))。System.Windows.Application.Run(System.Windows.Window) P2Designer.App.Main()上的.Windows.Application.Run()

Found a similar unanswered question on here: Why i'm getting a win32exception once i'm starting the Process? 在此处找到类似的未解决问题: 为什么启动流程后为什么会出现win32exception?

If more information is need please let me know and I'll provide as much as I can. 如果需要更多信息,请告知我,我们将尽力提供。 I have seen similar questions on here and other forums but none have given me the answer. 我在这里和其他论坛上看到过类似的问题,但没有一个给我答案。 Thanks, Jim 谢谢,吉姆

(Per Josh Gallagher's suggestion, reposting comment as answer) (根据Josh Gallagher的建议,将评论重新发布为答案)

That is likely an issue with current working directory (cwd). 当前工作目录(cwd)可能是一个问题。 IIRC, VS actually sets cwd to the output folder when launching your exe in debug. IIRC,VS实际上在调试中启动exe时将cwd设置为输出文件夹。 However, in read world, cwd really depends on how exe is launched and does not necessarily point to the same folder where your target exe is. 但是,在阅读环境中,cwd实际上取决于exe的启动方式,并不一定指向目标exe所在的文件夹。

You can actually test it easily by simply writing the value of Environment.CurrentWorkingDirectory (or something like that) and see what it points to. 您实际上可以通过简单地编写Environment.CurrentWorkingDirectory(或类似的东西)的值并查看其指向来轻松地对其进行测试。 alternatively try to hardcode full path for now while troubleshooting. 或者,尝试在进行故障排除时立即对完整路径进行硬编码。 Either way, my money are on the fact that your context for execution is in wrong dir. 无论哪种方式,我的钱都是基于您执行上下文错误的事实。

Wrap your code in 包装您的代码

try
{
  Process process = new Process();
  process.StartInfo.FileName = "Recorder.exe";
  process.StartInfo.Arguments = "";
  process.Start();
}
catch(Exception e)
{
   //Log using your logger the full error message.
}

This will give you indication of what's faulting your program. 这将给您指示程序出了什么问题。 Difference between success in VS and failure in real world is likely some context such as current working directory. VS成功与实际失败之间的差异可能是在某些情况下产生的,例如当前的工作目录。 But at least this will give you information as to what is the nature of the error that causes it to crash. 但这至少会为您提供有关导致错误崩溃的错误性质的信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#WPF应用程序在Visual中启动,但在直接运行时无法启动 - C# WPF application launches in Visual, but not when ran directly Visual Studio C#EXE而不是.application - Visual Studio C# EXE instead of .application 在Visual Studio 2015中使用C#为Windows独立应用程序创建exe - Creating an exe for a Windows standalone application using C# in Visual Studio 2015 如何防止在 Windows 窗体应用程序构建中创建 .exe.config(Visual Studio 社区 2019 - C#) - How prevent to create a .exe.config in a Windows Forms Application build (Visual Studio Community 2019 - C#) 简单的 C# 应用程序无法正常工作,在 Visual Studio 中运行时工作正常 - Simple C# application not working correctly, works fine when run from within Visual Studio Visual Studio Windows 服务 c# exe 文件丢失 - Visual Studio Windows Service c# exe file missing 如何在没有其他人下载的情况下将exe链接到按钮Visual Studio 2015(C#Windows窗体应用程序) - How to link a exe to a button without having other people to download it Visual Studio 2015 (C# Windows Forms application) 从Windows运行时,C#/ C ++应用程序崩溃,但不是从Visual Studio运行 - C# / C++ application crashes when run from Windows, but not from Visual Studio Visual C#Express和Visual C#Professional之间的已编译EXE Windows桌面应用程序中的差异 - Difference in compiled EXE Windows desktop application between Visual C# Express and Visual C# Professional 我的 Windows 服务应用程序在 onStart 时未运行(ODBC、C#、Visual Studio 2008) - My Windows Service Application is not running when onStart (ODBC, C#, Visual Studio 2008)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM