how can I make a shutdown program??? in c++ (Borland 5.02)???
how can I make a shutdown program??? in c++ (Borland 5.02)???
you're so damned lazy! This has been asked TWICE on the old board within a few days!! grrrr.....*calms himself down*
http://cprogram.hypermart.net/cgi-bi...age=0&Session=
But it doesnt work u idiot!
I should probably never post so early in the morning anymore...
what erros does it give you, cuz I'm sure it works...
This will shutdown windows (only 9x). It must be compiled as a windows app not a console one -
Code:int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { ExitWindowsEx(EWX_FORCE|EWX_SHUTDOWN,NULL); return 0; }
This is quoted from the Win32 API in Borland C++ 4.52 IDE. I've never used this as I usually have no need to actually shut down. Normally I use the ExitWindows function as my programs usually only require a reboot, not an actual shutdown.
I'm not sure if it is good practice to quote from SDK's, but the explanation was far too lengthy so that is why I did.
The ExitWindowsEx function can be used to shut down the system. Shutting down flushes file buffers to disk and brings the system to a condition in which it is safe to turn off the computer. The calling process must have the SE_SHUTDOWN_NAME privilege to shut down the system.
The following example enables the SE_SHUTDOWN_NAME privilege and then shuts down the system.
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
/* Get a token for this process. */
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
error("OpenProcessToken");
/* Get the LUID for the shutdown privilege. */
LookupPrivilegeValue(NULL, TEXT("SE_SHUTDOWN_NAME"),
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; /* one privilege to set */
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
/* Get the shutdown privilege for this process. */
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES)NULL, 0);
/* Cannot test the return value of AdjustTokenPrivileges. */
if (GetLastError() != ERROR_SUCCESS)
error("AdjustTokenPrivileges");
/* Shut down the system and force all applications to close. */
if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
error("ExitWindowsEx");
The price of using old help files is that they never tell you that the code you quote is for Windows NT/2000/XP only (given that Windows 9x has no security).This is quoted from the Win32 API in Borland C++ 4.52 IDE.
ExitWindowsEx alone will work in Windows 9x from a GUI application. There is no function call to shut down Windows from a console application.
Ess
Like a rat in a maze who says,
"Watch me choose my own direction"
Are you under the illusion
The path is winding your way? - Rush
>>There is no function call to shut down Windows from a console application.
There is a possible cheat. I used to use the following as part of a close-down bat file for win 98
....at least I think thats it. If I get home and find its wrong I'll change it....rundll32 shell32.dll,SHExitWindowsEx 1
Anyway I suppose you could use this as a system call......sloppy - but it might work....
Anyone know where i can find tuturial for borland c++ builder 5?