码迷,mamicode.com
首页 > Windows程序 > 详细

C#读取计算机插入USB历史记录

时间:2017-06-30 15:27:00      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:div   ntc   show   rms   als   logs   gen   .com   sub   

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;

namespace USBforensic1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            RegistryKey USBConnKey;
            
            USBConnKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Enum\USBSTOR", false);
            foreach (string sub1 in USBConnKey.GetSubKeyNames())
            {
                RegistryKey sub1key = USBConnKey.OpenSubKey(sub1, false);
                foreach (string sub2 in sub1key.GetSubKeyNames())
                {
                    try
                    {
                        RegistryKey sub2key = sub1key.OpenSubKey(sub2, false);
                        if (sub2key.GetValue("Service", "").Equals("disk"))
                        {
                            String Path = "USBSTOR" + "\\" + sub1 + "\\" + sub2;
                            String Name = (string)sub2key.GetValue("FriendlyName", "");
                            richTextBox1.AppendText("USB名称  " + Name + "\r\n");
                            richTextBox1.AppendText("UID标记  " + sub2 + "\r\n");
                            richTextBox1.AppendText("路径信息 " + Path + "\r\n\r\n");
                        }
                    }
                    catch (Exception msg)
                    {
                        MessageBox.Show(msg.Message);
                    }
                }
            }
        }
    }
}

  

C#读取计算机插入USB历史记录

标签:div   ntc   show   rms   als   logs   gen   .com   sub   

原文地址:http://www.cnblogs.com/websec/p/7098409.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!