getlasterror

when CreateDirectory returns ERROR_ACCESS_DENIED and “shouldn't”

余生长醉 提交于 2019-12-06 09:51:59
My Win32 app A1 (actually a collection of processes) is trying to use CreateDirectory to create a directory D1 within parent directory P. The path to P is the value of the TMP environment variable, which makes P a potentially busy but generally permissive place. The vast majority of the time, everything works fine, but, rarely, CreateDirectory fails and GetLastError then returns ERROR_ACCESS_DENIED , the meaning of which in this context is not documented. I wrote a test application A2 which does nothing but repeatedly create and delete a directory D2 as fast as it can within P, and I chose a

vc编程实现sys文件的安装

五迷三道 提交于 2019-12-04 20:29:24
#include <windows.h> #include <winsvc.h> #include <conio.h> #include <stdio.h> #define DRIVER_NAME "123467" #define DRIVER_PATH "..\\HelloDDK.sys" //装载NT驱动程序 BOOL LoadNTDriver(char* lpszDriverName,char* lpszDriverPath) { /************************ 加载NT驱动的代码******************************* ① 调用OpenSCManager,打开SCM管理器.如果返回NULL,则返回失败,否则继续 ② 调用CreateService,创建服务,创建成功则转步骤 ⑥ ③ 用GetLastError的得到错误返回值 ④ 返回值为ERROR_IO_PENDING,说明服务已经创建过,用OpenService打开此服务. ⑤ 返回值为其他值, 创建武服务失败,返回失败. ⑥ 调用StartService开启服务 ⑦ 成功返回 ************************************************************************/ char szDriverImagePath[256];

CreateProcess succeeds, but GetLastError() returns access denied

淺唱寂寞╮ 提交于 2019-12-04 02:01:40
问题 I'm having a little confusion due to conflicting return values from CreateProcess() and GetLastError() . When I use CreateProcess() in a manner similar to below, it succeeds and appears to accomplish its required tasks. Yet, GetLastError() still returns Access is Denied. If access is denied, why is does it appear to complete the task. In contrast, if CreateProcess() succeeds, why is GetLastError() returning access denied? Or is my use of GetLastError() incorrect? Am I only supposed to use it

How to retrieve information from multiple/dual code signatures on an executable file

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've been using the following code (taken from KB323809 article ) to retrieve information about the code signature on the executable file. This works fine for a single digital signature. But how to retrieve information for multiple code signatures? In that case the Microsoft code below simply retrives info only for the first signature. My thought was to call CryptMsgGetParam with CMSG_SIGNER_COUNT_PARAM to get the number of signatures and then pass each signature index to the subsequent call to CryptMsgGetParam with CMSG_SIGNER_INFO_PARAM

c++学习之:根据GetLastError()返回值获取错误信息

旧巷老猫 提交于 2019-12-02 18:38:20
注:本文属于转载,详细出处忘记了,如果找到了会加上出处。 VC中GetLastError()获取错误信息的使用在VC中编写应用程序时,经常需要涉及到错误处理问题。许多函数调用只用TRUE和FALSE来表明函数的运行结果。一旦出现错误,MSDN中往往会指出请用GetLastError()函数来获得错误原因。 可问题是,GetLastError()返回的只是一个双字节数值(DWORD)。OH,MY GOD!目前Win32的出错编号已经从0排到11031,而这还不是错误编码的全部。因为错误代码还在不断增加。 我想没有人愿意自己去查出错编码所对应的错误信息。好在Windows(Windows95以上, Window NT 3.1以上)已经提供了现成的错误信息处理函数:FormatMessage()。 以下是用FormatMessage()得到由GetLastError()返回的出错编码所对应错误信息的示例: LPVOID lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), //

OpenProcess error 87 invalid parameter

拥有回忆 提交于 2019-12-02 05:33:07
问题 I'm trying to write a program which executes make.exe from MinGW distribution in the current directory and makes use of its STDOUT data and exit code. I have a handle to process STDOUT where I fetch data from, created with CreatePipe. When I get an ERROR_HANDLE_EOF on that pipe I assume the process has exited and try to get its exit code: if(session->pid == 0) return; HANDLE hp = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_TERMINATE, TRUE, session->pid); if(hp == NULL) { printf(

CreateProcess succeeds, but GetLastError() returns access denied

拜拜、爱过 提交于 2019-12-01 12:46:01
I'm having a little confusion due to conflicting return values from CreateProcess() and GetLastError() . When I use CreateProcess() in a manner similar to below, it succeeds and appears to accomplish its required tasks. Yet, GetLastError() still returns Access is Denied. If access is denied, why is does it appear to complete the task. In contrast, if CreateProcess() succeeds, why is GetLastError() returning access denied? Or is my use of GetLastError() incorrect? Am I only supposed to use it when CreateProcess() returns a failed value? (My justification for the below behavior was that I

ReadFile() says it failed, but the error code is ERROR_SUCCESS

走远了吗. 提交于 2019-12-01 09:48:56
I'm using ReadFile() on Windows to read data from a serial port. This code was working fine at one point in time, but it's now failing and I'm trying to track down the source of the problem, so I doubt it's a problem with the serial configuration or timeouts, since none of that has changed. ReadFile() returns false, indicating that an error occurred. However, when I immediately check the value of GetLastError() , it returns 0, which is ERROR_SUCCESS . The number of bytes read is 0, so I'm inclined to think that indeed something has gone wrong, but that error code is utterly useless. Any ideas?

ReadFile() says it failed, but the error code is ERROR_SUCCESS

我只是一个虾纸丫 提交于 2019-12-01 09:30:41
问题 I'm using ReadFile() on Windows to read data from a serial port. This code was working fine at one point in time, but it's now failing and I'm trying to track down the source of the problem, so I doubt it's a problem with the serial configuration or timeouts, since none of that has changed. ReadFile() returns false, indicating that an error occurred. However, when I immediately check the value of GetLastError() , it returns 0, which is ERROR_SUCCESS . The number of bytes read is 0, so I'm

C++代码注入

我们两清 提交于 2019-12-01 02:38:05
一、C++代码注入原则: 在注入代码中不允许使用API。 在注入代码中不允许使用全局变量。 在注入代码中不允许使用字符串(编译时也被当做全局变量)。 在注入代码中不允许使用函数嵌套。 二、注入代码编写思路: 在本进程通过获取 LoadLibraryA 与 GetProcess 函数的地址。 涉及一组参数,里面包括 {函数地址、模块地址、函数名、传递参数}。 传入进去后,利用LoadLibraryA 与 GetProcess 函数,在注入代码中直接现场"加载模块-获取函数-调用",来达到调用API的目的。 三、编写过程的几个坑: 使用typedef定义函数指针,先在msdn搜索函数原型,复制过去,将名字定义成指针并大写。 申请内存时的权限,参数的内存使用 PAGE_READWRITE权限;代码的内存使用PAGE_EXECUTE_READWRITE权限,否则代码无法被执行。 一定要预先在msdn上搜索确定函数要加载的模块以及函数名,这一步很容易出错。如果出错只能调试被注入程序获取结果,比较麻烦。 四、olldbg调试思路: 在 "选项-调试设置-事件"中勾选“中断于新线程”。 注入后就可以在新线程上一步步进行调试。 五、源代码(练习了两套,一套是注入MessageBoxA,另一套是注入CreateFileA) 1 // 代码注入.cpp : 此文件包含 "main" 函数