|
本帖最后由 heavenm 于 2015-7-7 19:10 编辑
第一种方法,可以解除大多数标准的 任务栏锁定,但是有些就不行 比如PPS或者百度浏览器#Include <WinAPIEx.au3>
#Include <array.au3>
_pinunpin('C:\Windows\System32\calc.exe','p2tb')
MsgBox(0, '', '解除')
_pinunpin('C:\Windows\System32\calc.exe','up2tb')
Func _pinunpin($filepath, $action = 'p2sm', $arguments = '')
Local $clean,$pathsplit,$lastp,$file,$path,$filesplit,$last,$fileext,$filename,$code,$linkfile,$hInstance,$localizedstring
Local $objShell,$objFolder,$objFolderItem
$clean = 0
If Not FileExists($filepath) Or @OSBuild < 7600 Then Exit ; to arrange to your liking, SetError() & co
;split path, filename and extension
$pathsplit = StringSplit($filepath, '\')
$lastp = $pathsplit[0]
$file = $pathsplit[$lastp]
$path = StringReplace($filepath, $file, '')
$path = StringTrimRight($path, 1)
$filesplit = StringSplit($file, ".")
$last = $filesplit[0]
$fileext = $filesplit[$last]
$filename = StringReplace($file, '.' & $fileext, '', 1)
;define code to use depending on action choosen
Switch $action
Case 'pin2SM', 'p2sm' ;pin to Start Menu
$code = 5381
Case 'unpinFromSM', 'up2sm' ;unpin from Start Menu
$code = 5382
Case 'pin2TB', 'p2tb' ;pin to Task Bar
$code = 5386
Case 'unpinFromTB', 'up2tb' ;unpin from Task Bar
$code = 5387
EndSwitch
;if arguments, make a shortcut, pin it then mark it for deletion
If $arguments <> '' And $code <> 5382 And $code <> 5387 Then
$linkfile = @DesktopDir & '\' & $filename & '.lnk'
FileCreateShortcut($filepath, $linkfile, $path, $arguments, $filename & ' ' & $arguments, $filepath)
$path = @DesktopDir
$file = $filename & '.lnk'
$clean = 1
EndIf
;retrieve Localized text for action
$hInstance = _WinAPI_LoadLibraryEx('shell32.dll', $LOAD_LIBRARY_AS_DATAFILE)
If $hInstance Then
$localizedstring = _WinAPI_LoadString($hInstance, $code)
;If @error Then MsgBox(0, "Error", _WinAPI_GetLastErrorMessage()) ;debug
_WinAPI_FreeLibrary($hInstance)
EndIf
;when unpining from Start Menu, use the shortcut that is effectively pinned to do so, if argument(s) they are ignored
If $code == 5382 Then
$path = @UserProfileDir & '\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu'
$file = $filename & '.lnk'
EndIf
;pin or unpin
$objShell = ObjCreate('Shell.Application')
$objFolder = $objShell.Namespace($path)
$objFolderItem = $objFolder.ParseName($file)
For $val In $objFolderItem.Verbs()
If StringInStr($val(), $localizedstring) Then
$val.DoIt()
EndIf
Next
;clean temporary shortcut
If $clean Then
FileDelete($linkfile)
EndIf
EndFunc ;==>_pinunpin
另一种方法简单
ShellExecute ($_TASKBAR_PATH&'\Internet Explorer.lnk', '','',"taskbarunpin" )
但是存在问题就是如果这个程序没有在任务栏锁定就会弹出错误消息 |
|