Python write automation icon lock to taskbar or delete icon

Source: Internet
Author: User

This feature is sometimes used when testing an on-board load on Windows, and the versions of the two languages found online are as follows:

C # version:

Shell shell = new Shell (); Folder folder = Shell. NameSpace (Path.getdirectoryname (AppPath)); FolderItem app = folder. ParseName (Path.getfilename (AppPath)); string sverb = Islock? "Lock to Taskbar (&k)": "Detach from Taskbar (&k)"; foreach (Folderitemverb Fib in app. Verbs ()) {    if (fib.name = = Sverb)    {       fib.doit ();       return true;    }} return false;

VB version:

Public Shared Function Lockapp (islock as Boolean, AppPath as String) as Booleandim shell as New shell () Dim folder as Folde R = Shell. [NameSpace] (Path.getdirectoryname (AppPath)) Dim app as FolderItem = folder. ParseName (Path.getfilename (AppPath)) Dim sverb as String = If (Islock, "Locked (&k)", "Detached (&k)") for each Fib as Folderite Mverb in App. Verbs () If fib.name = Sverb thenfib.doit () Return trueend Ifnextreturn falseend Function


The next step is to convert the above code into Python, where the Windows interface is used, and the Windows interface is called in Python, and you can use the win32com

The code is as follows:

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 "Detach from taskbar (&k)" or  desktopcommon.tounicode (verb. Name) = = u "Unpin from Tas&kbar":                    verb. DoIt ()
The Python version of the icon operation is OK.

Welcome to the "Sogou test" of the public, a daily test-related articles to share with you to discuss the technology and development of software testing

Reprint Please specify: Http://blog.csdn.net/sogouauto

Python write automation icon lock to taskbar or delete icon

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.