Deploy a program to access the registry and MAC address

Source: Internet
Author: User

Some time ago, we were doing deployment again, becauseProgram(B/S ). Server Registry and Mac Address. No problems were found during the program debugging, but the registry and Mac The address is not accessible. Remember that I was writing 《 Install and deploy the database package and quickly start the browser A friend once asked me this similar question. At that time, I was not able to solve the problem well because I had no access to it. But this time, the stone in the Sky finally fell onto my head. I also encountered this problem.

At that time, I only felt that the problem was caused by the access permission. In order to access the registry andMacAddress.Web. configA simulated user is added:

<Identity impersonate = "true"/>

But in fact, this simulated user is no problem when debugging the program. When I deploy it on another machine, the program cannot access local resources because the user has insufficient permissions.

Later, we modified this node.

<Identity impersonate = "true" username = "username" Password = "password"/>

username and password the user name and password of the current machine, and the deployed program can access local resources.

with the solution, new problems have emerged. server to improve security, passwords are often changed, in this way, this program will no longer be used. Therefore, we decided to add a windowfrom program. When server the password has changed, use this program to change Web. config . Example:


CodeAs follows:

 

String Path = configurationsettings. appsettings ["path"]. tostring ();//Obtain from the configuration fileWeb. configAddress

Fileinfo file = new fileinfo (PATH );

Xmldocument Doc = new xmldocument ();

Doc. Load (file. fullname );

Xmlelement root = Doc. documentelement;

Xmlnodelist list = root. selectnodes ("/configuration/system. Web/identity ");

// <! -- Identity impersonate = "true" username = "esint \ Shiwei. Li" Password = ""/-->

If (list. Count! = 0)

{

Xmlnode node = (xmlnode) list [0];

Node. attributes ["Impersonate"]. value = "true ";

Node. attributes ["username"]. value = this.txt username. text;

Node. attributes ["password"]. value = this.txt password. text;

Doc. Save (file. fullname );

}

where path the parameter is winform A parameter in the configuration file. Web. config file path.

< Add Key = "Path" Value = ""/>

This parameter is modified during installation and deployment. A user-defined operation is required. The code in the Custom operation is as follows:

Fileinfo file =NewFileinfo (This. Context. Parameters ["Targetdir"] +@ "\ Activeprogramme \ activeprograme.exe. config");

Xmldocument Doc =NewXmldocument ();

Doc. Load (file. fullname );

Xmlelement root = Doc. documentelement;

Xmlnodelist list = root. selectnodes ("/Configuration/appsettings/Add");

Foreach(Xmlnode NodeInList)

{

If(Node. attributes ["Key"]. Value ="Path")

{

Node. attributes ["Value"]. Value =This. Context. Parameters ["Targetdir"]. Tostring () +@ "\ WEB. config";

Doc. Save (file. fullname );

Break;

}

}

"\ Activeprogramme \ activeprograme.exe. config" YesWinformPath of the configuration file in the program,Activeprograme.exe. configYesWinformUnderApp. configThe file after installation is the Assembly name+ " . EXE. config " .

The above is my solution to this problem. It seems like a huge circle is around. First record during deploymentWeb. configFile absolute location, and then in the customerServerChange PasswordWeb. configNode attribute in. In addition, I always feel that this reduces security. But I do not know any better methods. I hope you can give me more suggestions.

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.