The userprofile path returns the default value during the execution of the schedule task

I created the following C # console application:

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 the Windows Task Scheduler and set a user account to run the task in my account ( ht-laptop\huseyin), I get the following output in the info.txt file :

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

This seems random, although I saw cases where the printed text was as follows:

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

Any idea why this is happening?

+4
source share
1 answer

Windows 8+ ( )? , . (kb2968540) ( kludgy IMO).

+2

All Articles