How the Web system can read hardware information such as client computer Mac and is compatible with non IE browser

Source: Internet
Author: User

In a real-world Web application, we may encounter a "need to qualify a specific computer or user to use the system" issue.

As a general rule, the most likely use of ActiveX controls is to implement them, but this scenario is only applicable to IE. In order to be compatible with different browsers, such as Firefox, we need to consider a more general approach. This method we can refer to "in many sites, will be a link in the page somewhere to start QQ directly to chat." This approach enables the Web system to invoke an EXE file on the client computer (provided that the client must install an EXE application that needs to be called). The solution for QQ is to register a custom protocol in the OS, such as: Tencent://message/?uin=88888888&site=abc.com&menu=yes.

You can enter the above address in the browser address bar, can pop up a QQ chat dialog box, so that the web system and the client's local EXE application communication.

Through the above method, we can refer to this scheme to realize the Web system to read to the client computer's MAC address and so on.

In order to achieve this, we probably need the following steps:

1, first, we need to create a table in the database, such as: Logintempinfo, whose fields are:

Loginid,macaddress Two fields are all right.

2, create a WindowsForm application (to receive the Web login ID, and then get the local MAC address, and update to the Logintempinfo table in the background). The main point to note is: In the class Program.cs the main method in main is passed in a parameter, string[] args.

Specific as follows:

<summary>
The main entry point for the application.
</summary>
[STAThread]
static void Main (string[] args)
{
int argslength = args. Length;
MessageBox.Show (Argslength.tostring ());
Application.enablevisualstyles ();
Application.setcompatibletextrenderingdefault (FALSE);
if (Argslength = = 0)
{
Application.Run (New Form1 ());
}
Else
{
MessageBox.Show (Args[0]);
Application.Run (New Form1 (Args[0]));
}
}

The above parameter is to receive the connection address in the Web, in this address we pass some parameters, to implement the arguments with the EXE.

3, we can add a connection address in the Window.onload method in the login page login.aspx of the web system, for example: helloworld://hello_world/apara=abc001.

After the page is loaded, a unique loginID is automatically generated, and the loginID is inserted into the table Logintempinfo, when its macaddress is empty.

A connection is then automatically performed: helloworld://hello_world/loginid=**** (which represents the unique login ID for this build).

At this point, the local HelloWorld program is automatically called and the above:helloworld://hello_world/loginid=**** is passed into the EXE program.

In this case, the Web program pauses for 2 seconds and is implemented using the SetTimeout method, and after 2 seconds, the MAC address of the current login ID is removed from the datasheet (after the fourth step).

4, the local EXE program receives the parameter: After the unique login ID, call a method to get the current client computer's MAC address, and update this MAC address to the data table Logintempinfo, corresponding to the current login ID.

5, through the above 5 steps, you can achieve the Web system to obtain the client's MAC address to do the qualification verification.

In particular, the client must register the registry information synchronously when installing the EXE program:

Windows Registry Editor Version 5.00
[Hkey_classes_root\helloworld]
@= "HelloWorld Protocol"
"URL Protocol" = ""
[Hkey_classes_root\helloworld\defaulticon]
@= "e:\\hw_test\\helloworld.exe,1"
[Hkey_classes_root\helloworld\shell]
@=""
[Hkey_classes_root\helloworld\shell\open]
@=""
[Hkey_classes_root\helloworld\shell\open\command]
@= "\" e:\\hw_test\\helloworld.exe\ "\"%1\ ""

The attachment makes a simple example of how the Web system communicates with the local EXE. (Note: Annex is just a reference example)

Above, just the way I think of the more generic Web system calling client MAC address. If you have a better idea, you are welcome to discuss this. Thank you.

Attachment:

http://files.cnblogs.com/cjbandy/Web%E7%A8%8B%E5%BA%8F%E8%B0%83%E7%94%A8%E6%9C%AC%E5%9C%B0exe%E6%96%87%E4%BB% b6%e4%b9%8b%e6%96%b9%e6%b3%95%28%e5%b9%b6%e4%bc%a0%e5%8f%82%e5%88%b0cs%e7%a8%8b%e5%ba%8f%29.7z

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.