程序代码:
using System;
using System.Collections.Generic;
using using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.ServiceProcess;
using System.Management;
using Microsoft.Win32;
namespace WindowsApplication4
{
public partial class Form1 : Form
{
public static string path = String.Empty;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ServiceIsExisted("360rp");
if (path!="")
{
MessageBox.Show(path);
}
}
private bool ServiceIsExisted(string serviceName)
{
ServiceController[] services = ServiceController.GetServices();
foreach (ServiceController s in services)
{
if (s.ServiceName == serviceName)
{
if (FilePath(s.ServiceName)!="")
{
path = FilePath(s.ServiceName);
}
return true;
}
}
return false;
}
public string FilePath(string serviceName)
{
RegistryKey _Key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\ControlSet001\Services\" + serviceName);
if (_Key != null)
{
object _ObjPath = _Key.GetValue("ImagePath");
if (_ObjPath != null) return _ObjPath.ToString();
}
return "";
}
}
}
按照楼主的意思 写出代码 由于本人机器没有安装oracle 所以用360 代替
图片附件: 游客没有浏览图片的权限,请
登录 或
注册