har fået det til at virke. skulle inkludere reason.h men jeg måtte selv fremstille den. hvis der er nogen der vil se hvordan jeg har lavet den er den her:
#include <windows.h>
#include <iostream>
#include <reason.h>
using namespace std;
BOOL MySystemShutdown(int a)
{
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(EWX_SHUTDOWN | EWX_FORCE,
SHTDN_REASON_MAJOR_OPERATINGSYSTEM |
SHTDN_REASON_MINOR_UPGRADE |
SHTDN_REASON_FLAG_PLANNED))
return FALSE;
return TRUE;
}
main() {
int b;
b = MySystemShutdown (1);
cout<< "close " << b;
}
og reason.h:
//reason.h codes, used for shutdown reason codes.
#ifndef REASON_H
#define REASON_H
// Flags used by the various UIs.
#define SHTDN_REASON_FLAG_COMMENT_REQUIRED 0x01000000
#define SHTDN_REASON_FLAG_DIRTY_PROBLEM_ID_REQUIRED 0x02000000
#define SHTDN_REASON_FLAG_CLEAN_UI 0x04000000
#define SHTDN_REASON_FLAG_DIRTY_UI 0x08000000
// Flags that end up in the event log code.
#define SHTDN_REASON_FLAG_USER_DEFINED 0x40000000
#define SHTDN_REASON_FLAG_PLANNED 0x80000000
// Microsoft Major reasons
#define SHTDN_REASON_MAJOR_OTHER 0x00000000
#define SHTDN_REASON_MAJOR_NONE 0x00000000
#define SHTDN_REASON_MAJOR_HARDWARE 0x00010000
#define SHTDN_REASON_MAJOR_OPERATINGSYSTEM 0x00020000
#define SHTDN_REASON_MAJOR_SOFTWARE 0x00030000
#define SHTDN_REASON_MAJOR_APPLICATION 0x00040000
#define SHTDN_REASON_MAJOR_SYSTEM 0x00050000
#define SHTDN_REASON_MAJOR_POWER 0x00060000
// Microsoft Major reasons
#define SHTDN_REASON_MINOR_OTHER 0x00000000
#define SHTDN_REASON_MINOR_NONE 0x000000ff
#define SHTDN_REASON_MINOR_MAINTENANCE 0x00000001
#define SHTDN_REASON_MINOR_INSTALLATION 0x00000002
#define SHTDN_REASON_MINOR_UPGRADE 0x00000003
#define SHTDN_REASON_MINOR_RECONFIG 0x00000004
#define SHTDN_REASON_MINOR_HUNG 0x00000005
#define SHTDN_REASON_MINOR_UNSTABLE 0x00000006
#define SHTDN_REASON_MINOR_DISK 0x00000007
#define SHTDN_REASON_MINOR_PROCESSOR 0x00000008
#define SHTDN_REASON_MINOR_NETWORKCARD 0x00000009
#define SHTDN_REASON_MINOR_POWER_SUPPLY 0x0000000a
#define SHTDN_REASON_MINOR_CORDUNPLUGGED 0x0000000b
#define SHTDN_REASON_MINOR_ENVIRONMENT 0x0000000c
#define SHTDN_REASON_MINOR_HARWARE_DRIVER 0x0000000d
#define SHTDN_REASON_MINOR_OTHERDRIVER 0x0000000e
#define SHTDN_REASON_MINOR_BLUESCREEN 0x0000000F
#define SHTDN_REASON_UNKNOWN SHTDN_REASON_MINOR_NONE
#endif
men nu har jeg et lidt andet problem, jeg ville gerne have den til at spørge om man virkelig gerne vil have den til at lukke men det virker ikke rigtigt:
#include <windows.h>
#include <iostream>
#include <reason.h>
using namespace std;
BOOL MySystemShutdown(int a)
{
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(EWX_SHUTDOWN | EWX_FORCE,
SHTDN_REASON_MAJOR_OPERATINGSYSTEM |
SHTDN_REASON_MINOR_UPGRADE |
SHTDN_REASON_FLAG_PLANNED))
return FALSE;
return TRUE;
}
main() {
int b;
string svar;
b = MySystemShutdown (1);
cout<< "Dette program vil lukke Windows, vil du fortsætte\\? ";
cin>> svar;
switch(x){
case 1:
if(svar == ja){
cout<< " " << b;
}
case 2:
if(svar == nej){
cout<< "windows vil ikke blive lukket";
}
case 3:
cout<< "du skal skrive ja eller nej, kør programmet igen";
}
}
nogen der har en god ide? fejlen er 55
D:\\programmering\\luk windows\\luk windows videre.cpp `x' undeclared (first use this function) og
57 D:\\programmering\\luk windows\\luk windows videre.cpp `ja' undeclared (first use this function) og til sidst:
61 D:\\programmering\\luk windows\\luk windows videre.cpp `nej' undeclared (first use this function)
Indlæg senest redigeret d. 06.03.2007 18:25 af Bruger #3353