Don't worry, it's not wrong just frowned upon. Here's an identical program using inline functions...
main.cpp
Code:
//#define _WIN32_WINNT 0x0501
#include <iostream>
#include <windows.h>
#include "Usefull.h"
using namespace std;
int main()
{
char ans;
cout<<"Do you wish to shut down your computer?"<<endl;
cout<<">>";
cin>>ans;
if(ans=='y')
{
shutdown();
}
else
{
cout<<"Ok then cool";
}
cin.get();
cin.get();
return 0;
}
Usefull.h
Code:
//save this file as Usefull.h
#include <iostream>
#include <windows.h>
using namespace std;
void shutdown(void)
{
TOKEN_PRIVILEGES tkp;
HANDLE hToken;
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,NULL,0);
ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF, 0);
}