I'm creating a little stupid service as a joke, is supposed to create an "invincible" txt on the desktop which gets recreated if deleted. It works when debugged but when I install the service it doesn't create the txt.
I have :
- execute the service with admin rights adding this line of code:
<PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="Custom" SameSite="site" />
to the app.manifest). - I checked the "the authorize to interact whit desktop" checkmark on the service proprieties.
the code is working when I debug (i use Topshelf) but when I install the service it does not work.
the code which creates the txt(and the constructor):
public Invincible()
{
_timer = new Timer(3000) { AutoReset = true };
_timer.Elapsed += TimerElapsed;
}
private void TimerElapsed(object sender, ElapsedEventArgs e)
{
string[] frase = new string[] {"NON PUOI RIMUOVERE QUESTA MALEDIZIONE <3"};
string curFile = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)+"/Invincible_Curse.txt";
string curFile2 = "C:/temp/Demos/Invincible_Curse.txt";
if (!File.Exists(curFile))
{
File.AppendAllLines(curFile, frase);
}
}
the Main:
static void Main(string[] args)
{
var exitCode = HostFactory.Run(x =>
{
x.Service<Invincible>(s =>
{
s.ConstructUsing(Invincible => new Invincible());
s.WhenStarted(Invincible => Invincible.Start());
s.WhenStopped(Invincible => Invincible.Stop());
x.SetServiceName("InvincibleService");
x.SetDisplayName("Invincible Service");
x.SetDescription("Cerca di sopravvivere");
});
});
int exitCodeValue = (int)Convert.ChangeType(exitCode, exitCode.GetTypeCode());
Environment.ExitCode = exitCodeValue;
}
thanks for the help.