4

I have created following C# console app:

var userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
var path2 = Environment.ExpandEnvironmentVariables("%userprofile%");

File.AppendAllText(@"D:\logs\info.txt", userName + " -- " + path + " -- " + path2);

When I create a scheduled task using Windows Task Scheduler and set the user account to run the task to my account (ht-laptop\huseyin), I am getting the following output in info.txt file:

ht-laptop\huseyin -- C:\Users\Default\Documents -- C:\Users\Default

This seems to be random though, I had seen cases where the printed text was as follows:

ht-laptop\huseyin -- C:\Users\huseyin\Documents -- C:\Users\huseyin

Any idea why this happens?

sangram parmar
  • 8,462
  • 2
  • 23
  • 47
huseyint
  • 14,953
  • 15
  • 56
  • 78
  • Use `Debugger.Break()` to pause the process. Then inspect how it was started with say Process Explorer. Perhaps you have a duplicate task item still setup. – leppie Jun 26 '15 at 08:21

1 Answers1

2

Are you running this on Windows 8+ (or similar)? If so, this is a known issue with user profile loading. The technote (kb2968540) has a workaround (which is kind of kludgy IMO).

  • Yep, I am on Windows 8.1, looks like this is the issue I am having, I am going to try the work around and get you back. Thanks bunch! – huseyint Jun 26 '15 at 08:29