[英]How Can I Check To See If App was Started From A CD/DVD in C#?
如何檢查是否從C#中的CD / DVD啟動了應用程序?
使用Application.StartupPath屬性獲取exe所在的路徑。 然后使用新的DriveInfo(driveletter_from_path).DriveType確定它是CD還是硬盤。
您可以這樣做:
FileInfo file = new FileInfo(Process.GetCurrentProcess().MainModule.FileName);
DriveInfo drive = new DriveInfo(file.Directory.Root.ToString());
switch (drive.DriveType)
{
case DriveType.CDRom:
MessageBox.Show("Started from CD/DVD");
break;
case DriveType.Network:
MessageBox.Show("Started from network");
break;
case DriveType.Removable:
MessageBox.Show("Started from removable drive");
break;
default:
break;
}
擴展codemanix的答案:
string location = Assembly.GetExecutingAssembly().Location;
DriveInfo info = new DriveInfo(Path.GetPathRoot(location));
if (info.DriveType == DriveType.CDRom)
{
Console.WriteLine("Started from CD-ROM");
}
您需要檢查可執行路徑,然后查看它是否在CD / DVD驅動器上。 您可以使用以下命令獲取可執行文件路徑:
string path = Application.ExecutablePath;
我不能完全肯定你為什么這樣做,但以防萬一它是復制保護的企圖老記(古) SUBST在MS-DOS。
請記住,可以偽造使用Application.ExecutablePath和DriveInfo ...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.