.net - 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
解决方案
看起来我在 REG ADD 命令之前缺少 /C 或 /K 。从 cmd /? /C 执行字符串指定的命令,然后终止。/K 执行字符串指定的命令,但保留。
推荐阅读
- apache-camel - 为骆驼 json-validator 组件设置自定义错误消息
- python - DataFrame:列的累积总和,直到达到条件并在新列中返回总和
- spring - Spring security OAuth2 令牌自省
- python - 选择 Python 解释器在 VScode 中不起作用
- scala - Scala 中避免 if-else 阶梯的数据帧设计规则引擎
- javascript - 如何获取动态表数据?
- css - 计算字体大小时的 CSS 验证解析错误
- jenkins - 我如何在 jenkins 中修复这个 kubernetes 插件
- numpy - 以元组为键向量化字典中的数组
- animation - 如何在触摸设备上滚动画布?(三.js)