Click here to Skip to main content
15,914,795 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow do I set the default dir for saving in an MFC app? Pin
Jim Howard17-Aug-01 12:36
Jim Howard17-Aug-01 12:36 
AnswerRe: How do I set the default dir for saving in an MFC app? Pin
Bret Faller17-Aug-01 13:32
Bret Faller17-Aug-01 13:32 
GeneralRe: How do I set the default dir for saving in an MFC app? Pin
Jim Howard17-Aug-01 13:44
Jim Howard17-Aug-01 13:44 
QuestionIs current user an Administrator? Pin
Cathy17-Aug-01 11:40
Cathy17-Aug-01 11:40 
AnswerRe: Is current user an Administrator? Pin
Boris Russel17-Aug-01 12:16
Boris Russel17-Aug-01 12:16 
GeneralRe: Is current user an Administrator? Pin
Cathy21-Aug-01 5:53
Cathy21-Aug-01 5:53 
AnswerRe: Is current user an Administrator? Pin
Tim Deveaux17-Aug-01 14:48
Tim Deveaux17-Aug-01 14:48 
GeneralRe: Is current user an Administrator? Pin
Cathy21-Aug-01 5:51
Cathy21-Aug-01 5:51 
It works! Thanks! Big Grin | :-D

It's not short though. You have to define SetPrivilege(...)

BOOL SetPrivilege(
HANDLE hToken, // access token handle
LPCTSTR lpszPrivilege, // name of privilege to enable/disable
BOOL bEnablePrivilege // to enable or disable privilege
)
{
TOKEN_PRIVILEGES tp;
LUID luid;

if ( !LookupPrivilegeValue(
NULL, // lookup privilege on local system
lpszPrivilege, // privilege to lookup
&luid ) )
{ // receives LUID of privilege
printf("LookupPrivilegeValue error: %u\n", GetLastError() );
return FALSE;
}

tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
if (bEnablePrivilege)
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
else
tp.Privileges[0].Attributes = 0;

// Enable the privilege or disable all privileges.

AdjustTokenPrivileges(
hToken,
FALSE,
&tp,
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES) NULL,
(PDWORD) NULL);

// Call GetLastError to determine whether the function succeeded.

if (GetLastError() != ERROR_SUCCESS)
{
printf("AdjustTokenPrivileges failed: %u\n", GetLastError() );
return FALSE;
}

return TRUE;
}

It's a common enough thing to have to do. I'm sure there must be some built in function somewhere.




GeneralRe: Is current user an Administrator? Pin
Tim Deveaux24-Aug-01 10:46
Tim Deveaux24-Aug-01 10:46 
GeneralRe: Is current user an Administrator? Pin
Cathy24-Aug-01 11:25
Cathy24-Aug-01 11:25 
GeneralRe: Is current user an Administrator? Pin
Jon Sagara24-Aug-01 11:28
Jon Sagara24-Aug-01 11:28 
GeneralRe: Is current user an Administrator? Pin
Cathy24-Aug-01 11:54
Cathy24-Aug-01 11:54 
GeneralRe: Is current user an Administrator? Pin
Tim Deveaux24-Aug-01 11:34
Tim Deveaux24-Aug-01 11:34 
AnswerRe: Is current user an Administrator? Pin
Jon Sagara24-Aug-01 10:55
Jon Sagara24-Aug-01 10:55 
GeneralRe: Is current user an Administrator? Pin
Cathy24-Aug-01 11:26
Cathy24-Aug-01 11:26 
GeneralHOWTO: Determine if port is available Pin
Matt Weagle17-Aug-01 11:05
Matt Weagle17-Aug-01 11:05 
GeneralRe: HOWTO: Determine if port is available Pin
Tim Deveaux17-Aug-01 15:18
Tim Deveaux17-Aug-01 15:18 
GeneralBrain lock time Pin
17-Aug-01 9:46
suss17-Aug-01 9:46 
GeneralRe: Brain lock time Pin
Boris Russel17-Aug-01 12:22
Boris Russel17-Aug-01 12:22 
GeneralRe: Brain lock time Pin
Boris Russel17-Aug-01 12:25
Boris Russel17-Aug-01 12:25 
GeneralProgress updates from callback function Pin
Jake Palmer17-Aug-01 9:44
Jake Palmer17-Aug-01 9:44 
GeneralRe: Progress updates from callback function Pin
Ben Burnett17-Aug-01 17:28
Ben Burnett17-Aug-01 17:28 
GeneralNew C++ Website! Pin
17-Aug-01 9:39
suss17-Aug-01 9:39 
GeneralCEdit Pin
17-Aug-01 9:30
suss17-Aug-01 9:30 
GeneralRe: CEdit Pin
Jake Palmer17-Aug-01 9:40
Jake Palmer17-Aug-01 9:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.