我有一个文件main.exe,但是不知道放在哪个盘哪个文件夹中,我想得到这个程序的完全路径,要用什么函数?怎样做?谢谢!
解决方案 »
- c语言怎样判断网络状态
- MoveFirst()不能移动到开头
- 关于vc8.0制作带有编辑框与按钮的ocx(不耻下问)
- http://yacsoft.com/cn/tu/ 包你满意
- 小型数据库中的3组权限实现,300分等着高手。我在Single Doc/View 已经实现数据管理模块了(odbc)
- 为什么CListView 和 CTreeView 不能当作基类?
- 大家帮我看看GDI+ Bitmap::FromResource()怎么搞的?
- 请教大侠,怎么把工程的编译状态由release 改为 debug状态???
- 关于分辨率的问题......
- 一个问了三天无人回答的关键盘钩子的问题!
- 我做一个win32 Dynamic link lib,使用An Empty DLL Project,我想两个文件都export怎么做
- .bmp图片显示的问题
#include <windows.h>
#include <stdio.h>
#include "psapi.h"void PrintModules( DWORD processID )
{
HMODULE hMods[1024];
HANDLE hProcess;
DWORD cbNeeded;
unsigned int i; // Print the process identifier. printf( "\nProcess ID: %u\n", processID ); // Get a list of all the modules in this process. hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );
if (NULL == hProcess)
return; if( EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded))
{
for ( i = 0; i < (cbNeeded / sizeof(HMODULE)); i++ )
{
char szModName[MAX_PATH]; // Get the full path to the module's file. if ( GetModuleFileNameEx( hProcess, hMods[i], szModName,
sizeof(szModName)))
{
// Print the module name and handle value. printf("\t%s (0x%08X)\n", szModName, hMods[i] );
}
}
} CloseHandle( hProcess );
}int main( )
{
// Get the list of process identifiers. DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i; if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
return 1; // Calculate how many process identifiers were returned. cProcesses = cbNeeded / sizeof(DWORD); // Print the name of the modules for each process. for ( i = 0; i < cProcesses; i++ )
PrintModules( aProcesses[i] ); system( "PAUSE" );
return 0;
}
谢谢你,我要的不是这种。我要的是单独的外挂小程序,指定文件或者程序名称,就能够找到文件路径。TO WingForce(初六,履霜,坚冰至。)
谢谢你,你的得到文件路径的函数是GetModuleFileNameEx()和GetModuleFileName差不多。我要的就好是搜索文件一样。
你能具体给我几个函数吗?谢谢!那种不管程序有没有运行都能够搜索到的。
#include <string.h>
#include <stdio.h>int main(int argc, char *argv[])
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind = INVALID_HANDLE_VALUE;
char DirSpec[MAX_PATH]; // directory specification
DWORD dwError; printf ("Target directory is %s.\n", argv[1]);
strncpy (DirSpec, argv[1], strlen(argv[1])+1);
strncat (DirSpec, "\\*", 3); hFind = FindFirstFile(DirSpec, &FindFileData); if (hFind == INVALID_HANDLE_VALUE)
{
printf ("Invalid file handle. Error is %u\n", GetLastError());
return (-1);
}
else
{
printf ("First file name is %s\n", FindFileData.cFileName);
while (FindNextFile(hFind, &FindFileData) != 0)
{
printf ("Next file name is %s\n", FindFileData.cFileName);
}
dwError = GetLastError();
FindClose(hFind);
if (dwError != ERROR_NO_MORE_FILES)
{
printf ("FindNextFile error. Error is %u\n", dwError);
return (-1);
}
}
return (0);
}
//------------------------------------------------
主要是2个函数的使用:
FindFirstFile
FindNextFile