Operate the INI file and run it automatically upon startup

Source: Internet
Author: User
Public class volumncfg
{
Public static string INIFILE;
[Dllimport ("Kernel32")]
Private Static extern long writeprivateprofilestring (string section, string key, string Val, string filepath );
[Dllimport ("Kernel32")]
Private Static extern int getprivateprofilestring (string section, string key, string def, stringbuilder retval, int size, string filepath );
/// <Summary>
/// Constructor
/// </Summary>
/// <Param name = "INIFILE"> file path </param>
Public volumncfg ()
{
INIFILE = system. Windows. Forms. application. startuppath + "\ volumncfg. ini ";
If (! File. exists (INIFILE ))
Initaskfile (INIFILE );
}

Public static void init1_file (string filepath)
{
Iniwritevalue ("volumncfg", "autorun", system. boolean. falsestring );
Iniwritevalue ("volumncfg", "opacity", "0.8 ");
Iniwritevalue ("volumncfg", "delaysec", "3 ");
}

/// <Summary>
/// Write the INI File
/// </Summary>
/// <Param name = "section"> Project Name (for example, [datatp]) </param>
/// <Param name = "key"> key </param>
/// <Param name = "value"> value </param>
Public static void iniwritevalue (string section, string key, string value)
{
Writeprivateprofilestring (section, key, value, INIFILE );
}

/// <Summary>
/// Read the INI File
/// </Summary>
/// <Param name = "section"> Project Name (for example, [datatp]) </param>
/// <Param name = "key"> key </param>
Public static string inireadvalue (string section, string key)
{
Stringbuilder temp = new stringbuilder (500 );
Int I = getprivateprofilestring (section, key, "", temp, 500, INIFILE );
Return temp. tostring ();
}


/// <Summary>
/// Start item
/// </Summary>
/// <Param name = "started"> Start or not </param>
/// <Param name = "name"> name of the startup value </param>
/// <Param name = "path"> Start Program Path </param>
Public static void setautorun (bool started, string name, string path)
{
Registrykey HKLM = registry. localmachine;
Registrykey run = HKLM. createsubkey (@ "SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run ");
If (started = true)
{
Try
{
Run. setvalue (name, PATH );
HKLM. Close ();
}
Catch (exception)
{
// MessageBox. Show (ERR. Message. tostring (), "MUS", messageboxbuttons. OK, messageboxicon. Error );
}
}

}

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.