Stop SetVolumeMountPoint from opening file explorer

Multi tool use
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I am using SetVolumeMountPoint to mount a vhd to a drive letter of my choosing. The problem is that when the vhd is mounted file explorer automatically opens at the new drive directory. This is a problem for me as I need my programs to remain on the foreground and sometimes the spawned file explorer becomes part of the foreground.
https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-setvolumemountpointa
Thoughts?
UPDATE:
I programmatically set the noautorun registry key using these two methods before mounting my vhd:
/// <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
add a comment |
I am using SetVolumeMountPoint to mount a vhd to a drive letter of my choosing. The problem is that when the vhd is mounted file explorer automatically opens at the new drive directory. This is a problem for me as I need my programs to remain on the foreground and sometimes the spawned file explorer becomes part of the foreground.
https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-setvolumemountpointa
Thoughts?
UPDATE:
I programmatically set the noautorun registry key using these two methods before mounting my vhd:
/// <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
add a comment |
I am using SetVolumeMountPoint to mount a vhd to a drive letter of my choosing. The problem is that when the vhd is mounted file explorer automatically opens at the new drive directory. This is a problem for me as I need my programs to remain on the foreground and sometimes the spawned file explorer becomes part of the foreground.
https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-setvolumemountpointa
Thoughts?
UPDATE:
I programmatically set the noautorun registry key using these two methods before mounting my vhd:
/// <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
I am using SetVolumeMountPoint to mount a vhd to a drive letter of my choosing. The problem is that when the vhd is mounted file explorer automatically opens at the new drive directory. This is a problem for me as I need my programs to remain on the foreground and sometimes the spawned file explorer becomes part of the foreground.
https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-setvolumemountpointa
Thoughts?
UPDATE:
I programmatically set the noautorun registry key using these two methods before mounting my vhd:
/// <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
c# c++ winapi kernel32 vhd
edited Jan 4 at 16:34
Edgar Arakelyan
asked Jan 3 at 21:31


Edgar ArakelyanEdgar Arakelyan
205
205
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Cleanest way seem to be to catch RegisterWindowMessage("QueryCancelAutoPlay")
message by your foreground window and return TRUE from your window procedure.
https://docs.microsoft.com/en-us/windows/desktop/shell/autoplay-reg
EDIT:
If foreground window is not your application window, then I would recommend against editing registry, since it is global state, whereas you need just temporary autorun bypass.
Besides windows hook, mentioned in other answer, I would suggest registering your implementation of IQueryCancelAutoPlay interface in running object table
It looks like I can disable autorun for specific drive letters from the registry which is a better solution for my application since I always mount the vhds on specific drive letters and my application is not designed to be the foreground window, but it spawns other applications that are the foreground window.
– Edgar Arakelyan
Jan 3 at 22:32
1
I suggest against registry change, I've edited my answer
– Alexander Gutenev
Jan 4 at 19:42
add a comment |
Another way is using Registry.
Please reference "Using the Registry to Disable AutoRun" "How to disable the Autorun functionality in Windows"
Note
The NoDriveAutoRun and NoDriveTypeAutoRun values should only be
modified by system administrators to change the value for the entire
system for testing or administrative purposes. Applications should not
modify these values, as there is no way to reliably restore them to
their original values.
The third way is based on @Alexander Gutenev have pointed out that register a "QueryCancelAutoPlay" window message and then install a global hook from your application to monitor this message.
Note
You should use global hooks only for debugging purposes; otherwise,
you should avoid them. Global hooks hurt system performance and cause
conflicts with other applications that implement the same type of
global hook.
Hooks tend to slow down the system because they increase the amount of
processing the system must perform for each message. You should
install a hook only when necessary, and remove it as soon as possible.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54030078%2fstop-setvolumemountpoint-from-opening-file-explorer%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Cleanest way seem to be to catch RegisterWindowMessage("QueryCancelAutoPlay")
message by your foreground window and return TRUE from your window procedure.
https://docs.microsoft.com/en-us/windows/desktop/shell/autoplay-reg
EDIT:
If foreground window is not your application window, then I would recommend against editing registry, since it is global state, whereas you need just temporary autorun bypass.
Besides windows hook, mentioned in other answer, I would suggest registering your implementation of IQueryCancelAutoPlay interface in running object table
It looks like I can disable autorun for specific drive letters from the registry which is a better solution for my application since I always mount the vhds on specific drive letters and my application is not designed to be the foreground window, but it spawns other applications that are the foreground window.
– Edgar Arakelyan
Jan 3 at 22:32
1
I suggest against registry change, I've edited my answer
– Alexander Gutenev
Jan 4 at 19:42
add a comment |
Cleanest way seem to be to catch RegisterWindowMessage("QueryCancelAutoPlay")
message by your foreground window and return TRUE from your window procedure.
https://docs.microsoft.com/en-us/windows/desktop/shell/autoplay-reg
EDIT:
If foreground window is not your application window, then I would recommend against editing registry, since it is global state, whereas you need just temporary autorun bypass.
Besides windows hook, mentioned in other answer, I would suggest registering your implementation of IQueryCancelAutoPlay interface in running object table
It looks like I can disable autorun for specific drive letters from the registry which is a better solution for my application since I always mount the vhds on specific drive letters and my application is not designed to be the foreground window, but it spawns other applications that are the foreground window.
– Edgar Arakelyan
Jan 3 at 22:32
1
I suggest against registry change, I've edited my answer
– Alexander Gutenev
Jan 4 at 19:42
add a comment |
Cleanest way seem to be to catch RegisterWindowMessage("QueryCancelAutoPlay")
message by your foreground window and return TRUE from your window procedure.
https://docs.microsoft.com/en-us/windows/desktop/shell/autoplay-reg
EDIT:
If foreground window is not your application window, then I would recommend against editing registry, since it is global state, whereas you need just temporary autorun bypass.
Besides windows hook, mentioned in other answer, I would suggest registering your implementation of IQueryCancelAutoPlay interface in running object table
Cleanest way seem to be to catch RegisterWindowMessage("QueryCancelAutoPlay")
message by your foreground window and return TRUE from your window procedure.
https://docs.microsoft.com/en-us/windows/desktop/shell/autoplay-reg
EDIT:
If foreground window is not your application window, then I would recommend against editing registry, since it is global state, whereas you need just temporary autorun bypass.
Besides windows hook, mentioned in other answer, I would suggest registering your implementation of IQueryCancelAutoPlay interface in running object table
edited Jan 4 at 19:41
answered Jan 3 at 21:41


Alexander GutenevAlexander Gutenev
1,07011018
1,07011018
It looks like I can disable autorun for specific drive letters from the registry which is a better solution for my application since I always mount the vhds on specific drive letters and my application is not designed to be the foreground window, but it spawns other applications that are the foreground window.
– Edgar Arakelyan
Jan 3 at 22:32
1
I suggest against registry change, I've edited my answer
– Alexander Gutenev
Jan 4 at 19:42
add a comment |
It looks like I can disable autorun for specific drive letters from the registry which is a better solution for my application since I always mount the vhds on specific drive letters and my application is not designed to be the foreground window, but it spawns other applications that are the foreground window.
– Edgar Arakelyan
Jan 3 at 22:32
1
I suggest against registry change, I've edited my answer
– Alexander Gutenev
Jan 4 at 19:42
It looks like I can disable autorun for specific drive letters from the registry which is a better solution for my application since I always mount the vhds on specific drive letters and my application is not designed to be the foreground window, but it spawns other applications that are the foreground window.
– Edgar Arakelyan
Jan 3 at 22:32
It looks like I can disable autorun for specific drive letters from the registry which is a better solution for my application since I always mount the vhds on specific drive letters and my application is not designed to be the foreground window, but it spawns other applications that are the foreground window.
– Edgar Arakelyan
Jan 3 at 22:32
1
1
I suggest against registry change, I've edited my answer
– Alexander Gutenev
Jan 4 at 19:42
I suggest against registry change, I've edited my answer
– Alexander Gutenev
Jan 4 at 19:42
add a comment |
Another way is using Registry.
Please reference "Using the Registry to Disable AutoRun" "How to disable the Autorun functionality in Windows"
Note
The NoDriveAutoRun and NoDriveTypeAutoRun values should only be
modified by system administrators to change the value for the entire
system for testing or administrative purposes. Applications should not
modify these values, as there is no way to reliably restore them to
their original values.
The third way is based on @Alexander Gutenev have pointed out that register a "QueryCancelAutoPlay" window message and then install a global hook from your application to monitor this message.
Note
You should use global hooks only for debugging purposes; otherwise,
you should avoid them. Global hooks hurt system performance and cause
conflicts with other applications that implement the same type of
global hook.
Hooks tend to slow down the system because they increase the amount of
processing the system must perform for each message. You should
install a hook only when necessary, and remove it as soon as possible.
add a comment |
Another way is using Registry.
Please reference "Using the Registry to Disable AutoRun" "How to disable the Autorun functionality in Windows"
Note
The NoDriveAutoRun and NoDriveTypeAutoRun values should only be
modified by system administrators to change the value for the entire
system for testing or administrative purposes. Applications should not
modify these values, as there is no way to reliably restore them to
their original values.
The third way is based on @Alexander Gutenev have pointed out that register a "QueryCancelAutoPlay" window message and then install a global hook from your application to monitor this message.
Note
You should use global hooks only for debugging purposes; otherwise,
you should avoid them. Global hooks hurt system performance and cause
conflicts with other applications that implement the same type of
global hook.
Hooks tend to slow down the system because they increase the amount of
processing the system must perform for each message. You should
install a hook only when necessary, and remove it as soon as possible.
add a comment |
Another way is using Registry.
Please reference "Using the Registry to Disable AutoRun" "How to disable the Autorun functionality in Windows"
Note
The NoDriveAutoRun and NoDriveTypeAutoRun values should only be
modified by system administrators to change the value for the entire
system for testing or administrative purposes. Applications should not
modify these values, as there is no way to reliably restore them to
their original values.
The third way is based on @Alexander Gutenev have pointed out that register a "QueryCancelAutoPlay" window message and then install a global hook from your application to monitor this message.
Note
You should use global hooks only for debugging purposes; otherwise,
you should avoid them. Global hooks hurt system performance and cause
conflicts with other applications that implement the same type of
global hook.
Hooks tend to slow down the system because they increase the amount of
processing the system must perform for each message. You should
install a hook only when necessary, and remove it as soon as possible.
Another way is using Registry.
Please reference "Using the Registry to Disable AutoRun" "How to disable the Autorun functionality in Windows"
Note
The NoDriveAutoRun and NoDriveTypeAutoRun values should only be
modified by system administrators to change the value for the entire
system for testing or administrative purposes. Applications should not
modify these values, as there is no way to reliably restore them to
their original values.
The third way is based on @Alexander Gutenev have pointed out that register a "QueryCancelAutoPlay" window message and then install a global hook from your application to monitor this message.
Note
You should use global hooks only for debugging purposes; otherwise,
you should avoid them. Global hooks hurt system performance and cause
conflicts with other applications that implement the same type of
global hook.
Hooks tend to slow down the system because they increase the amount of
processing the system must perform for each message. You should
install a hook only when necessary, and remove it as soon as possible.
edited Jan 4 at 9:48
answered Jan 4 at 9:34
Rita Han - MSFTRita Han - MSFT
5,2261313
5,2261313
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54030078%2fstop-setvolumemountpoint-from-opening-file-explorer%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
j09q,2CFuv4MpAS11qaNmZ