2017-09-14 39 views
0

J'ai trouvé le code suivantAD Ouverture de vb.net avec différents titres de compétence

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


    ' Start the process 
    Process.Start(p) 

Je veux être en mesure de passer le cmd suivant qui vous invite à entrer le nom d'utilisateur

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

qui fonctionne par l'ouverture l'application, mais ne passe pas le nom d'utilisateur ou invite pour le mot de passe, je ne peux pas comprendre comment forcer la crédibilité différente avec des arguments.

Des idées?

Répondre

0

Ok figured it out - voici le code i utilisé

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