I am trying to open a cmd window as an admin but it never works. I can open a command window but it does not open as the admin.. Here is my code (VB.NET 2008)..

'This is in a module
Public strUserName, strPassword, strDomain As String
Public SecPassword As New Security.SecureString()
Public impersonater As New ProcessStartInfo()


'This is in the login form
Dim i As Integer

strUserName = Trim(txtUserName.Text)
strPassword = Trim(txtPassword.Text)
strDomain = Environment.UserDomainName.ToString

For i = 1 To Len(strPassword)
  SecPassword.AppendChar(Mid(strPassword, i, 1))
Next

'And finally the main form
Private Sub btnCMD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCMD.Click
        impersonater.UserName = strUserName
        impersonater.Password = SecPassword
        impersonater.Domain = strDomain
        impersonater.Arguments = "c:\"
        impersonater.UseShellExecute = False
        impersonater.FileName = "cmd"
        Process.Start(impersonater)
    End Sub

That was for C#. I know that they are similar but adding the verb = "runas" does not work..

current code:

'Startup form
Public Class frmStartup
    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Dim i As Integer

        ' Save user entered account information to associated strings
        strUserName = Trim(txtUserName.Text)
        strPassword = Trim(txtPassword.Text)
        strDomain = Environment.UserDomainName.ToString

        For i = 1 To Len(strPassword)
            SecPassword.AppendChar(Mid(strPassword, i, 1))
        Next

        ' Close startup form and show main application form
        Me.Hide()
        frmMain.ShowDialog()
    End Sub

    
'Main form
Private Sub btnCMD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCMD.Click
        impersonater.FileName = "cmd"
        Process.Start(impersonater)
        impersonater.UserName = strUserName
        impersonater.Password = SecPassword
        impersonater.Domain = strDomain
        impersonater.Arguments = "c:\"
        impersonater.UseShellExecute = False
        impersonater.Verb = "runas"
    End Sub

Has anyone done this before that can assist?

>Has anyone done this before that can assist?

Imports System.Security
Imports System.Diagnostics
Module Module1
    Sub Main()
        Dim secPass As New SecureString
        secPass.AppendChar("y")
        secPass.AppendChar("o")
        secPass.AppendChar("u")
        secPass.AppendChar("r")
        secPass.AppendChar("p")
        secPass.AppendChar("a")
        secPass.AppendChar("s")
        secPass.AppendChar("s")
        Process.Start("cmd", "Administrator", secPass, "domain")
    End Sub
End Module

Nevermind.. On a hunch I decided to test to see if it was logged in but not showing it and it was.. Thanks for your help.. It did not behave like it was supposed to, and was working before I even posted..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.