我正在使用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();
}
}发布于 2019-01-03 21:41:58
最干净的方法似乎是从前台窗口捕获RegisterWindowMessage("QueryCancelAutoPlay")消息并从窗口过程返回TRUE。
https://learn.microsoft.com/en-us/windows/desktop/shell/autoplay-reg
编辑:如果前台窗口不是您的应用程序窗口,那么我建议不要编辑注册表,因为它是全局状态,而您只需要临时的自动运行旁路。
发布于 2019-01-04 09:34:11
另一种方法是使用注册表。
请参阅"使用注册表禁用AutoRun“"如何禁用Windows中的自动运行功能”
Note
系统管理员只应修改NoDriveAutoRun和NoDriveTypeAutoRun值,以更改整个系统的值,以用于测试或管理目的。应用程序不应该修改这些值,因为无法可靠地将它们恢复到它们的原始值。
第三种方法是基于@Alexander已经指出,注册一个"QueryCancelAutoPlay“窗口消息,然后从您的应用程序中安装一个全局钩子来监视该消息。
Note
您应该只在调试时使用全局挂钩;否则,您应该避免使用它们。全局钩子损害系统性能,并导致与实现相同类型全局钩子的其他应用程序发生冲突。 钩子会减缓系统的运行速度,因为它们增加了系统对每条消息必须执行的处理量。您应该只在必要时安装钩子,并尽快将其移除。
https://stackoverflow.com/questions/54030078
复制相似问题