Complete disaster-recovery snapshot: engine/game source, game data assets, VC6 toolchain + DX SDKs, build outputs, deployed game, and _UNUSED archive. Large binaries in Git LFS; text preserved byte-for-byte (core.autocrlf=false, no eol attributes). See RECOVERY.md for the one-clone rebuild procedure.
133 lines
4.5 KiB
C++
133 lines
4.5 KiB
C++
//-----------------------------------------------------------
|
|
// Remote Shutdown v1.0 Console Mode
|
|
// Copyright (C) 2002, MATCODE Software
|
|
// http://www.matcode.com
|
|
// Author: Vitaly Evseenko
|
|
//-----------------------------------------------------------
|
|
|
|
#include <windows.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#pragma hdrstop
|
|
|
|
int RemoteShutdown(LPSTR lpMachineName, LPSTR lpMessage,
|
|
DWORD dwTimeout, BOOL bForceAppsClosed,
|
|
BOOL bRebootAfterShutdown )
|
|
{
|
|
HANDLE hToken;
|
|
TOKEN_PRIVILEGES TokenPrivileges;
|
|
OpenProcessToken( GetCurrentProcess(),
|
|
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken ) ;
|
|
LookupPrivilegeValue( NULL, SE_REMOTE_SHUTDOWN_NAME, &(TokenPrivileges.Privileges[0].Luid));
|
|
TokenPrivileges.PrivilegeCount = 1;
|
|
TokenPrivileges.Privileges[0].Attributes = 2;
|
|
AdjustTokenPrivileges( hToken, FALSE, &TokenPrivileges,
|
|
sizeof(TOKEN_PRIVILEGES), NULL, NULL );
|
|
if(!InitiateSystemShutdown(
|
|
lpMachineName, // name of computer to shut down
|
|
lpMessage, // address of message to display
|
|
dwTimeout, // time to display dialog box
|
|
bForceAppsClosed, // force applications with unsaved changes flag
|
|
bRebootAfterShutdown ))
|
|
{
|
|
return GetLastError();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void OutUsage(void)
|
|
{
|
|
printf("\nUsage: RSD-CON ComputerName [Message] [/tnn] [/f] [/s]\n");
|
|
printf("\tComputerName - remote computer name\n");
|
|
printf("\tMessage - specify message to display\n");
|
|
printf("\t/t - time to display message (nn seconds)\n");
|
|
printf("\t/f - do not force applications with unsaved changes flag\n");
|
|
printf("\t/s - the computer is to shut down.\n");
|
|
printf("Example: RSD-CON PC_LARRY This computer will be restarted now. /t20\n");
|
|
}
|
|
|
|
void main( int argc, char *argv[] )
|
|
{
|
|
char szMachineName[100];
|
|
char szMessage[200];
|
|
DWORD dwTimeout;
|
|
BOOL bForceAppsClosed;
|
|
BOOL bRebootAfterShutdown;
|
|
int i, Err;
|
|
|
|
printf("Remote Shutdown v1.0, Console\n");
|
|
printf("Copyright (C) 2002, MATCODE Software\n");
|
|
printf("http://www.matcode.com\n");
|
|
|
|
if (GetVersion() & 0x80000000) // Not Windows NT/2000/XP
|
|
{
|
|
printf("\n\tThis is a Windows NT/2000/XP application.\n"
|
|
"This program will not work on Windows 95/98/ME !\n");
|
|
return;
|
|
}
|
|
|
|
if(argc<2)
|
|
{
|
|
OutUsage();
|
|
return;
|
|
}
|
|
strcpy(szMachineName, argv[1]);
|
|
dwTimeout = 0;
|
|
bForceAppsClosed = TRUE;
|
|
bRebootAfterShutdown = TRUE;
|
|
szMessage[0] = '\0';
|
|
for( i = 2; i < argc; i++ )
|
|
{
|
|
// if not started with / then message ;-)
|
|
if( argv[i][0] != '/')
|
|
{
|
|
strcat(szMessage, argv[i]);
|
|
strcat(szMessage, " ");
|
|
continue;
|
|
}
|
|
// parse option type
|
|
if(argv[i][1]=='t' || argv[i][1]=='T')
|
|
{
|
|
dwTimeout = atol(&argv[i][2]);
|
|
}
|
|
else if(argv[i][1]=='f' || argv[i][1]=='F')
|
|
{
|
|
bForceAppsClosed = FALSE;
|
|
}
|
|
else if(argv[i][1]=='s' || argv[i][1]=='S')
|
|
{
|
|
bRebootAfterShutdown = FALSE;
|
|
}
|
|
}
|
|
if (dwTimeout == 0 && szMessage[0])
|
|
{
|
|
dwTimeout = 5;
|
|
}
|
|
Err = RemoteShutdown(szMachineName, szMessage,
|
|
dwTimeout, bForceAppsClosed,
|
|
bRebootAfterShutdown );
|
|
if(Err)
|
|
{
|
|
LPSTR lpstErr = "\0";
|
|
if(Err == 53)
|
|
{
|
|
lpstErr = "The network path was not found.\n"
|
|
"Invalid computer name or is not Windows NT/2000/XP machine.\n";
|
|
}
|
|
else if(Err == 5)
|
|
{
|
|
lpstErr = "Access is denied. You have no administrative rights on the specified computer.\n";
|
|
}
|
|
|
|
printf("\nUnable to shutdown computer %s, Error: %d.\n%s",
|
|
szMachineName, Err, lpstErr);
|
|
OutUsage();
|
|
}
|
|
else
|
|
{
|
|
printf("\nComputer %s is shut down.\n", szMachineName);
|
|
}
|
|
}
|
|
|
|
|