C # Two Methods for operating the registry and general methods for invoking scripts

Source: Internet
Author: User

Today, I am in a hurry to change the usage of daily supplements

1) using Microsoft. Win32; this is a common method and has many details. This is not the focus.

Code
Public static string getregvalue (string strregpath, string strregkeyname)
{
String STR;
Try
{
Registrykey rk = registry. localmachine. opensubkey (strregpath, true );

If (rk! = NULL)
{
STR = rk. getvalue (strregkeyname). tostring ();
}
Else
{
STR = "unable find the specified registry key or value ";
}

}
Catch (exception E)
{
STR = "unable find the specified registry key or value, Vista may need close UAC! "+ E;
}
Return STR;
}

 

2) Reference wshom. ocx: This provides a way to reuse various scripts. You can consider this when the methods provided by the framework are not good. For the time being, I just thought it was useful, but I still don't know how to use it.

VaR Reg = new activexobject ("wscript. Shell"); // locate the OCX reference of wscript. Shell

Reg. Read ();

Code
Public static string getregvalue (string strregpath)
{
String strregvalue;
Try
{
Iwshruntimelibrary. wshshell Ws = new iwshruntimelibrary. wshshell ();
Strregvalue = ws. regread (strregpath). tostring ();
}
Catch (exception E)
{
Strregvalue = "unable find the specified registry key or value, Vista may need close UAC! "+ E;
}
Return strregvalue;
}

 

 

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.