c# - How can I set sort of "Start in"-path for a Windows Service -
i have following class, used windows installer project, install service:
[runinstaller(true)] public sealed class installer : system.configuration.install.installer { private readonly string _installdir; public installer() { var locatedassembly = this.gettype().assembly.location; this._installdir = path.getdirectoryname(locatedassembly); var serviceprocessinstaller = new serviceprocessinstaller { account = serviceaccount.localsystem }; var serviceinstaller = new serviceinstaller { servicename = settings.service.name, starttype = servicestartmode.automatic }; this.installers.add(serviceprocessinstaller); this.installers.add(serviceinstaller); this.context = new installcontext(this._installdir + @"\install.log", new[] { string.format("/assemlypath={0}", locatedassembly) }); } public override void install(idictionary statesaver) { base.install(statesaver); var servicecontroller = new servicecontroller(settings.service.name); servicecontroller.start(); servicecontroller.waitforstatus(servicecontrollerstatus.running); } } if call following code inside console application, directory of assembly taken:
using (var stream = file.open("foo.store", filemode.openorcreate)) if run line windows service, c:\windows\system32\ taken instead.
how can change behaviour?
for clarification: not want utilize assembly-spying (get path of assembly this.gettype()...) or in appsettings. want work straight without magic on caller side :)
you need read folder location configuration file, or registry. there's no analogue of starting directory.
Comments
Post a Comment