标签: win32exception

System.ComponentModel.Win32Exception:操作成功完成

我有时会在运行Windows窗体应用程序时遇到此异常:

System.ComponentModel.Win32Exception: The operation completed successfully
   at System.Drawing.BufferedGraphicsContext.CreateCompatibleDIB(IntPtr hdc, IntPtr hpal, Int32 ulWidth, Int32 ulHeight, IntPtr& ppvBits)
   at System.Drawing.BufferedGraphicsContext.CreateBuffer(IntPtr src, Int32 offsetX, Int32 offsetY, Int32 width, Int32 height)
   at System.Drawing.BufferedGraphicsContext.AllocBuffer(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle)
   at System.Drawing.BufferedGraphicsContext.AllocBufferInTempManager(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle)
   at System.Drawing.BufferedGraphicsContext.Allocate(IntPtr targetDC, Rectangle targetRectangle)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.DataGridView.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.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Run Code Online (Sandbox Code Playgroud)

可能是什么原因造成的?

.net c# win32exception winforms

25
推荐指数
2
解决办法
3万
查看次数

.Net Core 2.0 Process.Start抛出"指定的可执行文件不是此OS平台的有效应用程序"

我需要使用与用户Windows上关联的这两种文件类型的任何可执行文件自动执行.reg文件和.msi文件.

.NET核2.0的Process.Start(字符串文件名)文档说:"文件名并不需要代表一个可执行文件它可以是任何一种扩展已经安装在系统上的应用程序相关的任何类型的文件."

然而

using(var proc = Process.Start(@"C:\Users\user2\Desktop\XXXX.reg")) { } //.msi also
Run Code Online (Sandbox Code Playgroud)

给我

System.ComponentModel.Win32Exception (0x80004005): The specified executable is not a valid application for this OS platform.
   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start(String fileName)
Run Code Online (Sandbox Code Playgroud)

使用ErrorCode和HResult -2147467259,以及NativeErrorCode 193.

相同的代码在.Net Framework 3.5或4控制台应用程序中工作.

我不能指定精确的exe文件路径作为方法的参数,因为用户的环境是变体(包括Windows版本)并且不受我的控制.这也是为什么我需要将程序移植到.Net Core,尝试使其作为SCD控制台应用程序工作,以便不需要安装特定的.Net Framework或.NET Core版本.

Visual Studio调试运行和发布为win-x86 SCD时都会抛出异常.我的电脑是Win7 64bit,我确信.reg和.msi与常规程序一样,与Windows PC一样.

有解决方案吗?任何帮助表示赞赏.

c# win32exception .net-core

22
推荐指数
4
解决办法
1万
查看次数

抛出Win32Exception

我最近编写了很多涉及与Win32 API互操作的代码,并且开始想知道什么是处理由Windows API函数调用引起的本机(非托管)错误的最佳方法.

目前,对本机函数的调用如下所示:

// NativeFunction returns true when successful and false when an error
// occurred. When an error occurs, the MSDN docs usually tell you that the
// error code can be discovered by calling GetLastError (as long as the
// SetLastError flag has been set in the DllImport attribute).
// Marshal.GetLastWin32Error is the equivalent managed function, it seems.
if (!WinApi.NativeFunction(param1, param2, param3))
    throw new Win32Exception();
Run Code Online (Sandbox Code Playgroud)

引发异常的行可以等效地重写,我相信:

throw new Win32Exception(Marshal.GetLastWin32Error());
Run Code Online (Sandbox Code Playgroud)

现在,这很好,它会抛出一个异常,包含设置的Win32错误代码以及作为MessageException对象属性的(通常)人类可读的错误描述.但是,我一直认为修改/包装至少一些(如果不是全部)这些异常是明智的,这样它们会给出一个稍微更多的面向上下的错误消息,即在本机代码的任何情况下都更有意义.正在使用.我考虑了几个替代方案:

  1. 在构造函数中指定自定义错误消息Win32Exception.

    throw new …
    Run Code Online (Sandbox Code Playgroud)

c# winapi exception win32exception

19
推荐指数
1
解决办法
9710
查看次数

使用 Process.Start() 打开文件夹时访问被拒绝异常

我在 C# 中有一个 winforms 应用程序,我必须在其中打开某个文件夹。我用

System.Diagnostics.Process.Start(pathToFolder);
Run Code Online (Sandbox Code Playgroud)

这导致以下异常:

System.ComponentModel.Win32Exception (0x80004005): 访问被拒绝

在 System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)

在 System.Diagnostics.Process.Start()

在 System.Diagnostics.Process.Start(ProcessStartInfo startInfo)

在 MyApp.openLogFolderToolStripMenuItem_Click(Object sender, EventArgs e)

我已经检查了以下事项:

  • 文件夹存在
  • 用户有权访问该文件夹(可以在资源管理器中打开它)

另一件事是,如果我使用Process.Start()打开此文件夹中的文件,它会起作用。

谁能给我一个提示?
干杯

编辑 我的目标是在资源管理器中打开文件夹。的pathToFolder是一样的东西H:\Something\App.Name\Log

c# win32exception process.start winforms

14
推荐指数
2
解决办法
3万
查看次数

Win32Exception:目录名无效

我正在尝试作为一个不同的用户运行一个进程,该用户在运行Vista并启用了UAC的2台不同计算机上具有管理员权限但在其中一个中我得到一个Win32Exception,其中显示"目录名称无效"

谁能告诉我我的代码有什么问题?

var myFile = "D:\\SomeFolder\\MyExecutable.exe";
var workingFolder = "D:\\SomeFolder";
var pInfo = new System.Diagnostics.ProcessStartInfo();
pInfo.FileName = myFile;
pInfo.WorkingDirectory = workingFolder;
pInfo.Arguments = myArgs;
pInfo.LoadUserProfile = true;
pInfo.UseShellExecute = false;
pInfo.UserName = {UserAccount};
pInfo.Password = {SecureStringPassword};
pInfo.Domain = ".";

System.Diagnostics.Process.Start(pInfo);
Run Code Online (Sandbox Code Playgroud)

UPDATE

执行上述代码的应用程序具有requireAdministrator执行级别.我甚至将工作文件夹设置为"Path.GetDirectoryName(myFile)""New System.IO.FileInfo(myFile).DirectoryName"

c# processstartinfo win32exception

13
推荐指数
2
解决办法
3万
查看次数

Win32Exception没有足够的存储空间来处理此命令

通过我为MaxTo自动崩溃收集,我得到了以下崩溃报告:

V8.12.0.0 - System.ComponentModel.Win32Exception - :Void UpdateLayered():0
Version: MaxTo8.12.0.0
Exception: System.ComponentModel.Win32Exception
Error message: Not enough storage is available to process this command
Stack trace: 
  at System.Windows.Forms.Form.UpdateLayered()
  at System.Windows.Forms.Form.OnHandleCreated(EventArgs e)
  at System.Windows.Forms.Control.WmCreate(Message& m)
  at System.Windows.Forms.Control.WndProc(Message& m)
  at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
  at System.Windows.Forms.ContainerControl.WndProc(Message& m)
  at System.Windows.Forms.Form.WmCreate(Message& m)
  at System.Windows.Forms.Form.WndProc(Message& m)
  at MaxTo.MainForm.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.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Run Code Online (Sandbox Code Playgroud)

另一个堆栈跟踪:

Version: MaxTo2009.9.0.0
Exception: System.ComponentModel.Win32Exception
Error message: Not enough storage is available to …
Run Code Online (Sandbox Code Playgroud)

.net c# winapi win32exception

12
推荐指数
2
解决办法
3万
查看次数

启动进程时出现System.ComponentModel.Win32Exception - 找不到文件,但文件存在

我正在尝试为自动启动创建一个经理.它应该读取一个XML文件,然后以自定义延迟启动我的程序.例如:

<startup id="0">
    <name>Realtek Audio Manager</name>
    <process arguments="-s">C:\Program Files\Realtek\Audio\HDA\RtkNGUI64.exe</process>
    <delay>5</delay>
</startup>
Run Code Online (Sandbox Code Playgroud)

这将C:\Program Files\...\RtkNGUI64.exe -s在5秒后运行指定的进程().

现在,有三个程序无法启动,给我一个System.ComponentModel.Win32Exception:"Das System kann die angegebene Datei nicht finden." ("系统无法找到指定的文件.")

但是XML被正确解析,我想要启动的文件位于我在XML文件中指定的位置.

该问题仅涉及这三个文件:
Intel HotkeysCmd - C:\ Windows\System32\hkcmd.exe
Intel GFX Tray - C:\ Windows\System32\igfxtray.exe
Intel Persistance - C:\ Windows\System32\igfxpers.exe

我认为问题来自文件的位置:它们都位于C:\ Windows\System32中,而所有其他工作程序都位于外部(C:\ Program Files,C:\ Program Files(x86) ,D:\ Program Files,%AppData%)

我是否必须为我的程序提供某种访问权限才能在C:\ Windows\System32中启动程序?我该怎么办?

如果没有,那么我在这些程序中出错的原因是什么?

编辑 - 我的代码:

delegate(object o)
{
    var s = (Startup) o;
    var p = new System.Diagnostics.Process
                {
                    StartInfo =
                        new System.Diagnostics.ProcessStartInfo(s.Process, …
Run Code Online (Sandbox Code Playgroud)

c# exception file-not-found win32exception file-access

8
推荐指数
1
解决办法
4万
查看次数

使用AvalonDock 2.0时未处理的'System.ComponentModel.Win32Exception'

我正在使用AvalonDock 2.0,当我打开一个dock容器时,在调试模式下应用程序崩溃(它在没有调试的情况下运行时工作正常).我得到以下异常:

WindowsBase.dll中发生了未处理的"System.ComponentModel.Win32Exception"类型异常

附加信息:操作成功完成

我遇到了这个答案,建议取消选中"例外设置"中的框.有线的事情是它第一次使用它.但它不再存在了.我试过其他机器也不行.任何有关如何解决此问题的建议.
Avalon代码(第5行引发的异常)

protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) {
            if (msg == Win32Helper.WM_WINDOWPOSCHANGING) {
                if (_internalHost_ContentRendered) {
                    // the below line throw the exception
                    Win32Helper.SetWindowPos(_internalHwndSource.Handle, Win32Helper.HWND_TOP, 0, 0, 0, 0, Win32Helper.SetWindowPosFlags.IgnoreMove | Win32Helper.SetWindowPosFlags.IgnoreResize);
                }
            }
            return base.WndProc(hwnd, msg, wParam, lParam, ref handled);
        }
Run Code Online (Sandbox Code Playgroud)

c# wpf exception win32exception avalondock

7
推荐指数
1
解决办法
3376
查看次数

获取进程路径时访问被拒绝

我试图通过pid获取进程路径,但我得到Win32Exception(访问ID被拒绝).

代码如下所示:

string path = Process.GetProcessById(pid).MainModule.FileName
Run Code Online (Sandbox Code Playgroud)

我已经尝试将OpenProcess与GetModuleFileNameEx一起使用,但OpenProcess返回0.我甚至尝试根据C#启用SeDebugPrivilege - 如何启用SeDebugPrivilege但它没有帮助.

上面的代码适用于大多数进程,但抛出SynTPHelper.exe(Synaptics Pointing Device Helper)的错误.应用程序在与我的代码相同的用户名下运行.两者,我的应用程序和进程都以64位运行.

是否可以在以管理员身份运行我的应用程序的情况下检索路径?

编辑

任务管理器能够"打开文件位置",即使我没有以管理员身份运行它.

c# winapi process access-denied win32exception

6
推荐指数
1
解决办法
1万
查看次数

"Quota Exceeded"Win32Exception的诊断

大部分的工作作为一个.NET开发人员的时间给了我们自由地浪费时间在我们的高级别的抽象世界,但有时现实踢你的私处,并告诉你找到一个男人谁真正理解.

我刚刚有过这样的经历之一.我认为将角落数据列为项目列表就足以让您了解我们的内容:

  • Win2008服务器
  • 64位环境
  • 多个客户端同时使用的WPF应用程序
  • Application是一个启动器,使用Process.Start()打开其他应用程序
  • 偶尔我们会得到下面列出的例外情况
System.ComponentModel.Win32Exception (0x80004005): Not enough quota is
available to process this command
at MS.Win32.UnsafeNativeMethods.PostMessage(HandleRef hwnd,
   WindowMessage msg, IntPtr   wparam, IntPtr lparam)
at System.Windows.Interop.HwndTarget.UpdateWindowSettings(Boolean
   enableRenderTarget, Nullable`1 channelSet)
at System.Windows.Interop.HwndTarget.UpdateWindowPos(IntPtr lParam)
at System.Windows.Interop.HwndTarget.HandleMessage(WindowMessage msg,
   IntPtr wparam, IntPtr lparam)
at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr hwnd,
   Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, 
   Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate
   callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object
   source, Delegate …
Run Code Online (Sandbox Code Playgroud)

.net wpf performance winapi win32exception

6
推荐指数
1
解决办法
5480
查看次数