| | |
author of a file
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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.
C++ Syntax (Toggle Plain Text)
#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; }
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.
![]() |
Similar Threads
- save ram file to hard disk,how? (Graphics and Multimedia)
- Bubble sort & File output jibrish errors??? (C)
- How do I pass data from a recordset on asp page towards an array on js file (HTML and CSS)
- Creating a .EXE file (Java)
- Generate file in memory to save to local disk (ASP.NET)
- Highjack file Ie wont download (Viruses, Spyware and other Nasties)
- .h file not found? (C++)
- problem reading text file to struct (C++)
Other Threads in the C++ Forum
- Previous Thread: Projrct in C++
- Next Thread: Please help w/ compile errors
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelp homeworkhelper iamthwee ifstream input int java lib list loop looping loops map math matrix memory multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg simple sorting string strings temperature template text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






