ComputersUnlimited
IS-IT--Management
The program I am working on executes another program that requires admin rights. In attempts to get this working I have the following code
When this line executes
an exception is thrown. (See Image)
If I comment out the UserName and Password lines the process starts but I am prompted to allow elevated rights, which is what I don't want as this program is intended to run unattended.
Am I going about this the proper way? Is there an easier or better way? This is the method almost every site I found says to use. I did see one site that said that secure password should not be use as it did not deliver what was promised, keeping the password or other sensitive data secure, but the article did not provide an alternative.
Any assistance is greatly appreciated!
Code:
Dim MyProcess As System.Diagnostics.Process = Nothing
Dim MyProcessStartInfo As System.Diagnostics.ProcessStartInfo = New System.Diagnostics.ProcessStartInfo()
Try
Dim UserAccount As String = "UserName"
Dim Password As SecureString = New SecureString()
Password.AppendChar("m")
Password.AppendChar("y")
Password.AppendChar("P")
Password.AppendChar("a")
Password.AppendChar("s")
Password.AppendChar("s")
Password.AppendChar("w")
Password.AppendChar("o")
Password.AppendChar("e")
Password.AppendChar("g")
Password.AppendChar("r")
Password.AppendChar("d")
Password.MakeReadOnly()
With MyProcessStartInfo
.FileName = Path
.Arguments = Args
.Verb = "runas"
.UseShellExecute = True
.UserName = UserAccount
.Password = Password
.WindowStyle = ProcessWindowStyle.Normal
End With
MyProcess = Process.Start(MyProcessStartInfo)
'Wait until the process passes back an exit code
MyProcess.WaitForExit()
'Free resources associated with this process
MyProcess.Close()
'Password.
Password.Dispose()
Password.Clear()
Catch ex As Exception
MsgBox(ex.Message, "Error") 'for testing and trouble shooting purposes only
End Try
When this line executes
Code:
MyProcess = Process.Start(MyProcessStartInfo)
If I comment out the UserName and Password lines the process starts but I am prompted to allow elevated rights, which is what I don't want as this program is intended to run unattended.
Am I going about this the proper way? Is there an easier or better way? This is the method almost every site I found says to use. I did see one site that said that secure password should not be use as it did not deliver what was promised, keeping the password or other sensitive data secure, but the article did not provide an alternative.
Any assistance is greatly appreciated!