伪装文件夹

Posted on   努力成长静待花开  阅读(186)  评论(0编辑  收藏  举报

实现效果:

  

知识运用:  

  File类的CreateText方法    //创建或打开一个文件用于写入UTF-8编码的文本

  public static StreamWriter CreateText (string path)    //f返回一个StreamWriter对象 它使用UTF-8编码写入指定文件

  StreamWriter对象的WriteLine方法  //将字符串写入文本流

  public virtual voidWriteLine (string value)

实现代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//返回对应值
private string GetFolType()
{
    int flage = comboBox1.SelectedIndex;
    switch (flage)
    {
        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}";
    }
    return @"{20D04FE0-3AEA-1069-A2D8-08002B30309D}";
}
//进行伪装操作
private void Camouflage(string fpath)
{
    if (File.Exists(fpath + "\\" + @"desktop.ini"))
        File.Delete(fpath + "\\" + @"desktop.ini");
    StreamWriter sw= File.CreateText(fpath+"\\"+@"desktop.ini");
    sw.WriteLine(@"[.ShellClassInfo]");
    sw.WriteLine("CLSID="+GetFolType());
    sw.Close();
    File.SetAttributes(fpath + "\\" + @"desktop.ini",FileAttributes.Hidden);
    File.SetAttributes(fpath + "\\" + @"desktop.ini", FileAttributes.System);
    MessageBox.Show("伪装成功","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
//还原伪装文件夹
private void NCamouflage(string fpath)
{
    string temp = fpath + "\\" + @"desktop.ini";
    if (!File.Exists(temp))
    {
        MessageBox.Show("该文件夹没有被伪装", "提示");
        return;
    }
    else
    {
        File.Delete(temp);
        MessageBox.Show("还原成功!", "提示");
    }
}

  

努力加载评论中...
点击右上角即可分享
微信分享提示