Click here to Skip to main content
15,912,021 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Basic query regarding arrays/data sets Pin
Philip Nicoletti17-Aug-00 8:30
Philip Nicoletti17-Aug-00 8:30 
GeneralRe: Basic query regarding arrays/data sets Pin
Philip Nicoletti17-Aug-00 13:46
Philip Nicoletti17-Aug-00 13:46 
QuestionMinimizeBox in a PropertySheet? Pin
Mathias16-Aug-00 7:50
Mathias16-Aug-00 7:50 
AnswerRe: MinimizeBox in a PropertySheet? Pin
Frank Deo16-Aug-00 10:40
Frank Deo16-Aug-00 10:40 
GeneralAnother socket failure - in Create() call Pin
Alex Alexapolsky16-Aug-00 3:29
sussAlex Alexapolsky16-Aug-00 3:29 
GeneralRegarding Dial up Pin
Krithivasan M. S16-Aug-00 3:14
Krithivasan M. S16-Aug-00 3:14 
GeneralRe: Regarding Dial up Pin
Member 120896516-Aug-00 13:01
Member 120896516-Aug-00 13:01 
QuestionReboot the PC programatically ? Pin
Adalsteinn B. Bjarnason16-Aug-00 1:21
Adalsteinn B. Bjarnason16-Aug-00 1:21 
I am developing an install program that have to be capable to restart the computer. Cases that requre such threatment are when you hit file collision, i.e. the file that you are trying to copy, exists and is occupied by another program.
So you need to put a line in WINSTART.BAT to delete the old file and replace it with the newer one.

Following are two different functions: Reboot and ColdBoot.
As their name points to they are quite different. The first one Reboots the machine (but didn't work) and the second one turn the computer off (crude and unprofessional).

Why doesn't Reboot function work ?

/*
Function: Reboot

Purpose: Turn off the computer.

Parameters: bForce (if TRUE it doesn't close any window)

Return: TRUE if successful ?

Remarks: This function is somehow spooky.
*/
BOOL Reboot(BOOL bForce)
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
char szBuf[100];


int x = MessageBox(GetFocus(), "This application closes all running "
"applications and logs you off of the system.\n"
"Do you wish to continue?", "Exit Windows", MB_YESNO);
if (x == IDNO) return FALSE;

/*
Get a token for this process.
*/
if (!(GetVersion() & WIN32S))
{
#ifdef _DEBUG
OutputDebugString("Setting token.\n");
#endif

/*
Running on NT so need to change privileges.
*/
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
wsprintf(szBuf, "OpenProcessToken Error #%d", GetLastError ());
MessageBox(GetFocus(), szBuf, NULL, MB_OK);
}

/*
Get the LUID for shutdown privilege.
*/
LookupPrivilegeValue(NULL, _T("SeShutdownPrivilege"), &tkp.Privileges[0].Luid);

tkp.PrivilegeCount = 1; // One privilege to set.
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

/*
Get shutdown privilege for this process.
*/
if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0))
{
wsprintf(szBuf, "AdjustTokenPrivileges Error #%d", GetLastError ());
MessageBox(GetFocus(), szBuf, NULL, MB_OK);
}
}

if (bForce)
{
if (!ExitWindowsEx(EWX_REBOOT, 0))
{
wsprintf(szBuf, "Error ExitWindows Error #%d", GetLastError ());
MessageBox(GetFocus(), szBuf, NULL, MB_OK);
}
}
else
{
if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
{
wsprintf(szBuf, "Error ExitWindows Error #%d", GetLastError ());
MessageBox(GetFocus(), szBuf, NULL, MB_OK);
}
}

return TRUE;
}

/*
Function: ColdBoot

Purpose: Turn off the computer.

Remarks: This function just turn off the computer,
it doesn't reboot it like I want to
*/
void ColdBoot()
{
char szWinIni[255];

GetWindowsDirectory(szWinIni, sizeof(szWinIni));
strcat(szWinIni, "\\rundll.exe user.exe,exitwindows");

WinExec(szWinIni, SW_SHOWNORMAL);
}

Adalsteinn B. Bjarnason
adal@itn.is

AnswerRe: Reboot the PC programatically ? Pin
Benedict Verheyen17-Aug-00 5:16
sussBenedict Verheyen17-Aug-00 5:16 
Generalchanging the default mfc icon Pin
Pierre Koerber16-Aug-00 0:10
sussPierre Koerber16-Aug-00 0:10 
GeneralRe: changing the default mfc icon Pin
Benedict Verheyen17-Aug-00 5:30
sussBenedict Verheyen17-Aug-00 5:30 
GeneralCAsyncSocket-debug assertion failed Pin
Alex Alexapolsky15-Aug-00 22:13
sussAlex Alexapolsky15-Aug-00 22:13 
GeneralRe: CAsyncSocket-debug assertion failed Pin
Remus Lazar16-Aug-00 2:27
Remus Lazar16-Aug-00 2:27 
GeneralCAsyncSocket-debug assertion failed Pin
Alex Alexapolsky15-Aug-00 22:11
sussAlex Alexapolsky15-Aug-00 22:11 
QuestionHow to register my program into the startup Pin
koteswara15-Aug-00 18:38
koteswara15-Aug-00 18:38 
AnswerRe: How to register my program into the startup Pin
Remus Lazar16-Aug-00 2:56
Remus Lazar16-Aug-00 2:56 
GeneralAddItem-method for MSHFlexGrid 6.0 Pin
Stefan Alpers15-Aug-00 5:10
sussStefan Alpers15-Aug-00 5:10 
GeneralRe: AddItem-method for MSHFlexGrid 6.0 Pin
Remus Lazar16-Aug-00 2:51
Remus Lazar16-Aug-00 2:51 
GeneralLoading a list from file into a List Box Pin
SmokingRope2214-Aug-00 14:53
SmokingRope2214-Aug-00 14:53 
GeneralRe: Loading a list from file into a List Box Pin
Philip Nicoletti15-Aug-00 3:24
Philip Nicoletti15-Aug-00 3:24 
GeneralRe: Loading a list from file into a List Box Pin
SmokingRope2215-Aug-00 17:06
SmokingRope2215-Aug-00 17:06 
GeneralMultiple doc templates problem Pin
Christian Graus14-Aug-00 9:20
protectorChristian Graus14-Aug-00 9:20 
GeneralRe: Multiple doc templates problem Pin
Mike Dunn14-Aug-00 20:40
Mike Dunn14-Aug-00 20:40 
GeneralRe: Check Visual C++ 4 HOW-TO Pin
Masaaki Onishi16-Aug-00 4:43
Masaaki Onishi16-Aug-00 4:43 
GeneralParsing a file Pin
mukesh.gupta@promap.co.uk14-Aug-00 4:23
mukesh.gupta@promap.co.uk14-Aug-00 4:23 

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.