首页 > 解决方案 > Open CMD and run command from VB.net

问题描述

Got so far, but I'm stuck now. Need to from an VB app, change windows registry. CMD window opens in admin mode but no argument is passed. Im guessing argument is not the right trick ...but also tried making one string only cmd.exe red add ... and no argument.

My problem is that the CMD window opens but the REG ADD ... Is not passed

Private Sub StartProcess(ByVal app As String, ByVal arg As String, ByVal verb As 
String)
    Dim p As New ProcessStartInfo
    p.FileName = app                                                                        
    p.Arguments = arg
    p.Verb = verb                                                                           
    Process.Start(p)
End Sub

Private Sub explorer_btn_Click(sender As Object, e As EventArgs) Handles 
explorer_btn.Click
call StartProcess("cmd", "reg add ""HKey_Local_Machine\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"" /v Shell /t reg_sz /d ""explorer.exe"" "", "runas")
End Sub

标签: .netvb.netcmd

解决方案


看起来我在 REG ADD 命令之前缺少 /C 或 /K 。从 cmd /? /C 执行字符串指定的命令,然后终止。/K 执行字符串指定的命令,但保留。


推荐阅读