|
Try using "\?\\machine\sharename" as your arg to the Win32 API CreateDirectory() . See this[^] link. Hope this helps.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Hi,
I am developing one application, i want to list all system used files, it may be exe, dll, etc. I downloaded one code from syteminternals.comm, they wrote separate sys file (alfa file monitor also). I need the following details
1. Without sys file how do hook the file sytems.
2. how do write the vxd for file sytems, if any sample code is avilble in net pls mention the website.
Regards,
|
|
|
|
|
This is very complex work, and the best way to do this is via the drivers (sys and vxd).
|
|
|
|
|
I am using Visual Studio 6.0.
I would like to use ShellExecute{} to launch the
registered email client and include a specific file
as an attachment to that email.
I don't want to include the 'To' email address
in the ShellExecute() call.
From Nishant's excellent article i have a starting point:
ShellExecute(this->m_hWnd,"open",
"mailto:nishinapp@yahoo.com","","", SW_SHOW );
How do I NOT include the email address but DO include
a file for attachment?
Thanks a lot,
Robert
|
|
|
|
|
I do not think that you can, you may have to use MAPI (look up "Simple MAPI" in MSDN).
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Thanks James.
I'm slugging through MSDN - one of my least favorite ways of finding info
|
|
|
|
|
Hi All,
I'm trying to provide a C function with a Class method as a function pointer,
roughly declared- void (__cdecl *) (void *) . the problem is, of course,
the __thiscall calling convention which is given to a class method by
default. This generates a conversion error by compiler.
Is there a way to somehow "convert" or type-cast the function calling?
I've tried to type-cast and reinterpret_cast it. Even tried declaring the
function as __cdecl from within the class but no luck.
Thanks very much for your help!
|
|
|
|
|
Not a recommended practice.
1. Pass a pointer to the class instance to your C function and then invoke the class member from there.
OR
2. Declare a static member function of the class, call it from the C function (You still need to pass pointer to class instance to static member function) and then invoke other member functions through the class pointer.
|
|
|
|
|
|
Hi All Gurus!!
I'm trying to use FileSystemObject to sort the file and folder before I access files information.
But I don't know how to createinstance of FileSystemObject.
I tried to import the
#import "c:\windows\system32\scrrun.dll" named_guids no_namespace raw_interfaces_only
or
#import "c:\windows\system32\scrrun.dll" no_namespace rename("FreeSpace", "FSpace") rename("Unknown", "Unk")
neither one is working. I got errors..
How do use FileSystemObject in VC++?
Thanks
|
|
|
|
|
pnpfriend wrote:
How do use FileSystemObject in VC++?
Are you sure you want to do this? Even if it is possible, it seems like a lot of work to simply sort a file and folder list.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
So.. what do you suggest?
I just simply want to sort files by name, type.. etc.
I was using FindFirstFile, FindNextFile..
But it seems like reading like following
c:\test
c:\test\a.txt
c:\test\b
c:\test\b\mm.txt
c:\test\c.txt
c:\test\d.zip
c:\test\d.zip\mm.txt
c:\test\m.txt
I want to sort the files first then get files info.
c:\test
c:\test\a.txt
c:\test\c.txt
c:\test\d.zip
c:\test\d.zip\mm.txt
c:\test\m.txt
c:\test\b
c:\test\b\mm.txt
thanks
|
|
|
|
|
pnpfriend wrote:
c:\test\b
c:\test\b\mm.txt
Shouldn't these two come between a.txt and c.txt?
pnpfriend wrote:
So.. what do you suggest?
You were on the right path with the FindFirstFile() /FindNextFile() pair. For each file/folder encountered, add it to a CArray object if you are using MFC, or a list object if you are using STL. Then sort. Another option is to add the file/folder items to a hidden listbox control that has the LBS_SORT style.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Hi David,
Thanks for ur reply.
No..
c:\test\b shouldnt' come between a.txt and c.txt because b is a folder not a file. I want all the file above folders.. just like you will see in ms explorer. I thought of using array.. but it is taking so long to sort it using array. I also did used ctreectrl.. again.. takes long time when minipulating huge files list..
Therefore, I was wondering to use FileSystemObject.
With FileSystemOjbect, I can sort folder first, then files later before minipulating any files information. I think.
But dont' know how to use it in c++. Do you have any idea?
|
|
|
|
|
pnpfriend wrote:
I want all the file above folders.. just like you will see in ms explorer.
That works. I initially thought you wanted each file/folder sorted in relation to ALL others.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
So do you know how to use FileSystemObject in c++?
or any other similar class that take care of it?
|
|
|
|
|
pnpfriend wrote:
So do you know how to use FileSystemObject in c++?
No, I've only used it in .wsh and .vbs files. With C++ I would opt for the FindFirstFile /FindNextFile pair, or CFileFind if using MFC.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Thank you for your replies, David.
I have no choice that I have to use FindNextFile() FindFirstFile().
|
|
|
|
|
I am trying to check if I have the proper access to a file. Here is my testing program
<br />
#include <stdio.h><br />
#include <windows.h><br />
<br />
typedef int TBK_BOOL;<br />
typedef int TBK_PERMISSIONS;<br />
<br />
#define TBK_TRUE 1<br />
#define TBK_FALSE 0<br />
<br />
#define F_OK 0 /* exists */<br />
#define X_OK 1 /* executable */<br />
#define W_OK 2 /* writable */<br />
#define R_OK 4 /* readable */<br />
#define D_OK 8 /* deletable */<br />
<br />
static TBK_BOOL win32_access(<br />
const char * os_path,<br />
TBK_PERMISSIONS permissions )<br />
{<br />
DWORD dwDesiredAccess;<br />
<br />
<br />
switch( permissions ) {<br />
case F_OK :<br />
return TBK_TRUE;
<br />
case R_OK :<br />
dwDesiredAccess = GENERIC_READ;<br />
break;<br />
<br />
case W_OK :<br />
dwDesiredAccess = GENERIC_WRITE;<br />
break;<br />
<br />
case X_OK :<br />
dwDesiredAccess = GENERIC_EXECUTE;<br />
break;<br />
<br />
case D_OK :<br />
dwDesiredAccess = DELETE;<br />
break;<br />
<br />
default :<br />
<br />
return TBK_FALSE;<br />
}<br />
<br />
GENERIC_MAPPING genericMapping = { READ_CONTROL | FILE_READ_DATA | FILE_READ_ATTRIBUTES | FILE_READ_EA,<br />
FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA | FILE_WRITE_DATA | FILE_APPEND_DATA,<br />
READ_CONTROL | FILE_READ_ATTRIBUTES | FILE_EXECUTE,<br />
FILE_ALL_ACCESS } ;<br />
LPCTSTR lpFilePath = LPCTSTR(os_path);<br />
PSECURITY_DESCRIPTOR pSD = NULL ;<br />
DWORD dwLenNeeded = 0;<br />
HANDLE hHeap = GetProcessHeap();<br />
<br />
PRIVILEGE_SET privileges;<br />
DWORD dwGrandedAccess, dwPrivilegeLength;<br />
BOOL bSuccess, bAccessGranded;<br />
HANDLE hProcess, hToken;<br />
<br />
fprintf(stderr, "Start checking access for %s\n", os_path);<br />
<br />
GetFileSecurity( lpFilePath ,<br />
OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,<br />
pSD, 0, &dwLenNeeded );<br />
<br />
pSD = HeapAlloc(hHeap, HEAP_GENERATE_EXCEPTIONS, dwLenNeeded);<br />
if( pSD == NULL )<br />
{<br />
DWORD dwError = GetLastError();<br />
LPVOID lpError;<br />
<br />
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM , NULL, dwError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpError, NULL, NULL);<br />
<br />
fprintf(stderr, "Cannot allocate memory for security descriptor.\n", (LPCTSTR) lpError );<br />
<br />
return TBK_FALSE;<br />
}<br />
<br />
bSuccess = GetFileSecurity( lpFilePath,<br />
OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,<br />
pSD, dwLenNeeded, &dwLenNeeded );<br />
if( bSuccess == FALSE ) {<br />
DWORD dwError = GetLastError();<br />
LPVOID lpError;<br />
<br />
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM , NULL, dwError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpError, NULL, NULL);<br />
<br />
<br />
fprintf(stderr, "Cannot get security id. Buffer len is %d. Error %s\n", dwLenNeeded, (LPCTSTR) lpError );<br />
<br />
<br />
return TBK_FALSE;<br />
}<br />
hProcess = GetCurrentProcess();<br />
<br />
bSuccess = OpenProcessToken(hProcess, TOKEN_QUERY, &hToken);<br />
if( bSuccess == FALSE )<br />
fprintf(stderr, "Cannot get Process Access Token.\n");<br />
<br />
fprintf(stderr, "Access asked %x.\n", dwDesiredAccess);<br />
MapGenericMask(&dwDesiredAccess, &genericMapping);<br />
fprintf(stderr, "Access to examine %x.\n", dwDesiredAccess);<br />
<br />
bSuccess = AccessCheck( pSD, hToken, dwDesiredAccess, &genericMapping,<br />
&privileges, &dwPrivilegeLength, &dwGrandedAccess,<br />
&bAccessGranded );<br />
<br />
if( bSuccess == FALSE ) {<br />
DWORD dwError = GetLastError();<br />
LPVOID lpError;<br />
<br />
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM , NULL, dwError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpError, NULL, NULL);<br />
<br />
<br />
fprintf(stderr, "Cannot check permissions. Error no %d %s\n", dwError, (LPCTSTR) lpError );<br />
<br />
<br />
return TBK_FALSE;<br />
}<br />
<br />
<br />
CloseHandle(hToken);<br />
<br />
HeapFree(hHeap, 0, pSD);<br />
<br />
fprintf(stderr, "Finish checking access.\n");<br />
<br />
return ((bAccessGranded == TRUE) ? TBK_TRUE : TBK_FALSE);<br />
}<br />
<br />
int main(int argc, LPCSTR argv [])<br />
{<br />
LPCTSTR path = LPCTSTR(argv[1]);<br />
char c;<br />
<br />
fprintf(stderr, "About to check %s file.\n", (LPCTSTR) path);<br />
<br />
if( win32_access( (LPCTSTR) path, R_OK ) )<br />
fprintf(stderr, "File is readable\n.");<br />
<br />
if( win32_access( (LPCTSTR) path, W_OK ) )<br />
fprintf(stderr, "File is writeable.");<br />
<br />
if( win32_access( (LPCTSTR) path, X_OK ) )<br />
fprintf(stderr, "File is executable.");<br />
<br />
if( win32_access( (LPCTSTR) path, D_OK ) )<br />
fprintf(stderr, "File is deleteable.");<br />
<br />
return 0;<br />
}<br />
When I am running it I am getting the following results
G:\Debug>check check.obj
About to check check.obj file.
Start checking access for check.obj
Access asked 80000000.
Access to examine 20089.
Cannot check permissions. Error no 998 Invalid access to memory location.
Start checking access for check.obj
Access asked 40000000.
Access to examine 116.
Cannot check permissions. Error no 998 Invalid access to memory location.
Start checking access for check.obj
Access asked 20000000.
Access to examine 200a0.
Cannot check permissions. Error no 998 Invalid access to memory location.
Start checking access for check.obj
Access asked 10000.
Access to examine 10000.
Cannot check permissions. Error no 998 Invalid access to memory location.
I do not undrstand what is wrong in the AccessCheck call. Everything seems to be fine and all memory is been in place.
Can someone spot any mistake on this small program. Help is much appriciated.
Ανέγνως αλλ' ουκ έγνων, η γαρ έγνως ουκ αν κατέγνων...Καβάφης.
|
|
|
|
|
You need to pass buffer to the AccessCheck for the privilege set. You need to pass in a thread token, not the process token. Here are some tips:
For the PRIVILEGE_SET privileges;
I changed it to PRIVILEGE_SET* lpPrivileges;
and malloced about 8192 bytes.
Set the dwPrivilegeLength to 8192
Pass lpPrivileges (already a pointer) to AccessCheck instead of &privileges (which was your locla variable).
Then I got error 1309 instead, meaning you need to open the thread token instead of the process token. Look at using OpenThread with GetCurentThradId followed by OpenThreadToken and maybe error 1309 will go away or be replaced by something else.
|
|
|
|
|
I also forgot to mention you initialize the Generic Mappings incorrectly.
It is a data structure with four 32-bit fields.
Try
GENERIC_MAPPING genericMapping;<br />
<br />
genericMapping.GenericAll = READ_CONTROL | FILE_READ_DATA | FILE_READ_ATTRIBUTES | FILE_READ_EA,<br />
FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA | FILE_WRITE_DATA | FILE_APPEND_DATA,<br />
READ_CONTROL | FILE_READ_ATTRIBUTES | FILE_EXECUTE,<br />
FILE_ALL_ACCESS;<br />
<br />
genericMapping.GenericExecute = genericMapping.GenericAll;<br />
genericMapping.GenericRead = genericMapping.GenericAll;<br />
genericMapping.GenericWrite = genericMapping.GenericAll;
I am not suggesting these should all be the same value, only that this syntax is 'more corrct' than what you had before.
|
|
|
|
|
Thanks a lot for you help.
Someone else sugested to use CreateFile which simplifies a lot the permission checking. Although sounds weird to 'create a file' for just checking the permissions, it looks like a simpler solution to go for.
Ανέγνως αλλ' ουκ έγνων ή γαρ έγνως ουκ αν κατέγνων...Καβάφης
|
|
|
|
|
Hi all,
I want a good way to encrypting files,
and I want to say that I am a beginner.
Please help me on this,
Cheers,
Thanks.
|
|
|
|
|
|
How about EncryptFile() ?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|