public static void Main()
{
try
{
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"software\zrh");// 读注册表以判断是否正在运行
if (key == null)//如果不存在,就创建标志位
{
RegistryKey writekey = Registry.LocalMachine.CreateSubKey(@"software\zrh");
writekey.SetValue("instanceFlag", "1"); 
/**//*调用应用程序代码*/
}
else
{
MessageBox.Show("the application has running");
}
}
catch (Exception ex)
{
MessageBox.Show(" on exception is occuring \n" + ex.Message);
}
}
try
Microsoft.Win32.RegistryKey flagKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"software", true);
flagKey.DeleteSubKey("zrh");
}
catch (Exception ex)
{
MessageBox.Show(" on exception is occuring \n" + ex.Message);
}