Hi all
Can any1 tell me how to extract the author of a file in ntfs.....any class or method availbe for it???

Here is an example in VB, which you should be able to translate to c++ because they both use the same win32 api functions.

#include <windows.h>
#include <iostream>
#include <string>
using std::cout;
using std::string;

DWORD ShowError()
{
    DWORD dwErr = GetLastError();
    char buf[255] = {0};
    FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, dwErr, 0, buf, sizeof(buf), 0);
    cout << buf << "\n";
    return dwErr;
}

string GetFileOwner(string szfilename)
{
    BOOL bSuccess;       //' Status variable
    DWORD sizeSD;         //' Buffer size to store Owner's SID
    PSID pOwner = 0;         //' Pointer to the Owner's SID
    char ownerName[255] = {0};    //' Name of the file owner
    char domain_name[255] = {0};  //' Name of the first domain for the owner
    DWORD name_len;       //' Required length for the owner name
    DWORD domain_len;     //' Required length for the domain name
    DWORD nLength;        //' Length of the Windows Directory
    SID_NAME_USE deUse;          //' Pointer to a SID_NAME_USE enumerated type 
                         //   ' indicating the type of the account
    char sdBuf[255];
    BOOL OwnerDefaulted = 0;
   //' Call GetFileSecurity the first time to obtain the size of the buffer
    //' required for the Security Descriptor.
    bSuccess = GetFileSecurity(szfilename.c_str(), 
                OWNER_SECURITY_INFORMATION, &sdBuf, sizeof(sdBuf), &sizeSD);
    //' exit if any error
    if(bSuccess == 0)
    {
        ShowError();
        return "";
    }
    
    //' Obtain the owner's SID from the Security Descriptor, exit if error
    bSuccess = GetSecurityDescriptorOwner(sdBuf, &pOwner, &OwnerDefaulted);
    if( bSuccess == 0) return "";

    //' Retrieve the name of the account and the name of the first domain on 
    //' which this SID is found.  Passes in the Owner's SID obtained previously.  
    name_len = sizeof(ownerName);
    domain_len = sizeof(domain_name);
    bSuccess = LookupAccountSid(NULL, pOwner, ownerName, &name_len,
        domain_name, &domain_len, &deUse);
    if( bSuccess == 0) 
    {
        ShowError();
        ownerName[0] = 0;
    }
    //' we've found a result
    return ownerName;
}

int _tmain(int argc, _TCHAR* argv[])
{
    string filename = "C:\\Users\\Ancient_Dragon\\Documents\\bookmark.htm";
    string owner = GetFileOwner(filename);
    cout << owner << "\n";
	return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.