Can I access Duplicati environment variables from a .NET console app?

I was thinking I could make a .NET console app to run as a post-script after my backup completes, and am trying to access the Duplicati environment variables in that app. I ran my backup job, expecting that when I went in Visual Studio to see those variables available but they are all returning NULL. When I look at Environment.GetAllVariables() I don’t see any Duplicati variables listed.

I wondered if maybe it was the user context; my backup jobs are running as a service so I ran VS as administrator and got the same result.

My idea was for a cross-platform console app in dotnetcore, or am I limited to only using bash or batch file scripts as a “run-script-after” option?

I’m running Duplicati - 2.0.2.15_experimental_2018-01-03, on Windows 10, using Visual Studio 2017 Community Edition. Thanks for any help!

Can I assume you mean Environment.GetEnvironmentVariables() instead of Environment.GetAllVariables()?

If so, then I don’t really know why it isn’t working for you. My simple test application that writes all environment variables to a file works just fine. I simply added the compiled *.exe file as parameter for the run-script-after option.

Do you see the variables when you iterate through them all with Environment.GetEnvironmentVariables() and they have a value of NULL or are they not even in there?

Sorry, yes, I meant Environment.GetEnvironmentVariables()…was typing too fast :slight_smile:

I don’t see the environment variable at all. What I thought I could expect was that I could run a backup job, and then after the fact launch my app and debug through in VS and see the results of the variables. What I’m wondering now is - when a process is run via the run-script-after option does that get run in a special process or something and the variables are only available under that context instead of persisting to the whole system?

The environment variables are only set for the spawned process, so just running a program will not have access to the variables. That is very much “by-design” as it would otherwise be possible to interfere with other processes on the system.

Ah that makes sense, thanks! I’ll just need to adjust my testing process to take that into account. Thanks again!