Heyy pplz:
I'm kind of a beginner at C++ and could use soem help with a program I'm writing for fun =)
( MY REVISED PROGRAM AS A WINDOWS APPLICATION )
Code:
#include <iostream>
#include <windows.h>
#include <stdlib.h>
#include <tchar.h>
#include <iomanip>
#include <stdio.h>
#include <time.h>
#include <Winuser.h>
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "advapi32.lib")
using namespace std;
BOOL MySystemShutdown()
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// Get a token for this process.
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return( FALSE );
// Get the LUID for the shutdown privilege.
LookupPrivilegeValue(NULL, 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);
if (GetLastError() != ERROR_SUCCESS)
return FALSE;
// Shut down the system and force all applications to close.
if (!ExitWindowsEx(0x00000001 | 0x00000004,
0x00020000 |
0x00000003 |
0x80000000))
return FALSE;
//shutdown was successful
return TRUE;
}
My program is suppose to... Say things... And shut down someones computer unexpectedly. It is meant as a practical joke and does not do harm to another's machine.
( MY ORIGINAL PROGRAM AS A WINDOWS CONSOLE APPLICATION )
Code:
#include <iostream>
#include <windows.h>
#include <stdlib.h>
#include <tchar.h>
#include <iomanip>
#include <stdio.h>
#include <time.h>
#include <Winuser.h>
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "advapi32.lib")
using namespace std;
int APIENTRY _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
{
cout << "\a\n";
Sleep(200);
cout << "\a\n";
Sleep(200);
cout << "\a\n";
Sleep(200);
cout << "Alert. A virus has been detected in netcfgx.dll " << endl;
Sleep(1500);
system ("PAUSE");
cout << "Please wait while WINDOWS attempts to remove the file. " << endl;
Sleep(3000);
system ("PAUSE");
cout << "ERROR CODE 1505. FILE IS IN USE. \a" << endl;
Sleep(500);
system ("PAUSE");
cout << "WINDOWS requires a process to be ended in order to remove the file. " << endl;
system ("PAUSE");
Sleep(3000);
cout << "Unable to end process. WINDOWS CANNOT TERMINATE A SYSTEM PROCESS \a" << endl;
system ("PAUSE");
cout << "WINDOWS must be shut down to prevent damage to critical SYSTEM files " << endl;
system ("PAUSE");
cout << "Please exit all applications and save all work. Shutdown in one minute " << endl;
system ("PAUSE");
ExitWindowsEx(0x00000008, 0x00010000);
return (0);
}
BOOL MySystemShutdown()
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// Get a token for this process.
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return( FALSE );
// Get the LUID for the shutdown privilege.
LookupPrivilegeValue(NULL, 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);
if (GetLastError() != ERROR_SUCCESS)
return FALSE;
// Shut down the system and force all applications to close.
if (!ExitWindowsEx(0x00000001 | 0x00000004,
0x00020000 |
0x00000003 |
0x80000000))
return FALSE;
//shutdown was successful
return TRUE;
}
And, Yes. I'm a stupid high-school student who is trying to use C++ to shut down someone elses computer =DD
Also I keep getting 2 socially unacceptable errors....
Code:
LIBCD.lib(wwincrt0.obj) : error LNK2001: unresolved external symbol _wWinMain@16
and
Code:
Debug/Shutdown.exe : fatal error LNK1120: 1 unresolved externals
Please help if u can )