首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >停止SetVolumeMountPoint打开文件资源管理器

问停止SetVolumeMountPoint打开文件资源管理器
EN

Stack Overflow用户
提问于 2019-01-03 21:31:31
回答 2查看 337关注 0票数 1

我正在使用SetVolumeMountPoint将vhd挂载到我选择的驱动器上。问题是,当vhd被挂载时,文件资源管理器会在新的驱动器目录下自动打开。这对我来说是个问题,因为我需要我的程序保持在前台,有时生成的文件资源管理器会成为前台的一部分。

https://learn.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-setvolumemountpointa

有什么想法?

更新:

在挂载vhd之前,我使用以下两种方法编程地设置了noautorun注册表项:

代码语言:javascript
复制
        /// <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();
            }
        }
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-01-03 21:41:58

最干净的方法似乎是从前台窗口捕获RegisterWindowMessage("QueryCancelAutoPlay")消息并从窗口过程返回TRUE。

https://learn.microsoft.com/en-us/windows/desktop/shell/autoplay-reg

编辑:如果前台窗口不是您的应用程序窗口,那么我建议不要编辑注册表,因为它是全局状态,而您只需要临时的自动运行旁路。

除了在其他答案中提到的windows钩子之外,我建议在运行对象表中注册您的运行对象表接口实现。

票数 4
EN

Stack Overflow用户

发布于 2019-01-04 09:34:11

另一种方法是使用注册表。

请参阅"使用注册表禁用AutoRun“"如何禁用Windows中的自动运行功能”

Note

系统管理员只应修改NoDriveAutoRun和NoDriveTypeAutoRun值,以更改整个系统的值,以用于测试或管理目的。应用程序不应该修改这些值,因为无法可靠地将它们恢复到它们的原始值。

第三种方法是基于@Alexander已经指出,注册一个"QueryCancelAutoPlay“窗口消息,然后从您的应用程序中安装一个全局钩子来监视该消息。

Note

您应该只在调试时使用全局挂钩;否则,您应该避免使用它们。全局钩子损害系统性能,并导致与实现相同类型全局钩子的其他应用程序发生冲突。 钩子会减缓系统的运行速度,因为它们增加了系统对每条消息必须执行的处理量。您应该只在必要时安装钩子,并尽快将其移除。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54030078

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档