发布网友 发布时间:2022-04-25 22:44
共1个回答
热心网友 时间:2022-06-18 08:13
这个功能在windows上测试安装卸载时,有时会用到,网上查到的两种语言的版本如下:
C#版:
[csharp] view plain copy
Shell shell = new Shell();
Folder folder = shell.NameSpace(Path.GetDirectoryName(appPath));
FolderItem app = folder.ParseName(Path.GetFileName(appPath));
string sVerb = isLock ? "锁定到任务栏(&K)" : "从任务栏脱离(&K)";
foreach (FolderItemVerb Fib in app.Verbs())
{
if (Fib.Name == sVerb)
{
Fib.DoIt();
return true;
}
}
return false;
[vb] view plain copy
Public Shared Function LockApp(isLock As Boolean, appPath As String) As Boolean
Dim shell As New Shell()
Dim folder As Folder = shell.[NameSpace](Path.GetDirectoryName(appPath))
Dim app As FolderItem = folder.ParseName(Path.GetFileName(appPath))
Dim sVerb As String = If(isLock, "锁定(&K)", "脱离(&K)")
For Each Fib As FolderItemVerb In app.Verbs()
If Fib.Name = sVerb Then
Fib.DoIt()
Return True
End If
Next
Return False
End Function
接下来,就是要把上面的代码如何转化为Python了,此处使用到了Windows接口,Python中调用windows接口,可以使用win32com
代码如下:
[python] view plain copy
def DeleteQuickLaunchOnTaskBar(lnkName):
objShell = win32com.client.Dispatch("Shell.Application")
taskbarPath = os.path.join(os.environ["appdata"], r'Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar')
lnkName = DesktopCommon.ToUnicode(lnkName)
objFolder = objShell.NameSpace(taskbarPath)
desktopItems = objFolder.Items()
for item in desktopItems:
if DesktopCommon.ToUnicode(item.Name) == lnkName:
verbs = item.Verbs()
for verb in verbs:
if DesktopCommon.ToUnicode(verb.Name) == u"从任务栏脱离(&K)" or DesktopCommon.ToUnicode(verb.Name) == u"Unpin from Tas&kbar":
verb.DoIt()