Try pin folders to quick access on Win10 with .net6.
I've tried using whether c# or powershell script, they all stuck after InvokeVerb("pintohome")
. and there's no any other shell instance or folder open.
Then i have to force quit the shell or just delete it.
There's no further info when i tried using breakpoint in visual studio, just get stuck and nothing happens, no erros and no infos, just nothing.
Here's my code, and basically same as those on whether stackoverflow or msdn.
I just know little about c#, so it's not clear for me to figure out why this happens and how to continue. Has someone have had similar issue?
public void pin_to_home(string path)
{
// If path not exists or is a file, return false
if (!(File.Exists(path) ^ Directory.Exists(path)))
{
Console.WriteLine("Given path is inavlid. " + File.Exists(path));
return;
}
Type shellAppType = Type.GetTypeFromProgID("Shell.Application");
object pinShell = System.Activator.CreateInstance(shellAppType);
if (pinShell == null)
{
return;
}
dynamic pathFolder = shellAppType.InvokeMember("NameSpace", System.Reflection.BindingFlags.InvokeMethod, null, pinShell, new object[] { path });
if (pathFolder == null)
{
return;
}
Console.WriteLine("Try pin to home: " + path);
pathFolder.Self.InvokeVerb("pintohome");
}
or ps script
$Namespace = "shell:::{679f85cb-0220-4080-b29b-5540cc05aab6}"
$QuickAccess = New-Object -ComObject Shell.Application
$RecentFiles = $QuickAccess.Namespace($Namespace).Items()
Write-Output "Start pin to home!"
$QuickAccess.Namespace("D:\TEMP").Self.InvokeVerb("pintohome")
Write-Output "Finish! "