I am doing some work with a Windows ServiceApplication and when I run the application it correctly writes a file with an updated value every 5 seconds with a timer. When I launch the application as a service, no file is written on Windows. Not sure what I am doing incorrectly or what I am missing? Any thoughts?
I changed the App’s super to a ServiceApplication, and installed the service with the following sc command:
sc create Text type= own start= auto binpath= c:\\Test\\TestServices.exe
Service installation works well. I start the application and its supposed to overwrite a file to the desktop every 5 seconds with the added text value of elapsed seconds (5, 10, 15,etc). I start the service, and all is successful to this point. Unfortunately, there is no file created on the desktop. If I run the program in a command prompt or double click the program in an explorer window, then it works well and creates and overwrites the file every 5 seconds. Is there maybe an elevated permission needed to write a file with a ServiceApplication?
The output file will be C:\Windows\System32\config\systemprofile\Desktop\TestService.txt, but you won’t have access to the folder unless you change permissions. Perhaps output to a folder on C:?
Right. Check the user that the service is running as. Thats the desktop itll show up under… and only if it has permissions to do so (some users are not interactive and dont actually have user folders like Desktop)
This worked! Thanks Wayne. I modified the line of code to point to a C:\Test\ directory and it works when running.
f= New FolderItem("c:\\Test\\TestService.txt")
This is interesting as I am the only user on my development computer and when I use the SpecialFolder.Desktop.Child(“TestService.txt”) location then the file does not appear, as it must be writing the information somewhere else.
f=SpecialFolder.Desktop.Child("TestService.txt")
Changing the code to point to my account desktop works:
f= New FolderItem("C:\\Users\\eugen\\Desktop\\TestService.txt")
Great information Wayne and Greg, thanks for your help!!
[quote=400189:@Greg O’Lone]try sending SpecialFolder.Desktop.ShellPath to your log. I bet it doesn’t point where you think.[/quote]I must not have permission, since my computer will not allow me to get the ShellPath information. I learn something new every day. Greg, your right, as the path doesn’t go where I thought it should.
Technically, you’re not. There are special system users. By default, a service does not run as you. It runs as SYSTEM. You could set it to run as you, but I usually use SpecialFolder.SharedApplicationData.