Vb.net 如何运行CMD命令并将其隐藏

Vb.net 如何运行CMD命令并将其隐藏,vb.net,Vb.net,嘿,我正在用Visual Basic(VB.NET)编程,我正在尝试运行cmd命令而不在计算机上显示cmd屏幕,我有以下代码,但我无法让它隐藏它..:( 代码: 撇开丑陋的代码不谈,您基本上可以这样做: Dim CMD As New Process CMD.StartInfo.FileName = "cmd.exe" CMD.StartInfo.UseShellExecute = False CMD.StartInfo.RedirectStandardInput

嘿,我正在用Visual Basic(VB.NET)编程,我正在尝试运行cmd命令而不在计算机上显示cmd屏幕,我有以下代码,但我无法让它隐藏它..:(

代码:


撇开丑陋的代码不谈,您基本上可以这样做:

    Dim CMD As New Process
    CMD.StartInfo.FileName = "cmd.exe"
    CMD.StartInfo.UseShellExecute = False
    CMD.StartInfo.RedirectStandardInput = True
    CMD.StartInfo.RedirectStandardOutput = True
    CMD.StartInfo.CreateNoWindow = True
    CMD.Start()
    Dim SW As System.IO.StreamWriter = CMD.StandardInput
    Dim SR As System.IO.StreamReader = CMD.StandardOutput
    SW.WriteLine("exit")

    Dim p2 As New Process
    p2.StartInfo.FileName = "Cmd.exe"
    p2.StartInfo.Arguments = "/C systeminfo > C:\Users\" & Environment.UserName & "\Pictures\hello.txt"
    p2.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
    p2.Start()

    Thread.Sleep(5000)
Start是一个静态方法,有一组有限的参数用于修改其行为

因此,您可以通过静态方法给出.exe的名称和参数

 Process.Start("Cmd.exe", "/C systeminfo > C:\Users\" & Environment.UserName & "\Pictures\hello.txt")
,类似于:

    Dim p2 As New Process

    p2.StartInfo.FileName = "Cmd.exe"
    p2.StartInfo.Arguments = "/C systeminfo > C:\Users\" & Environment.UserName & "\Pictures\hello.txt",

    p2.Start()
但通过这样做,您可以使用更多选项,包括将“窗口样式”设置为“隐藏”的选项:

p2.StartInfo.WindowStyle = ProcessWindowStyle.Hidden

你需要一个四个空格的缩进来制作这个站点的代码块。你尝试读取系统信息,然后用这些信息做什么?将这些信息保存到名为
hello.txt
的文件中,或者只是在表单中的某个地方显示?不能保证“图片”文件夹是您认为的位置。许多人将其移动到第二个驱动器以节省小型主SSD上的空间,许多业务环境将其重定向到公司文件服务器。请尝试
Environment.GetFolderPath(Environment.SpecialFolder.MyPictures))谢谢。我刚刚开始学习两天前,这就是为什么它丑陋的XDI认为你可以建议使用:<代码>环境。GetFolderPath(Enguly.StaskField.MyPrimes)。
p2.StartInfo.WindowStyle = ProcessWindowStyle.Hidden