通过注册表判断一个服务是否存在
1 private bool IsServiceExist()
2 {
3 string[] subkeyNames;
4 RegistryKey hkml = Registry.LocalMachine;
5 RegistryKey software = hkml.OpenSubKey(@"SYSTEM\CurrentControlSet\services");
6 subkeyNames = software.GetSubKeyNames(); //取得该项下所有子项的名称的序列,并传递给预定的数组中
7 foreach (string keyName in subkeyNames)
8 {
9 if (keyName == serviceName)
10 {
11 hkml.Close();
12 return true;
13
14 }
15 }
16 hkml.Close();
17 return false;
18 }
2 {
3 string[] subkeyNames;
4 RegistryKey hkml = Registry.LocalMachine;
5 RegistryKey software = hkml.OpenSubKey(@"SYSTEM\CurrentControlSet\services");
6 subkeyNames = software.GetSubKeyNames(); //取得该项下所有子项的名称的序列,并传递给预定的数组中
7 foreach (string keyName in subkeyNames)
8 {
9 if (keyName == serviceName)
10 {
11 hkml.Close();
12 return true;
13
14 }
15 }
16 hkml.Close();
17 return false;
18 }
浙公网安备 33010602011771号