Skip to main content
gamedev.net
🔒 Locked

MFC

Started by Militant 0 replies 1.8k views
Original Post
Militant
Militant
General programming, right? I have an MFC app (used vc++ wizard to start project). It is dialog based. I want to be able to do the following... : Hide window on minimize : Show window on users command (below) : Get a menu when user clicks on icon in the tray : Get priviledges from Win NT/2K to shutdown the computer. I have the shutdown working for W9x, and I can get an icon in the tray. I tried working w/ the examples that are in the vc++ help... but I get an error (privileges) when I try to shutdown the computer. My current process: : GetToken && Handle for dialog : LookupPrivilegeName : AdjustTokenPriviledges [there may be something missing, not sure since I don''t have my source w/ me] any help? ~ me ~
I'm not the brightest something or other in a group or similar.~ me ~
Militant
Militant
ok.. so here is my code..
BOOL CblahDlg::NTShutDown(BOOL sda)
{
HANDLE hToken;
TOKEN_PRIVILEGES tp;
LUID luid;
CString err_msg;

OpenThreadToken( GetCurrentThread(), TOKEN_READ | TOKEN_WRITE, TRUE, &hToken );

if ( !LookupPrivilegeValue(
NULL, // lookup privilege on local system
SE_SHUTDOWN_NAME, // privilege to lookup
&luid ) ) { // receives LUID of privilege
err_msg.Format( "Lookup error: %u", GetLastError() );
MessageBox( err_msg, AD_ERR );
return FALSE;
}

tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
if ( sda )
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) {
err_msg.Format( "Privilege Error: %u", GetLastError() );
MessageBox( err_msg, AD_ERR );
return FALSE;
}

return TRUE;
}

The above is to change the privileges, here is the code to shutdown.. (what is inside a function)

NTShutDownAble( TRUE );
ewe_ret = ExitWindowsEx( m_exitMethod | m_force, 0 );


That is the main stuff.. (2 function calls).. m_exitMethod is the exit method (Shutdown/Logoff/Restart) and m_force tells us if we should forget about letting all programs close..

I don''t know what I''m doing wrong, but I can''t shutdown W2k (which is what my college has).. Any help.

thanx..

~ me ~
I'm not the brightest something or other in a group or similar.~ me ~

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.