author of a file

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2008
Posts: 18
Reputation: chanda gul is an unknown quantity at this point 
Solved Threads: 1
chanda gul chanda gul is offline Offline
Newbie Poster

author of a file

 
0
  #1
Sep 28th, 2008
Hi all
Can any1 tell me how to extract the author of a file in ntfs.....any class or method availbe for it???
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,484
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1478
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: author of a file

 
0
  #2
Sep 28th, 2008
Here is an example in VB, which you should be able to translate to c++ because they both use the same win32 api functions.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,484
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1478
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: author of a file

 
0
  #3
Sep 28th, 2008
  1. #include <windows.h>
  2. #include <iostream>
  3. #include <string>
  4. using std::cout;
  5. using std::string;
  6.  
  7. DWORD ShowError()
  8. {
  9. DWORD dwErr = GetLastError();
  10. char buf[255] = {0};
  11. FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, dwErr, 0, buf, sizeof(buf), 0);
  12. cout << buf << "\n";
  13. return dwErr;
  14. }
  15.  
  16. string GetFileOwner(string szfilename)
  17. {
  18. BOOL bSuccess; //' Status variable
  19. DWORD sizeSD; //' Buffer size to store Owner's SID
  20. PSID pOwner = 0; //' Pointer to the Owner's SID
  21. char ownerName[255] = {0}; //' Name of the file owner
  22. char domain_name[255] = {0}; //' Name of the first domain for the owner
  23. DWORD name_len; //' Required length for the owner name
  24. DWORD domain_len; //' Required length for the domain name
  25. DWORD nLength; //' Length of the Windows Directory
  26. SID_NAME_USE deUse; //' Pointer to a SID_NAME_USE enumerated type
  27. // ' indicating the type of the account
  28. char sdBuf[255];
  29. BOOL OwnerDefaulted = 0;
  30. //' Call GetFileSecurity the first time to obtain the size of the buffer
  31. //' required for the Security Descriptor.
  32. bSuccess = GetFileSecurity(szfilename.c_str(),
  33. OWNER_SECURITY_INFORMATION, &sdBuf, sizeof(sdBuf), &sizeSD);
  34. //' exit if any error
  35. if(bSuccess == 0)
  36. {
  37. ShowError();
  38. return "";
  39. }
  40.  
  41. //' Obtain the owner's SID from the Security Descriptor, exit if error
  42. bSuccess = GetSecurityDescriptorOwner(sdBuf, &pOwner, &OwnerDefaulted);
  43. if( bSuccess == 0) return "";
  44.  
  45. //' Retrieve the name of the account and the name of the first domain on
  46. //' which this SID is found. Passes in the Owner's SID obtained previously.
  47. name_len = sizeof(ownerName);
  48. domain_len = sizeof(domain_name);
  49. bSuccess = LookupAccountSid(NULL, pOwner, ownerName, &name_len,
  50. domain_name, &domain_len, &deUse);
  51. if( bSuccess == 0)
  52. {
  53. ShowError();
  54. ownerName[0] = 0;
  55. }
  56. //' we've found a result
  57. return ownerName;
  58. }
  59.  
  60. int _tmain(int argc, _TCHAR* argv[])
  61. {
  62. string filename = "C:\\Users\\Ancient_Dragon\\Documents\\bookmark.htm";
  63. string owner = GetFileOwner(filename);
  64. cout << owner << "\n";
  65. return 0;
  66. }
Last edited by Ancient Dragon; Sep 28th, 2008 at 7:21 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC