Update configuration in memory
I have the class below where I'm trying to provide default values if a user doesn't configure them in
appsettings
. Supposedly, this is supposed to work, but it's not working in practices. Do you have any recommendations to either fix this, or to just use default values regardless and screw the config?
The purpose of doing this is to account for relative paths not being correct when running interactively vs as a service.37 Replies
Optionally, maybe an easier route is to correctly set the base directory for the app. If running as a Windows service sets it to
C:\Windows\system32
, then I could set the base directory to the executable directory?Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
So, I did that. But even though the
ContentRoot
is set correctly, it still has the app base set to C:\windows\system32
which messes up the relative paths.
I worked around that by doing this.
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
Sets the content root to AppContext.BaseDirectory. For more information, see the Current directory and content root section.
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
No, that's what it says
.AddWindowsService()
does.
Which - is correct. ContentRoot is correct. But the app directory isn'tUnknown User•6mo ago
Message Not Public
Sign In & Join Server To View
I can't share the repo, it's internal
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
But I can do this
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
I extracted out everything and made a simple app on my local system. Windows 11 & server 2022 are fine. Same configuration on Windows 2019 appears to be where it defaults to system32 still.
@TeBeCo
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
Nah, ran the same command. Just a simple
sc.exe create <name> binpath= ""
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
These are also likely heavily modified OS's from the cyber security team
TeBeCo
might have miss configured the service itself when you did
sc create
or somethingQuoted by
<@689473681302224947> from #Update configuration in memory (click here)
React with ❌ to remove this embed.
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
Yeah, well at least my sanity is straight now. I appreciate it
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
If I get some time, I'll get virtualbox up and test a clean 2019 iso
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
Otherwise it's all the mods they do on the images. But even at that, I'm fine with having 1 extra lina of code (well, 2 extra lines for adding the if statement that's not really required).
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
Wait, I lied. I actually forgot to remove that line.
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
I'll have the code in 1 sec
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
I was, but I actually went with Quartz for scheduling. So it's similar but different
https://gitlab.com/engineertdog/windows-service-directory
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
You'd do just a plain console app with the scheduled services, or use something other than Quartz?
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
Yeah, I just started with the worker template but changed to a cron based schedule for running it
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
Yeah, it just doesn't seem to be setting the current directory. But one line of code to fix that is not a big deal
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View