开发者

Search for a file in Program Files dir

I am searching for a file using the win32 functions FindFirstFileEx & FindNextFile.

But when I attempt to s开发者_如何学Cearch for a file in the directory C:\Program Files my function fails & I am pretty sure from GetLastError() that it is because directory is privileged & I dont have access to it.

Is there a way to ask the user for & get privileged access to the program files directory

or C:/windows so I can search in it?

Or a different win32 function that allows myself to search in this directory?

Or maybe there is never a need for a program to need to search those directories, so there is no way to do it?


This is a little off topic, but...

You know what's really awesome for dealing with files on any platform in C++ these days? Boost.Filesystem

http://www.boost.org/doc/libs/1_45_0/libs/filesystem/v3/doc/index.htm

You should be able to skip over directories you don't have access to.

The Windows Token API might get you on the right track for that prompt:

http://msdn.microsoft.com/en-us/magazine/cc163486.aspx


Or a different win32 function that allows myself to search in this directory? You could try to use the cmd.exe to run a dir command against that folder and capture the directory list to a temp file.

For example you could use the CreateProcess Win32 API to run this command:

cmd.exe /k dir "c:\Program Files" > c:\temp\files.txt

and the list of files in the directory would be written to the c:\temp\files.txt temp file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜