0
我做了一个windows服务(这是工作),但它运行在SYSTEM用户,我希望它在我当前登录的用户上运行。Windows服务从登录用户开始c#
这里是我的服务安装程序类:
[RunInstaller(true)]
class CloudManagerServiceInstaller : Installer
{
public CloudManagerServiceInstaller()
{
var serviceInstaller = new ServiceInstaller();
var serviceProcessInstaller = new ServiceProcessInstaller();
serviceProcessInstaller.Account = System.ServiceProcess.ServiceAccount.User;
serviceProcessInstaller.Username = Environment.MachineName + "\\carl";
serviceInstaller.DisplayName = "Z";
serviceInstaller.StartType = ServiceStartMode.Manual;
serviceInstaller.ServiceName = "Z";
this.Installers.Add(serviceInstaller);
this.Installers.Add(serviceProcessInstaller);
}
}
而且还有我的servicebase:
class CloudManagerServiceBase : ServiceBase
{
public int i = 0;
private System.Timers.Timer _timer;
private int m = 2;
public CloudManagerServiceBase()
{
this.ServiceName = "ZSCloudManager";
}
protected override void OnStart(string[] args)
{
base.OnStart(args);
_timer = new System.Timers.Timer(m * 60 * 1000); // every m minutes
_timer.Elapsed += _timer_Elapsed;
_timer.Start(); // <- important
}
void _timer_Elapsed(object sender, ElapsedEventArgs e)
{ do work }}
我与另一progamm的帮助下安装该服务。 我可以写这样的服务吗?或者我必须遵循这些说明 - >http://blogs.msdn.com/b/winsdk/archive/2009/07/14/launching-an-interactive-process-from-windows-service-in-windows-vista-and-later.aspx 如果是这种情况,那么请给我一个代码片段,因为我没有完全理解这一点。
一个windows服务根本不需要用户登录,可能有多个用户登录。那么你是什么意思,你想运行该服务作为“当前登录的用户”。你想永远以特定的用户身份运行吗? – 2014-12-05 15:09:54
我想你想从Windows服务更改为在用户登录时运行的应用程序。 – AWinkle 2014-12-05 15:32:43
是@Ben Robinson我希望服务始终以特定用户身份运行。 – carlilord 2014-12-08 19:17:35