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 );
}
}
}