C#实现伪装文件夹功能

 更新时间:2022年12月26日 09:51:07   作者:芝麻粒儿  
这篇文章主要为大家详细介绍了如何利用C#实现伪装文件夹的功能,文中的示例代码讲解详细,对我们学习C#有一定的帮助,感兴趣的小伙伴可以跟随小编一起了解一下

实践过程

效果

代码

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
    private string GetFolType()
    {
        int Tid = comboBox1.SelectedIndex;
        switch (Tid)
        {
            case 0: return @"{20D04FE0-3AEA-1069-A2D8-08002B30309D}";
            case 1: return @"{450D8FBA-AD25-11D0-98A8-0800361B1103}";
            case 2: return @"{992CFFA0-F557-101A-88EC-00DD010CCC48}";
            case 3: return @"{21EC2020-3AEA-1069-A2DD-08002B30309D}";
            case 4: return @"{D6277990-4C6A-11CF-8D87-00AA0060F5BF}";
            case 5: return @"{2227A280-3AEA-1069-A2DE-08002B30309D}";
            case 6: return @"{208D2C60-3AEA-1069-A2D7-08002B30309D}";
            case 7: return @"{645FF040-5081-101B-9F08-00AA002F954E}";
            case 8: return @"{85BBD920-42A0-1069-A2E4-08002B30309D}";
            case 9: return @"{BD84B380-8CA2-1069-AB1D-08000948F534}";
            case 10: return @"{BDEADF00-C265-11d0-BCED-00A0C90AB50F}";
        }
        return @"{20D04FE0-3AEA-1069-A2D8-08002B30309D}";
    }
    private void button1_Click(object sender, EventArgs e)
    {
        if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
        {
            if (folderBrowserDialog1.SelectedPath.Length >= 4)
            {
                txtFolPath.Text = folderBrowserDialog1.SelectedPath;
            }
            else
            {
                MessageBox.Show("不能对盘符进行伪装", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        comboBox1.SelectedIndex = 0;
    }

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (comboBox1.SelectedIndex == 11)
        {
            txtID.ReadOnly = false;
            txtID.Text = "";
        }
        else
        {
            txtID.ReadOnly = true;
            txtID.Text = GetFolType();
        }

    }

    private void Camouflage(string str)
    {
        StreamWriter sw = File.CreateText(txtFolPath.Text.Trim() + @"\desktop.ini");
        sw.WriteLine(@"[.ShellClassInfo]");
        sw.WriteLine("CLSID=" + str);
        sw.Close();
        File.SetAttributes(txtFolPath.Text.Trim() + @"\desktop.ini", FileAttributes.Hidden);
        File.SetAttributes(txtFolPath.Text.Trim(), FileAttributes.System);
        MessageBox.Show("伪装成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }

    private void button2_Click(object sender, EventArgs e)
    {
        if (this.txtFolPath.Text == "")
        {
            MessageBox.Show("请选择文件夹路径!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        else
        {
            try
            {
                if (txtID.ReadOnly == false)
                {
                    string str = txtID.Text.Trim();
                    if (str.StartsWith("."))
                        str = str.Substring(1);
                    if (!str.StartsWith("{")||str.Trim().Length!=38)
                    {
                        MessageBox.Show("自定义类型错误!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        Camouflage(str);
                    }
                }
                else
                {
                    Camouflage(GetFolType());
                }
            }
            catch
            {
                MessageBox.Show ("不要进行多次伪装!","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
            }
        }
    }

    private void button3_Click(object sender, EventArgs e)
    {
        if (txtFolPath.Text == "")
        {
            MessageBox.Show("请选择加密过的文件夹!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Error);
        }
        else
        {
            try
            {
                FileInfo fi = new FileInfo(txtFolPath.Text.Trim() + @"\desktop.ini");
                if (!fi.Exists)
                {
                    MessageBox.Show("该文件夹没有被伪装!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    System.Threading.Thread.Sleep(1000);
                    File.Delete(txtFolPath.Text + @"\desktop.ini");
                    File.SetAttributes(txtFolPath.Text.Trim(), FileAttributes.System);
                    MessageBox.Show("还原成功", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch
            {
                MessageBox.Show("不要多次还原!");
            }
        }
    }
}
partial class Form1
{
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Windows 窗体设计器生成的代码

    /// <summary>
    /// 设计器支持所需的方法 - 不要
    /// 使用代码编辑器修改此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
        this.groupBox1 = new System.Windows.Forms.GroupBox();
        this.txtFolPath = new System.Windows.Forms.TextBox();
        this.button1 = new System.Windows.Forms.Button();
        this.label1 = new System.Windows.Forms.Label();
        this.groupBox2 = new System.Windows.Forms.GroupBox();
        this.txtID = new System.Windows.Forms.TextBox();
        this.label3 = new System.Windows.Forms.Label();
        this.comboBox1 = new System.Windows.Forms.ComboBox();
        this.label2 = new System.Windows.Forms.Label();
        this.groupBox3 = new System.Windows.Forms.GroupBox();
        this.button3 = new System.Windows.Forms.Button();
        this.button2 = new System.Windows.Forms.Button();
        this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
        this.groupBox1.SuspendLayout();
        this.groupBox2.SuspendLayout();
        this.groupBox3.SuspendLayout();
        this.SuspendLayout();
        // 
        // groupBox1
        // 
        this.groupBox1.Controls.Add(this.txtFolPath);
        this.groupBox1.Controls.Add(this.button1);
        this.groupBox1.Controls.Add(this.label1);
        this.groupBox1.ForeColor = System.Drawing.Color.Black;
        this.groupBox1.Location = new System.Drawing.Point(12, 8);
        this.groupBox1.Name = "groupBox1";
        this.groupBox1.Size = new System.Drawing.Size(431, 55);
        this.groupBox1.TabIndex = 1;
        this.groupBox1.TabStop = false;
        this.groupBox1.Text = "第一步:选择文件夹";
        // 
        // txtFolPath
        // 
        this.txtFolPath.Location = new System.Drawing.Point(78, 22);
        this.txtFolPath.Name = "txtFolPath";
        this.txtFolPath.Size = new System.Drawing.Size(296, 21);
        this.txtFolPath.TabIndex = 0;
        // 
        // button1
        // 
        this.button1.Location = new System.Drawing.Point(380, 21);
        this.button1.Name = "button1";
        this.button1.Size = new System.Drawing.Size(43, 23);
        this.button1.TabIndex = 2;
        this.button1.Text = "选择";
        this.button1.UseVisualStyleBackColor = true;
        this.button1.Click += new System.EventHandler(this.button1_Click);
        // 
        // label1
        // 
        this.label1.AutoSize = true;
        this.label1.Location = new System.Drawing.Point(6, 25);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(77, 12);
        this.label1.TabIndex = 1;
        this.label1.Text = "文件夹路径:";
        // 
        // groupBox2
        // 
        this.groupBox2.Controls.Add(this.txtID);
        this.groupBox2.Controls.Add(this.label3);
        this.groupBox2.Controls.Add(this.comboBox1);
        this.groupBox2.Controls.Add(this.label2);
        this.groupBox2.ForeColor = System.Drawing.Color.Black;
        this.groupBox2.Location = new System.Drawing.Point(12, 69);
        this.groupBox2.Name = "groupBox2";
        this.groupBox2.Size = new System.Drawing.Size(431, 99);
        this.groupBox2.TabIndex = 2;
        this.groupBox2.TabStop = false;
        this.groupBox2.Text = "第二部:选择伪装的类型";
        // 
        // txtID
        // 
        this.txtID.Location = new System.Drawing.Point(103, 57);
        this.txtID.Name = "txtID";
        this.txtID.ReadOnly = true;
        this.txtID.Size = new System.Drawing.Size(320, 21);
        this.txtID.TabIndex = 3;
        // 
        // label3
        // 
        this.label3.AutoSize = true;
        this.label3.Location = new System.Drawing.Point(20, 60);
        this.label3.Name = "label3";
        this.label3.Size = new System.Drawing.Size(77, 12);
        this.label3.TabIndex = 2;
        this.label3.Text = "自定义类型:";
        // 
        // comboBox1
        // 
        this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
        this.comboBox1.FormattingEnabled = true;
        this.comboBox1.Items.AddRange(new object[] {
        "我的电脑",
        "我的文档",
        "拨号网络",
        "控制面板",
        "计划任务",
        "打印机",
        "网络邻居",
        "回收站",
        "公文包",
        "字体",
        "Web 文件夹",
        "自定义ID"});
        this.comboBox1.Location = new System.Drawing.Point(101, 26);
        this.comboBox1.Name = "comboBox1";
        this.comboBox1.Size = new System.Drawing.Size(322, 20);
        this.comboBox1.TabIndex = 1;
        this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
        // 
        // label2
        // 
        this.label2.AutoSize = true;
        this.label2.Location = new System.Drawing.Point(8, 30);
        this.label2.Name = "label2";
        this.label2.Size = new System.Drawing.Size(89, 12);
        this.label2.TabIndex = 0;
        this.label2.Text = "选择伪装类型:";
        // 
        // groupBox3
        // 
        this.groupBox3.Controls.Add(this.button3);
        this.groupBox3.Controls.Add(this.button2);
        this.groupBox3.ForeColor = System.Drawing.Color.Black;
        this.groupBox3.Location = new System.Drawing.Point(12, 174);
        this.groupBox3.Name = "groupBox3";
        this.groupBox3.Size = new System.Drawing.Size(431, 53);
        this.groupBox3.TabIndex = 3;
        this.groupBox3.TabStop = false;
        this.groupBox3.Text = "第三部:操作";
        // 
        // button3
        // 
        this.button3.Location = new System.Drawing.Point(230, 20);
        this.button3.Name = "button3";
        this.button3.Size = new System.Drawing.Size(75, 23);
        this.button3.TabIndex = 1;
        this.button3.Text = "还原";
        this.button3.UseVisualStyleBackColor = true;
        this.button3.Click += new System.EventHandler(this.button3_Click);
        // 
        // button2
        // 
        this.button2.Location = new System.Drawing.Point(127, 20);
        this.button2.Name = "button2";
        this.button2.Size = new System.Drawing.Size(75, 23);
        this.button2.TabIndex = 0;
        this.button2.Text = "伪装";
        this.button2.UseVisualStyleBackColor = true;
        this.button2.Click += new System.EventHandler(this.button2_Click);
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(452, 233);
        this.Controls.Add(this.groupBox3);
        this.Controls.Add(this.groupBox2);
        this.Controls.Add(this.groupBox1);
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
        this.MaximizeBox = false;
        this.Name = "Form1";
        this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
        this.Text = "伪装文件夹";
        this.Load += new System.EventHandler(this.Form1_Load);
        this.groupBox1.ResumeLayout(false);
        this.groupBox1.PerformLayout();
        this.groupBox2.ResumeLayout(false);
        this.groupBox2.PerformLayout();
        this.groupBox3.ResumeLayout(false);
        this.ResumeLayout(false);

    }

    #endregion

    private System.Windows.Forms.GroupBox groupBox1;
    private System.Windows.Forms.TextBox txtFolPath;
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.GroupBox groupBox2;
    private System.Windows.Forms.GroupBox groupBox3;
    private System.Windows.Forms.Button button3;
    private System.Windows.Forms.Button button2;
    private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
    private System.Windows.Forms.ComboBox comboBox1;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.TextBox txtID;
    private System.Windows.Forms.Label label3;
}

到此这篇关于C#实现伪装文件夹功能的文章就介绍到这了,更多相关C#伪装文件夹内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • C# 8.0可空引用类型的使用注意记录

    C# 8.0可空引用类型的使用注意记录

    这篇文章主要给大家介绍了关于C# 8.0可空引用类型使用注意的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用C#具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
    2019-04-04
  • 详解C#如何手动改变自制窗体的大小

    详解C#如何手动改变自制窗体的大小

    这篇文章主要为大家详细介绍了在C#中如何实现手动改变自制窗体的大小,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下
    2024-03-03
  • C#获取指定目录下某种格式文件集并备份到指定文件夹

    C#获取指定目录下某种格式文件集并备份到指定文件夹

    这篇文章介绍了C#获取指定目录下某种格式文件集并备份到指定文件夹的方法,文中通过示例代码介绍的非常详细。对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-04-04
  • C#设置软件开机自动运行的方法(修改注册表)

    C#设置软件开机自动运行的方法(修改注册表)

    这篇文章主要介绍了C#设置软件开机自动运行的方法,通过简单修改注册表开机启动项实现软件的开机启动功能,非常简单实用,需要的朋友可以参考下
    2016-06-06
  • C#使用IronPython调用Python的实现

    C#使用IronPython调用Python的实现

    本文主要介绍了C#使用IronPython调用Python的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-02-02
  • C# ping网络IP 实现网络状态检测的方法

    C# ping网络IP 实现网络状态检测的方法

    下面小编就为大家带来一篇C# ping网络IP 实现网络状态检测的方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2016-08-08
  • C#调用exe文件的方法详解

    C#调用exe文件的方法详解

    这篇文章主要为大家详细介绍了C#调用exe文件的相关方法,文中的示例代码讲解详细,具有一定的借鉴价值,有需要的小伙伴可以参考一下
    2024-04-04
  • 解析C#中断言与异常的应用方式及异常处理的流程控制

    解析C#中断言与异常的应用方式及异常处理的流程控制

    这篇文章主要介绍了C#中断言与异常的应用方式及异常处理的流程控制,一般来说断言用于修正程序员自己的错误而异常用于应对程序运行过程中可能出现的错误,需要的朋友可以参考下
    2016-01-01
  • C#获取HTML文本的第一张图片与截取内容摘要示例代码

    C#获取HTML文本的第一张图片与截取内容摘要示例代码

    在日常web开发的时候,经常会遇到需要获取保存的HTML文本中的第一张图片,并且截取内容摘要的效果,例如织梦的后台添加完详细内容后就是自动读取内容摘要,并保存第一张图片为缩略图,那么这篇文章跟大家分享下利用C#如何实现,感兴趣的朋友们下面来一起看看吧。
    2016-10-10
  • C# 执行CMD命令并接收返回结果的操作方式

    C# 执行CMD命令并接收返回结果的操作方式

    这篇文章主要介绍了C# 执行CMD命令并接收返回结果的操作方式,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2021-04-04

最新评论