admin account vs user account in windows

Posted on 2004-04-19
Last Modified: 2013-11-20

I have a file in C:\Program Files\etc etc...

I never realized that I could read / write from these files without any issues simply because my user account had admin rights.

I am always refused access to these files if I use an account that does not have admin rights. Something like

CStdioFile file;

if (!file.Open("C:\\test.txt", CFile::modeReadWrite)) {
    cout << "couln't open file";
else {
    cout << "file opened ok";

will always fail in my non admin account. Is there anyway to tell the OS the user can access this file through my app?

Question by:ragin_cajun
  • 2
LVL 86

Expert Comment

ID: 10860721
As an admin, use

cacls.exe /e /g yourotheraccount:f c:\test.txt

Author Comment

ID: 10860878
Hi jkr, it seemed to work, but is there any way to do it programatically at runtime right before the file is accessed, then set back to normal access rights?

Otherwise I would have to ask the administrator to change the permission for all users on all the files accessed each time they do an install.

LVL 86

Accepted Solution

jkr earned 100 total points
ID: 10861493
>> but is there any way to do it programatically at runtime right before the file is accessed

That's sourt of pointless. When your program is not running under the admin account, you cannot change the access mode anyway. But, if you really want to know that:

   LPTSTR FileName = "C:\\test.txt";
   LPTSTR TrusteeName = "Everyone";

   EXPLICIT_ACCESS explicitaccess;

   PACL ExistingDacl;
   PACL NewAcl = NULL;

   DWORD dwError;

   dwError = GetNamedSecurityInfo(


   // add specified access to the object

   dwError = SetEntriesInAcl(

   // apply new security to file

   dwError = SetNamedSecurityInfo(
                   SE_FILE_OBJECT, // object type

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
zeroFront challenge 7 98
wordmultiple challenge 12 132
Sed question 2 85
Excel file not created as expected 7 72
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question