Warm tip: This article is reproduced from serverfault.com, please click
c#

How to get the users certain directory for apps

发布于 2020-11-27 22:38:40

I am trying to make it so it finds the current user on the pc so that when i put (for example USERPROFILE) it can find the right directory to the exe

        private void siticoneImageButton3_Click_1(object sender, EventArgs e)
        {
           Process.Start("C:\\Users\\USERPROFILE\\AppData\\Local\\Programs\\lunarclient\\Lunar Client.exe");
        }
Questioner
saustee
Viewed
0
Matthew Ransley 2020-11-28 08:34:26

You should be able to use the Environment.UserName property like so:

Process.Start($"C:\\Users\\{Environment.UserName}\\AppData\\Local\\Programs\\lunarclient\\Lunar Client.exe");