[英]how to get process name and date time stamp in native C++
In Native C++, how can I get the current process Name and date time. 在Native C ++中,如何获取当前进程的名称和日期时间。 I am not a C++ programmer. 我不是C ++程序员。
In C#, it is very trivial to do it like this: 在C#中,这样做很简单:
Process name: 流程名称:
Process.GetCurrentProcess().ProcessName
Date Time: 约会时间:
DateTime.Now.ToString("yyyy-MM-dd_HH.mm.ss.ff")
How can they be retrieved in C++ native? 如何在C ++本机中检索它们?
To get the name of the current process you can use GetModuleFileName()
: 要获取当前进程的名称,可以使用GetModuleFileName()
:
char exe_path[MAX_PATH];
GetModuleFileName(NULL, exe_path, MAX_PATH);
You can then extract the part of exe_path
after the last \\
character. 然后,您可以提取exe_path
中最后一个\\
字符之后的部分。
To get the current time, you can use std::time()
. 要获取当前时间,可以使用std::time()
。
GetSystemTime GetSystemTime
Syntax 句法
void WINAPI GetSystemTime(
__out LPSYSTEMTIME lpSystemTime
);
Parameters: lpSystemTime [out] 参数: lpSystemTime [输出]
A pointer to a SYSTEMTIME structure to receive the current system date and time. 指向SYSTEMTIME结构的指针,以接收当前系统日期和时间。 The lpSystemTime parameter must not be NULL. lpSystemTime参数不能为NULL。 Using NULL will result in an access violation. 使用NULL将导致访问冲突。
Return value: This function does not return a value or provide extended error information. 返回值:该函数不返回值或提供扩展的错误信息。
Remarks: To set the current system date and time, use the SetSystemTime function. 备注:要设置当前系统日期和时间,请使用SetSystemTime函数。
Requirements: Minimum supported client Windows 2000 Professional 要求:支持的最低客户端Windows 2000 Professional
Minimum supported server: Windows 2000 Server 支持的最低服务器: Windows 2000 Server
Header : Winbase.h (include Windows.h) 标题: Winbase.h(包括Windows.h)
Library : Kernel32.lib 程式库: Kernel32.lib
DLL : Kernel32.dll DLL文件: Kernel32.dll
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724390(v=vs.85).aspx http://msdn.microsoft.com/zh-CN/library/windows/desktop/ms724390(v=vs.85).aspx
And for process name: 对于进程名称:
QueryFullProcessImageName function QueryFullProcessImageName函数
GetModuleFileNameEx function GetModuleFileNameEx函数
Process and Thread Functions can be found here 进程和线程函数可以在这里找到
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.