I would like to be determine the user name of the account from which a program has been launched with elevated privileges. For example, if a user named "Standard1" with non-admin rights is logged into their Windows account and an application is launched by elevated privileges by a user with Admin privileges (let's call the user "Admin1"), GetUserName called from within the elevated program will return "Admin1". How can I return the user name for the account from which the application was launched ("Standard1")?
Asked
Active
Viewed 43 times
0
-
I very much doubt that is possible. Why would you possibly want to know that? – David Heffernan Dec 17 '15 at 22:08
-
I have a program that must run elevated but the users will in many cases not have admin rights. So a user logs in to Windows, gets a supervisor to launch the program with elevated privilege and then the user works with the program for an extended period. I need to know the standard user's name so that I can store their preferences. – TomT Dec 17 '15 at 22:16
-
I do have a workaround but it is inelegant. I could have users start a launcher program that would run without elevation, write the username to disk, and then launch the elevated program. The elevated program could then read the username from the file. – TomT Dec 17 '15 at 22:17
-
2You are doing this wrong. Use two processes. One running as the non admin user. The other elevated just to perform those tasks that require elevation. If the two processes need to communicate use IPC. – David Heffernan Dec 17 '15 at 22:49
-
1[ShellExecuteEx](https://msdn.microsoft.com/en-us/library/windows/desktop/bb762154.aspx) allows you to pass command line parameters to the elevated process. But David is right, you have gone for the wrong solution altogether. – IInspectable Dec 17 '15 at 23:09
-
1From the sounds of it, though, what you really want is a system service so that it can run with admin privilege without an administrator needing to explicitly launch it. – Harry Johnston Dec 17 '15 at 23:54