Reputation: 51
I am just starting out with VB.net and building simple applications to help me work better. I am creating a form application using Visual Studio Express VB 2008. In this form, there would be buttons to launch applications installed in the computer. Ideally, some applications require to launch as normal user and some as administrator. I would be providing an option for the user to enter their administrator credentials within that same form and would use that to launch the applications that require administrator access. Unfortunately, am not able to build the code due to this error: Value of type 'String' cannot be converted to 'System.Security.SecureString' Here is the code have written:
Private Sub cmd_button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_button.Click
Dim passwd As New System.Security.SecureString
Dim proc As New ProcessStartInfo
passwd = password_box.Text
passwd.Clear()
With Proc
.FileName = "cmd.exe"
.Username = username_box.Text
.Passwd = passwd
End With
Process.Start(proc)
End Sub
Hope to get some help here, had tried Googling and searching through so many forums and as well as on Stackoverflow, but got results to work on C#, VB.Net was not able to find, or maybe something was not going clear on me. Hope someone here can help.
Upvotes: 0
Views: 1630
Reputation: 27342
To run an application as Administrator you set the .Verb
property to "runas"
and the UseShellExecute
property to True
on the process like this:
Dim process As New Process()
process.StartInfo.FileName = "cmd.exe "
process.StartInfo.Verb = "runas"
process.StartInfo.UseShellExecute = True
process.Start()
This will prompt for credentials if the current user is not a member of the administrators group of give a UAC prompt if they are (and UAC is turned on).
You cannot give it credentials to use. This is by design so what you are trying to do will not work as you want it to.
Upvotes: 2