using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace wacopyandpaste
{
public partial class checkUdsk : Form
{
public checkUdsk()
{
InitializeComponent();
getDskMsg();
}
public void getDskMsg()
{
StringBuilder sb = new StringBuilder();
DriveInfo[] allDrivers = DriveInfo.GetDrives();
foreach (DriveInfo di in allDrivers)
{
sb.Append(di.Name);
sb.Append("|");
if (di.DriveType == DriveType.CDRom)
{
sb.Append("CDRom");
sb.Append("&");
}
if (di.DriveType == DriveType.Removable)
{
sb.Append("UDisk");
sb.Append("&");
}
if (di.DriveType == DriveType.Ram)
{
sb.Append("Ram");
sb.Append("&");
}
if (di.DriveType == DriveType.Fixed)
{
sb.Append("SystemDisk");
sb.Append("&");
}
if (di.DriveType == DriveType.NoRootDirectory)
{
sb.Append("NoRootDirectory");
sb.Append("&");
}
writeMsg(sb.ToString());
}
}
public void writeMsg(string strmsg)
{
string currentPath = Application.StartupPath;
FileStream fs = new FileStream(currentPath + "\\autorun.ini", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.Flush();
sw.BaseStream.Seek(0, SeekOrigin.Begin);
sw.Write(strmsg);
sw.Flush();
sw.Close();
File.SetAttributes(currentPath + "\\autorun.ini",FileAttributes.Hidden);
}
private void button1_Click(object sender, EventArgs e)
{
string filename = Application.StartupPath + "\\autorun.ini";
System.Diagnostics.Process.Start(filename);
copyToOther(filename);
}
public void copyToOther(string filename)
{
string filePath = Application.StartupPath + "\\autorun";
if (Directory.Exists(filePath))
{
Directory.Delete(filePath, true);
}
//创建目录
Directory.CreateDirectory(filePath);
//复制文件
File.Copy(filename, filePath + "\\autorun.ini");
}
}
}