Option Explicit 'Const CSIDL_COMMON_PROGRAMS = &H17 Dim ShellApp, FSO, Desktop Set ShellApp = CreateObject("Shell.Application") Set FSO = CreateObject("Scripting.FileSystemObject") 'Set StartMenuFolder = ShellApp.NameSpace(CSIDL_COMMON_PROGRAMS) Set Desktop = ShellApp.NameSpace("C:\Users\Wayne\Desktop") Dim LnkFile LnkFile = Desktop.Self.Path&"\ScheduleNotifier.lnk" If(FSO.FileExists(LnkFile)) Then Dim tmp, verb 'For Each verb in Desktop.ParseName("ScheduleNotifier.lnk").Verbs 'tmp = tmp&verb&chr(13) 'Next 'MsgBox(tmp) Dim desktopImtes, item Set desktopImtes = Desktop.Items() For Each item in desktopImtes If (item.Name = "ScheduleNotifier") Then 'MsgBox(item.Name) For Each verb in item.Verbs If (verb.Name = "Pin to Tas&kbar") _ Then 'If (verb.Name = "鎖定到任務欄(&K)") verb.DoIt End If Next End If Next End If Set FSO = Nothing Set ShellApp = Nothing
Option Explicit 'Const CSIDL_COMMON_PROGRAMS = &H17 Dim ShellApp, FSO, Desktop Set ShellApp = CreateObject("Shell.Application") Set FSO = CreateObject("Scripting.FileSystemObject") 'Set StartMenuFolder = ShellApp.NameSpace(CSIDL_COMMON_PROGRAMS) Set Desktop = ShellApp.NameSpace("C:\Users\Wayne\Desktop") Dim LnkFile LnkFile = Desktop.Self.Path&"\ScheduleNotifier.lnk" If(FSO.FileExists(LnkFile)) Then Dim tmp, verb 'For Each verb in Desktop.ParseName("ScheduleNotifier.lnk").Verbs 'tmp = tmp&verb&chr(13) 'Next 'MsgBox(tmp) Dim desktopImtes, item Set desktopImtes = Desktop.Items() For Each item in desktopImtes If (item.Name = "ScheduleNotifier") Then 'MsgBox(item.Name) For Each verb in item.Verbs If (verb.Name = "Unpin from Tas&kbar") _ Then 'If (verb.Name = "從任務欄脫離(&K)") verb.DoIt End If Next End If Next End If Set FSO = Nothing Set ShellApp = Nothing
Although two snippets of VBS code are simple and straight-forward, they have one serious limitation. It only supports one specified language, attention of this line of code:html
If (verb.Name = "Pin to Tas&kbar") Then 'If (verb.Name = "鎖定到任務欄(&K)")
If WScript.Arguments.Count < 1 Then WScript.Quit '---------------------------------------------------------------------- Set objFSO = CreateObject("Scripting.FileSystemObject") objFile = WScript.Arguments.Item(0) sKey1 = "HKCU\Software\Classes\*\shell\{:}\\" sKey2 = Replace(sKey1, "\\", "\ExplorerCommandHandler") '---------------------------------------------------------------------- With WScript.CreateObject("WScript.Shell") KeyValue = .RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer" & _ "\CommandStore\shell\Windows.taskbarpin\ExplorerCommandHandler") .RegWrite sKey2, KeyValue, "REG_SZ" With WScript.CreateObject("Shell.Application") With .Namespace(objFSO.GetParentFolderName(objFile)) With .ParseName(objFSO.GetFileName(objFile)) .InvokeVerb("{:}") End With End With End With .Run("Reg.exe delete """ & Replace(sKey1, "\\", "") & """ /F"), 0, True End With '----------------------------------------------------------------------
Param($Target) $KeyPath1 = "HKCU:\SOFTWARE\Classes" $KeyPath2 = "*" $KeyPath3 = "shell" $KeyPath4 = "{:}" $ValueName = "ExplorerCommandHandler" $ValueData = (Get-ItemProperty("HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\" + "Explorer\CommandStore\shell\Windows.taskbarpin")).ExplorerCommandHandler $Key2 = (Get-Item $KeyPath1).OpenSubKey($KeyPath2, $true) $Key3 = $Key2.CreateSubKey($KeyPath3, $true) $Key4 = $Key3.CreateSubKey($KeyPath4, $true) $Key4.SetValue($ValueName, $ValueData) $Shell = New-Object -ComObject "Shell.Application" $Folder = $Shell.Namespace((Get-Item $Target).DirectoryName) $Item = $Folder.ParseName((Get-Item $Target).Name) $Item.InvokeVerb("{:}") $Key3.DeleteSubKey($KeyPath4) if ($Key3.SubKeyCount -eq 0 -and $Key3.ValueCount -eq 0) { $Key2.DeleteSubKey($KeyPath3) }
https://stackoverflow.com/questions/31720595/pin-program-to-taskbar-using-ps-in-windows-10shell
Uses ComObj,... procedure TForm1.Button1Click(Sender: TObject); var Shell, OleFolder, OleFolderItem : OleVariant; i : integer; begin Shell := CreateOleObject('Shell.Application') ; OleFolder := Shell.Namespace('C:\Windows\System32'); OleFolderItem := OleFolder.ParseName('Calc.exe'); OleFolderItem.InvokeVerb('P&in to Start Menu'); //REQUIRED for XP! for i := 0 to OleFolderItem.Verbs.Count - 1 do //REQUIRED for Vista! if OleFolderItem.Verbs.Item(i).Name = 'P&in to Start Menu' then begin OleFolderItem.Verbs.Item(i).DoIt; break; end; end;
https://www.experts-exchange.com/questions/23817347/Using-Delphi-how-to-Pin-an-Icon-to-Start-Menu-xp-style-start-menu-not-the-classic-start-menu.htmlwindows