【发布时间】:2019-05-30 12:03:26
【问题描述】:
我正在使用 SetVolumeMountPoint 将 vhd 挂载到我选择的驱动器号。问题是当 vhd 被挂载时,文件资源管理器会自动在新的驱动器目录中打开。这对我来说是个问题,因为我需要我的程序保持在前台,有时生成的文件资源管理器会成为前台的一部分。
https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-setvolumemountpointa
想法?
更新:
在挂载我的 vhd 之前,我使用这两种方法以编程方式设置 noautorun 注册表项:
/// <summary>
/// Removing file explorer auto run for the given DriveLetter so that when a vhd is mounted file explorer doesn't open
/// </summary>
/// <param name="DriveLetter"></param>
private void RemoveFileExplorerAutoRun(char DriveLetter)
{
var KeyPath = "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer";
RegistryKey AutoRunKey = Registry.CurrentUser.OpenSubKey(KeyPath, true);
var DriveLetterValue = DriveLetter - 'A';
if (AutoRunKey != null)
{
RemoveFileExplorerAutoRun(AutoRunKey, DriveLetterValue);
}
else // create key as it does not exist
{
AutoRunKey = Registry.CurrentUser.CreateSubKey(KeyPath);
RemoveFileExplorerAutoRun(AutoRunKey, DriveLetterValue);
}
}
private void RemoveFileExplorerAutoRun(RegistryKey AutoRunKey, int DriveLetterValue)
{
if (AutoRunKey != null)
{
AutoRunKey.SetValue("NoDriveTypeAutoRun", DriveLetterValue);
AutoRunKey.Close();
}
}
【问题讨论】:
标签: c# c++ winapi kernel32 vhd