c# - How To Pin To Start Special Folders With No Target -


how pin start special folders using powershell? "thispc", iexplorer

this pin start exe's fine, windows explorer , mycomputer? how pin items since have no target?

given this

 <start:desktopapplicationtile size="2x2" column="0" row="0" desktopapplicationlinkpath="%appdata%\microsoft\windows\start menu\programs\windows system\this pc.lnk" /> 

it seems have issues .lnk's "this pc", "file explorer", etc

function pinlnk {     param     (         [parameter(mandatory,position=0)]         [alias('p')]         [string[]]$path     )     $shell = new-object -comobject shell.application     $desktop = $shell.namespace(0x0)     $wshshell = new-object -comobject wscript.shell     $flag=0     foreach($itempath in $path)     {         $itemname = split-path -path $itempath -leaf         #pin application windows start menu         $itemlnk = $desktop.parsename($itempath)         $itemverbs = $itemlnk.verbs()         foreach($itemverb in $itemverbs)         {             if($itemverb.name.replace("&","") -match "pin start")             {                 $itemverb.doit()                 $flag=1             }         }     } } pinlnk "c:\program files (x86)\microsoft visual studio 14.0\common7\ide\devenv.exe" 

i tried approach still not pinning mycomputer start

ps c:\windows\system32> function pinlnk14 >> { >> >> $shell = new-object -com shell.application >> $folder = $shell.namespace("shell:::{20d04fe0-3aea-1069-a2d8-08002b30309d}") # ssfdrives >> $itemverbs=$folder.self.verbs() >>         foreach($itemverb in $itemverbs) >>         { >>             write-output $itemverb.name >>             if($itemverb.name.replace("&","") -match "pin start") >>             { >> write-output "trying pin" >>                 $itemverb.doit() >>             } >>         } >>     } ps c:\windows\system32> ps c:\windows\system32> pinlnk14 &open pin quick access mana&ge &pin start trying pin map &network drive... dis&connect network drive... create &shortcut &delete rena&me p&roperties 

most special folders accessible using special values, documented here: shellspecialfolderconstants enumeration

so, if want computer (a.k.a. "this pc") folder, can this:

$shell = new-object -com shell.application $folder = $shell.namespace(17) # "ssfdrives" constant 

and folder object.

there way wich uses folder clsid (a guid). allow folder in what's called shell namespace, ones may not defined in enumeration above (3rd party shell namespace extensions example). syntax this:

$shell = new-object -com shell.application $folder = $shell.namespace("shell:::{clsid}") 

in fact, funny syntax combines 'shell:' uri moniker shell namespace parsing syntax ::{clsid}.

so example computer folder, use constant known clsid_mycomputer this:

$shell = new-object -com shell.application $folder = $shell.namespace("shell:::{20d04fe0-3aea-1069-a2d8-08002b30309d}") 

this work:

$shell = new-object -com shell.application $folder = $shell.namespace("shell:mycomputerfolder") # direct shell: syntax 

and should bring same object in previous call. they're equivalent.

once have folder object, there last trick associated verbs, because verbs() method defined on folderitem object. folderitem folder (as folder "item" in namespace, has folderitem facade), can use self property, this:

$shell = new-object -com shell.application $folder = $shell.namespace("shell:::{20d04fe0-3aea-1069-a2d8-08002b30309d}") # ssfdrives $folder.self.verbs() 

ok, verbs folderitem. pin item start however, "pin start" verb invocation not work (for computer example), or verb isn't available (for standard folder example). in general, doesn't work folders reason.

so, 1 solution folders first create shortcut file (.lnk) somewhere folder (including computer or other special locations), , pin shortcut file start. note: standard (non language localized) verb pin start "pintostartscreen", it's better use scan various verbs (all verbs have canonical name). code pin computer start:

$wshell = new-object -com wscript.shell $shortcut = $wshell.createshortcut("c:\temp\mypc.lnk") $shortcut.targetpath = "shell:mycomputerfolder" # use same syntax described above $shortcut.save()  $shell = new-object -com shell.application $folder = $shell.namespace("c:\temp") $lnk = $folder.parsename("mypc.lnk") # shortcut file $lnk.invokeverb("pintostartscreen") # invoke "pin start" on shortcut file 

the fact that's windows when "pin start" on computer, creates shortcut in c:\users\<my user>\appdata\roaming\microsoft\windows\start menu\programs


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -