Board index » cppbuilder » Re: What is this code good for?

Re: What is this code good for?


2005-04-04 04:33:51 AM
cppbuilder114
"Grety" < XXXX@XXXXX.COM >wrote in message
Quote
My Question ius what is this code for?
Restarting windows?
It ensures that the callng process has rights to shutdown Windows. It does
not perform the actual shutdown.
Gambit
 
 

Re:Re: What is this code good for?

"Grety" < XXXX@XXXXX.COM >wrote in message
Quote
Then it seems that I have to add a line (maybe more) to
the last line to make it shutdown.
You need to call ExitWindows/Ex() to perform the actual shutdown. The code
you have show so far only sets up the process for having the rights to call
ExitWindows/Ex().
Quote
Is it different in WinXP? I guess there is some difference
between Win98 and WinXP codes to shutdown the OS.
The difference is that Win98 does not implement access rights at all,
whereas all NT-based versions (NT4, Win2K, XP, Win2K3) do. The code you
posted earlier has no effect on Win98.
Gambit
 

Re:Re: What is this code good for?

HANDLE hToken;
TOKEN_PRIVILEGES tkp;
OSVERSIONINFO info;
info.dwOSVersionInfoSize = sizeof(info);
GetVersionEx(&info);
if( info.dwPlatformId == VER_PLATFORM_WIN32_NT )
{
if( ! OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES |
TOKEN_QUERY, &hToken ) )
LookupPrivilegeValue( NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid );
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges( hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)
NULL, 0 );
if( GetLastError() != ERROR_SUCCESS );
}
My Question ius what is this code for?
Restarting windows?
 

{smallsort}

Re:Re: What is this code good for?

Then it seems that I have to add a line (maybe more) to the last line to
make it shutdown.
Is it different in WinXP? I guess there is some difference between Win98 and
WinXP codes to shutdown the OS.
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Grety" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>My Question ius what is this code for?
>Restarting windows?

It ensures that the callng process has rights to shutdown Windows. It
does
not perform the actual shutdown.


Gambit


 

Re:Re: What is this code good for?

"Grety" < XXXX@XXXXX.COM >wrote:
Quote
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
OSVERSIONINFO info;
info.dwOSVersionInfoSize = sizeof(info);
GetVersionEx(&info);
if( info.dwPlatformId == VER_PLATFORM_WIN32_NT )
{
if( ! OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES |
TOKEN_QUERY, &hToken ) )
LookupPrivilegeValue( NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid );
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges( hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)
NULL, 0 );
if( GetLastError() != ERROR_SUCCESS );
}

My Question ius what is this code for?
Restarting windows?
Part of an MSDN sample.
msdn.microsoft.com/library/default.asp
 

Re:Re: What is this code good for?

thanks to everyone, I'm well understand :-)
"Matt Jacobs" < XXXX@XXXXX.COM >wrote in message
Quote
"Grety" < XXXX@XXXXX.COM >wrote:

>HANDLE hToken;
>TOKEN_PRIVILEGES tkp;
>OSVERSIONINFO info;
>info.dwOSVersionInfoSize = sizeof(info);
>GetVersionEx(&info);
>if( info.dwPlatformId == VER_PLATFORM_WIN32_NT )
>{
>if( ! OpenProcessToken( GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES |
>TOKEN_QUERY, &hToken ) )
>LookupPrivilegeValue( NULL, SE_SHUTDOWN_NAME,
>&tkp.Privileges[0].Luid );
>tkp.PrivilegeCount = 1;
>tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
>AdjustTokenPrivileges( hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)
>NULL, 0 );
>if( GetLastError() != ERROR_SUCCESS );
>}
>
>My Question ius what is this code for?
>Restarting windows?

Part of an MSDN sample.


msdn.microsoft.com/library/default.asp
e/how_to_shut_down_the_system.asp
Quote