积极答复者
windows服务的安装

问题
-
IDictionary mySavedState = new Hashtable();
AssemblyInstaller AssemblyInstaller1 = new AssemblyInstaller();
AssemblyInstaller1.UseNewContext = true;
AssemblyInstaller1.Path = Application.ExecutablePath+" -s";
AssemblyInstaller1.Install(mySavedState);
AssemblyInstaller1.Commit(mySavedState);
AssemblyInstaller1.Dispose();AssemblyInstaller1.Path = Application.ExecutablePath+" -s";我是想如果是服务,启动时传-s参数。但在安装时出错。
在Program的Main函数里
if (args != null && args.Length > 0 && (args[0].Trim().ToLower() == "-s" || args[0].Trim().ToLower()=="/s"))
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Service1()
};
ServiceBase.Run(ServicesToRun);
}
else
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}这个怎么安装服务,才能达到我要的效果?
无
答案
-
不记得了。
现在是安装后,
RegistryKey regKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\"+m_strServiceName,true);
object value = regKey.GetValue("ImagePath");
if (value != null)
{
string imgePath = value.ToString();
regKey.SetValue("ImagePath", imgePath + " -s");
regKey.Flush();
}这样就可以了
无
- 已标记为答案 Lie YouModerator 2012年4月13日 1:36
全部回复
-
不记得了。
现在是安装后,
RegistryKey regKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\"+m_strServiceName,true);
object value = regKey.GetValue("ImagePath");
if (value != null)
{
string imgePath = value.ToString();
regKey.SetValue("ImagePath", imgePath + " -s");
regKey.Flush();
}这样就可以了
无
- 已标记为答案 Lie YouModerator 2012年4月13日 1:36
-