I have a simple WinForms .Net 4.8.1 launcher application that works perfectly if everything is local, but fails with invalid directory if the files are stored on a share. The MainForm has two text boxes for inputting credentials and 2 buttons as well as some images and labels... The issue is in the following code:
private void Ok_Click(object sender, EventArgs e)
{
ProcessStartInfo psi = new ProcessStartInfo("AdminApp.exe")
{
Verb="runas",
UserName=userName.Text.Trim(),
PasswordInClearText=password.Text.Trim(),
LoadUserProfile=true,
Domain="DOMAIN",
ErrorDialog=true,
UseShellExecute=false
};
Process.Start(psi);
Application.Exit();
}
The app needs to run with Admin Credentials. We use Avecto and when using that to specify admin credentials it just adds an admin token to the current user no matter what valid credentials are supplied (if logged on user is PlainUser, and we supply credentials for AdminUser, the app gets executed as PlainUser with an admin token instead of AdminUser and we need to execute it as AdminUser). The above code launches in the correct user context with Admin token when run from the local drive but fails if run from a share with invalid directory. I have tried supplying the absolute path to the executable, setting the WorkingDirectory, setting both, and setting a relative path as well...
The application needs Admin rights to backup and restore files from multiple profiles as well as settings in HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER (this is for a specific application, not a backup/restore for the machine/profile).
We are trying to eliminate Guest access to SMB shares on NAS devices and we are trying to avoid using a single account embedded in the application so that an Admin from Office X does not have access to files in Office Y by using security groups.
Any ideas?
I was able to resolve by creating a temp CMD file locally and launching that to launch the app, then I delete the CMD file.