* Program Name : Computer Power Options
* Program Ver. : v1.0.0.0
* Module Name : ShutDown.exe
* Last Edition : 20.03.2013
* Optimization : No code analysis issues were detected.
****************************************************************************/
#include <Windows.h>
#include <strsafe.h>
#define BUF_SIZE 260
int wmain( int argc, TCHAR *argv[] )
{
TCHAR param[MAX_PATH] = L"";
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
DWORD op;
if ( argc == 2 )
StringCchCat( param, BUF_SIZE, argv[1] );
else {
wprintf( L"\nKullanim :\n\tShutDown <parametre>" );
wprintf( L"\nKullanilabilir parametre degerleri:" );
wprintf( L"\n\tlogoff : Oturumunuzu sona erdirir." );
wprintf( L"\n\tshutdown : Bilgisayari kapatir." );
wprintf( L"\n\treboot : Bilgisayari yeniden baslatir." );
wprintf( L"\n\tpoweroff : Bilgisayari kapatip gucu keser." );
return 1;
}
if ( ! lstrcmp( param, L"logoff" ) )
op = EWX_LOGOFF;
else if ( ! lstrcmp( param, L"shutdown" ) )
op = EWX_SHUTDOWN;
else if ( ! lstrcmp( param, L"reboot" ) )
op = EWX_REBOOT;
else if ( ! lstrcmp( param, L"poweroff" ) )
op = EWX_POWEROFF;
else
op = 999;
op = op | EWX_FORCE;
// Get a token for this process.
if ( ! OpenProcessToken( GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
&hToken
)
)
return 1;
// Get the LUID for the shutdown privilege.
LookupPrivilegeValue( NULL, // Name of the system
SE_SHUTDOWN_NAME, // Name of the privilege
&tkp.Privileges[0].Luid // Locally unique identifier
);
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
);
if ( GetLastError() != ERROR_SUCCESS )
return 1;
ExitWindowsEx( op, 0 );
return 0;
}
Hiç yorum yok:
Yorum Gönder