Monday, September 20, 2010

Start a Process as a Different User - developer Fusion

Start a Process as a Different User - developer Fusion: "Function ConvertToSecureString(ByVal str As String)

Another usefull code snippet
Credits go to Peter Rekdal Sunde at developerfusion.com

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

No comments:

Post a Comment