Windows 서비스 (작동 중)를 만들었지 만 SYSTEM 사용자에서 실행 중이며 현재 로그인 한 사용자에서 실행되기를 원합니다.
내 서비스 설치 프로그램 클래스는 다음과 같습니다.
[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);
}
}
그리고 내 서비스베이스가 있습니다.
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 }}
다른 프로그램의 도움으로 서비스를 설치합니다. 그렇게 서비스를 작성할 수 있습니까 아니면 다음 지침을 따라야합니까-> http://blogs.msdn.com/b/winsdk/archive/2009/07/14/launching-an-interactive-process-from-windows -service-in-windows-vista-and-later.aspx 그럴 경우 코드 스 니펫을 주실 수 있습니다. 왜냐하면 나는 이것을 완전히 이해하지 못하기 때문입니다.
나는 그것을 수동으로 포기하고 Visual Studio의 서비스 사전 설정으로 만들었습니다. 방금 이것을 사전 설정 (projectInstaller 클래스)에 추가했습니다.
public ProjectInstaller()
{
InitializeComponent();
serviceProcessInstaller1.Username = ".\\" + Environment.UserName;
}
그리고 serviceProcessInstaller의 속성 계정을 "user"로 설정합니다. 그런 다음 서비스 클래스에 코드를 추가 할 수 있습니다. 그것은 나를 위해 잘 작동합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다