2

I've been using

Environment.UserName

To display the current user's name and it's been working all this time.

However, started working on my project today - Environment.UserName has returned the word "SYSTEM" despite the user name still being the same as it was before.

derHugo
  • 83,094
  • 9
  • 75
  • 115
SammyJ
  • 25
  • 6
  • Hello! Does this answer your question?https://stackoverflow.com/questions/21111687/environment-username-returning-application-pool-name-instead-of-username –  Dec 04 '19 at 12:10
  • [`Environment.UserName`](https://learn.microsoft.com/dotnet/api/system.environment.username) `The user name of the person who is logged on to the operating system.` or what describes it actually better: `You can use the UserName property to identify the user on the current thread` ... is it possible your app / UnityEditor is running as the Windows administrator user called "System"? – derHugo Dec 04 '19 at 12:21
  • are you using windows service? – Praveen M Dec 04 '19 at 14:45

1 Answers1

3

Happened to us too 3 days ago, we were reaching the documents and settings via Environment.UserName (i guess it was a windows update)

We solved it by using %USERPROFILE% instead of Environment.UserName in the string.

 readonly string savedFilesDirectoryPath =
     Environment.ExpandEnvironmentVariables(@"%USERPROFILE%\Documents\OurProjectName");

%USERPROFILE% env var on windows indicates where a user home directory is located in the file system

For your exact question tho: I think in build mode your solution will work actually so try that

Menyus
  • 6,633
  • 4
  • 16
  • 36