[英]Open Powershell and Change directory in VB.NET
I want my Windows application built with VB.NET to open powershell onclick of button event and change directory to C:\\ and not close window.我希望我用 VB.NET 构建的 Windows 应用程序打开 powershell onclick 按钮事件并将目录更改为 C:\\ 而不是关闭窗口。
Here is my code:这是我的代码:
Private Sub PowershellToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles PowershellToolStripMenuItem.Click
Process.Start("powershell")
End Sub
I tried to add "-wait"
after "powershell.exe"
but that causes an error.我试图在
"powershell.exe"
之后添加"-wait"
,但这会导致错误。 Anyone have an idea how I can go about this?任何人都知道我该怎么做?
Powershell is a command line executable. Powershell 是一个命令行可执行文件。 It will not attach a console normally, but if you execute it as the shell, then it should behave as you expect:
它不会正常附加控制台,但如果您将其作为 shell 执行,那么它的行为应该符合您的预期:
Process.Start(New ProcessStartInfo() With {.UseShellExecute = True, _
.FileName = "powershell", _
.WorkingDirectory = "C:\"})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.