C # implement URL-based triggering of your programs

Source: Internet
Author: User

Principle: http://hi.baidu.com/wu1987116/blog/item/8352896056ea254deaf8f83e.html

Function in this example: When ie accesses the Baidu: content, execute ceshi.exeProgramIn the program, the content is used as a search

Content, execute Baidu search

Steps:

Create a Windows Application in vs2005

Static void main () in the program. CS File ()

Add to MethodCode:

Static void main ()
{
Application. enablevisualstyles ();
Application. setcompatibletextrenderingdefault (false );
If (system. environment. getcommandlineargs (). length> 1) // If any startup parameter exists
{
String strcmd = system. environment. getcommandlineargs () [1]. tolower ();
String startcmd = "http://www.baidu.com/s? WD = "+ strcmd. Replace (" Baidu :","");
System. Diagnostics. process. Start (startcmd );
}
Else
{
MessageBox. Show ("parameter error! "," Prompt ");
}
}

Generate EXE file

Import the following registry information:

Windows Registry Editor Version 5.00

[Hkey_classes_root \ Baidu]
@ = ""
"URL protocol" = ""

[Hkey_classes_root \ Baidu \ shell]

[Hkey_classes_root \ Baidu \ shell \ open]

[Hkey_classes_root \ Baidu \ shell \ open \ command]
@ = "D: \ ceshi.exe % 1"

"D: \ ceshi.exe % 1" is the generated program path,

what this registry implements is when the browser (or other) encounters a Baidu :... Ceshi.exe is automatically called, and Baidu :... The address is passed as a parameter to ceshi.exe, and ceshi.exe is used to determine the input parameter format and perform the operation.

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.