-5

I'am writing a program in C#. How to move file without knowing a username? Like C:\Users\ and now there is a username, but I don't know the someones username and how to move it?

            var proc2 = new ProcessStartInfo();
            proc2.UseShellExecute = true;

            proc2.WorkingDirectory = @"C:\Windows\System32";

            proc2.FileName = @"C:\Windows\System32\cmd.exe";
            proc2.Verb = "runas";
            proc2.Arguments = "/c move x.bat C:\Users\HERE";       
            proc2.WindowStyle = ProcessWindowStyle.Hidden;
            Process.Start(proc2);

2 Answers2

1

The closest would be the environment variable %userprofile%, which contains the path to the current user's directory: C:\Users\Somebody.

Swift
  • 3,250
  • 1
  • 19
  • 35
  • But do you know how to add it into code that I added in description? – JsonFile191 Mar 31 '19 at 15:31
  • A quick google search would bring you [here](https://learn.microsoft.com/en-us/dotnet/api/system.environment.getenvironmentvariable?view=netframework-4.7.2) – Swift Mar 31 '19 at 15:33
0

You can do like this:

String foldername = @"C:\Users\" & Environment.UserName

Getting user name with the command : Environment.UserName