计算机病毒恶搞程序,【图片】我写的恶搞软件【病毒吧】_百度贴吧

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

class2.cs:

using Microsoft.Win32;

using System;

using System.Windows.Forms;

using System.Diagnostics;

namespace MPR

{

public class Class2

{

///

/// 将本程序设为开启自启

///

/// 自启开关

///

public static bool SetMeStart(bool onOff)

{

string appName = Process.GetCurrentProcess().MainModule.ModuleName;

string appPath = Process.GetCurrentProcess().MainModule.FileName;

bool isOk = SetAutoStart(onOff, appName, appPath);

return isOk;

}

///

/// 将应用程序设为或不设为开机启动

///

/// 自启开关

/// 应用程序名

/// 应用程序完全路径

public static bool SetAutoStart(bool onOff, string appName, string appPath)

{

bool isOk = true;

//如果从没有设为开机启动设置到要设为开机启动

if (!IsExistKey(appName) && onOff)

{

isOk = SelfRunning(onOff, appName, @appPath);

}

//如果从设为开机启动设置到不要设为开机启动

else if (IsExistKey(appName) && !onOff)

{

isOk = SelfRunning(onOff, appName, @appPath);

}

return isOk;

}

///

/// 判断注册键值对是否存在,即是否处于开机启动状态

///

/// 键值名

///

private static bool IsExistKey(string keyName)

{

try

{

bool _exist = false;

RegistryKey local = Registry.LocalMachine;

RegistryKey runs = local.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);

if (runs == null)

{

RegistryKey key2 = local.CreateSubKey("SOFTWARE");

RegistryKey key3 = key2.CreateSubKey("Microsoft");

RegistryKey key4 = key3.CreateSubKey("Windows");

RegistryKey key5 = key4.CreateSubKey("CurrentVersion");

RegistryKey key6 = key5.CreateSubKey("Run");

runs = key6;

}

string[] runsName = runs.GetValueNames();

foreach (string strName in runsName)

{

if (strName.ToUpper() == keyName.ToUpper())

{

_exist = true;

return _exist;

}

}

return _exist;

}

catch

{

return false;

}

}

///

/// 写入或删除注册表键值对,即设为开机启动或开机不启动

///

/// 是否开机启动

/// 应用程序名

/// 应用程序路径带程序名

///

private static bool SelfRunning(bool isStart, string exeName, string path)

{

try

{

RegistryKey local = Registry.LocalMachine;

RegistryKey key = local.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);

if (key == null)

{

local.CreateSubKey("SOFTWARE//Microsoft//Windows//CurrentVersion//Run");

}

//若开机自启动则添加键值对

if (isStart)

{

key.SetValue(exeName, path);

key.Close();

}

else//否则删除键值对

{

string[] keyNames = key.GetValueNames();

foreach (string keyName in keyNames)

{

if (keyName.ToUpper() == exeName.ToUpper())

{

key.DeleteValue(exeName);

key.Close();

}

}

}

}

catch (Exception a)

{

throw a;

}

return true;

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值