Call the context menu function of a Windows Operating System

Source: Internet
Author: User
There are many components in the operating system that can call the functions of these components to integrate system functions into our software. Using these components can accomplish many tasks that we cannot imagine.
When I was doing something today, I accidentally found that the operating system has a component, shell32.dll, on the C drive. Program Under the System32 file (which can be searched), this component encapsulates the indexes of many folders and files on the computer. I did not carefully test the specific components, because there are too many. Besides, you can use this component to call the context menu items of these folders and files. Therefore, many menu functions of files and folders in the operating system can be called in our program using this component.
I did a test and put a new file .txt on the table. Right-click the file and choose open, edit, delete, compress, scan virus, and attribute from the menu to call these functions.
The specific method is: Add shell32.dll to the project, define the shell Class Object of the component, and then call the function of the object. For example Code Now, open the new file .txt on the table and scan the virus (I installed Kaspersky ).
Shell32.shell SH = new shell32.shell ();
Shell32.folder Sf = Sh. namespace (0 );
Shell32.folderitems FS = SF. Items ();
String itemname = Fi. Item (11). Name. tostring ();
Shell32.folderitemverbs fivs = FCM. Item (11). verbs ();
Foreach (shell32.folderitemverb FV in fivs)
{
String name = FV. Name. tostring ();
If (name = "open (& O )")
{
FV. doit ();
}
If (name = "Scan virus (& K )")
{
FV. doit ();
// Break;
}
}
It's easy. I don't have a few lines of code...
However, nothing is better than 100%, and the disadvantages of calling components are very large. I will not use components unless I have. For example, components are highly dependent on the system. A new version of the system may fail to be executed, and the code above may fail to be executed or implemented on your machine, not to mention that the code I wrote is incorrect.
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.