使用不同的凭据从vb.net打开AD

时间:2017-09-14 02:04:14

标签: vb.net process active-directory passwords username

我找到了以下代码

    Dim p As New ProcessStartInfo With {
        .FileName = "c:\Windows\System32\dsa.msc",
        .Arguments = "/SAVECRED /user:DOMAIN\username"
    }


    ' Start the process
    Process.Start(p)

我希望能够传递以下提示输入用户名的cmd

c:\Windows\System32\runas.exe /SAVECRED /user:DOMAIN\username "c:\Windows\System32\mmc.exe c:\Windows\System32\dsa.msc"

通过打开应用程序,但没有传递用户名或提示输入密码,我无法弄清楚如何在争论中找出不同的信誉。

创意??

1 个答案:

答案 0 :(得分:0)

好的想出来 - 这是我用过的代码

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

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

    Dim passwordString As String
    passwordString = "..........."
    Dim password As SecureString = ConvertToSecureString(passwordString)


    ' New ProcessStartInfo created
    Dim p As New ProcessStartInfo

    ' Specify the location of the binary
    p.FileName = "mmc.exe"
    p.WorkingDirectory = "c:\Windows\System32\"
    ' Use these arguments for the process
    p.Arguments = "dsa.msc"
    p.Domain = "........"
    p.UserName = "......."
    p.Password = password
    p.UseShellExecute = False
    ' Start the process
    Process.Start(p)


End Sub