0

I have a program that I need to run with administrative privileges but start a process as the user. If I use environment.username I get the administrator but I need it to be the local user. Any ideas on how to call a process as the user signed in, not as the administrator?

Dim proc As New System.Diagnostics.Process()
proc = Process.Start("Avaya 7.0.exe", "")
  • 1
    Change the program so it no longer needs administrator access. One way to do this is the break up the program over multiple exe files, so the sections that may still need administrator access can run elevated for just those things. If you don't know what areas those are, you haven't done enough work yet to justify asking for administrator access in the first place. – Joel Coehoorn Oct 08 '19 at 21:32
  • 1
    Possible duplicate of [How to Start a Process Unelevated](https://stackoverflow.com/questions/17765568/how-to-start-a-process-unelevated) – GSerg Oct 08 '19 at 22:13
  • [How can I launch an unelevated process from my elevated process, redux](https://devblogs.microsoft.com/oldnewthing/20190425-00/?p=102443) – GSerg Oct 08 '19 at 22:17

1 Answers1

0

If you can securely save in your program username/password/domain of the user in witch context you want to launch the process you can use the Process.Start variant that accept, other than the filename to launch, the login data of the user in witch context to launch the process:

Public Shared Function Start (fileName As String, arguments As String, userName As String, password As SecureString, domain As String) As Process

In your code it will be something like:

Dim proc As New System.Diagnostics.Process()
Dim SS As New Security.SecureString
For Each C As Char In "MyPassword"
    SS.AppendChar(C)
Next

proc = Process.Start("Avaya 7.0.exe", "", "NonAdminUsername", SS, "MyDomain")

Check Process.Start documentation for more info:

  • 1
    Do not store usernames and passwords inside your code. Store them in environment variables and read from those. There's plenty of information available online about reading from environment variables. – Richard Barker Oct 08 '19 at 22:19