我正在使用 SetVolumeMountPoint 将 vhd 安装到我选择的驱动器号。问题是,当安装 vhd 时,文件资源管理器会自动在新驱动器目录中打开。这对我来说是一个问题,因为我需要我的程序保留在前台,有时生成的文件资源管理器成为前台的一部分。
https://learn.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();
}
}
最佳答案
最干净的方法似乎是通过前台窗口捕获 RegisterWindowMessage("QueryCancelAutoPlay")
消息并从窗口过程返回 TRUE。
https://learn.microsoft.com/en-us/windows/desktop/shell/autoplay-reg
编辑: 如果前台窗口不是您的应用程序窗口,那么我建议不要编辑注册表,因为它是全局状态,而您只需要临时自动运行绕过。
除了其他答案中提到的 Windows 钩子(Hook)之外,我建议注册 IQueryCancelAutoPlay 的实现界面位于 running object table
关于c# - 停止 SetVolumeMountPoint 打开文件资源管理器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54030078/