Start a Process as a Different User

To use this code please create a new module or add it to your existing project.

Function ConvertToSecureString(ByVal str As String)
        Dim password As New SecureString
        For Each c As Char In str.ToCharArray
            password.AppendChar(c)
        Next
        Return password
End Function
Sub Main()
       dim username as string = "Administrator"
       dim password as SecureString = ConvertToSecureString("my password")
       dim domain as string = Nothing
       dim filename as string = "notepad.exe" ' %SYSTEMROOT%\system32
        Try
            System.Diagnostics.Process.Start(filename,username, password, domain)
        Catch ex As Win32Exception
            MessageBox.Show("Wrong username or password.", _
"Error logging in as administrator", MessageBoxButtons.OK, _
 MessageBoxIcon.Error)
        End Try
End Sub

You might also like...

Comments

Peter Rekdal Sunde

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match” - Bill Bryson