C#实现伪装文件夹功能
芝麻粒儿 人气:0实践过程
效果
代码
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; }
加载全部内容