Reputation: 15715
I'm using this to get the location of my application's config file:
string path = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
But it doesn't give me the path to the file that is actually being used.
My problem is that, I need my application to be runnable from the Windows Task Scheduler, and I want it to take parameters. The way I've been doing it is, when I create a task in the Scheduler, click Browse and locate the appref-ms
icon. Then the Scheduler will fill the text box where I'd enter the path to the file with the path to a weird location under AppData\Local\Apps\2.0\...
(instead of just keeping the path to the icon). This way I can also add arguments and everything works fine unlike other things I've tried such as using the path to the .exe
file or typing the path to the icon, except that...
When the application is launched from the Task Scheduler it uses a different config file than when is launched with the icon. Say I change setting S
to value T
(always from within the application) after running it from the Task Scheduler. Then I change setting S
to I
when I run it from the icon. The next time I run the application from the Task Scheduler, setting S
will be T
and the next time I run it from the icon, setting S
will be I
. Also, setting S
inside the file at the path the code above gives me, is just the default value (which is not T
nor I
).
This is a big problem because I need my settings to be the same no matter how I'm running the application. I'm considering replacing the default settings file for my own file with a location determined by myself. Is this my only choice? Is there any other way to run the application from the Task Scheduler such that I'll be able to pass arguments that will also use the same config file as when I run it from the icon? How about a piece of code that would force the application to use always the same config file?
Upvotes: 0
Views: 588
Reputation: 11877
You could move the settings to a place that everyone can find them. If it's anything that's saved, you'll want to do this anyway, as ClickOnce updates can wipe out the user's saved settings.
Upvotes: 1
Reputation: 45
I know you can get the application installed path from
INSTALLED_PATH = Application.StartupPath ;
One approach could be that the first launch of the application, after each ClicOnce deployment, would be from the the icon. If the application then saves INSTALLED_PATH to a fixed text file, then the task could get the path from there. Does that makes sense ?
Upvotes: 0