Process.Start() is not working for VB Forms application

~OSD~ 2,126 Reputation points
2020-12-09T12:26:07.563+00:00

Hi,

I am using command line syntax and saving output as text file using ">" switch to current user profile as:

wmic product get Description, InstallDate, Version > C:\Users\%UserName%\Documents\AppList.txt

When I use the same command didn't worked in VB Process.Start () as:

Process.Start("wmic product get Description, InstallDate, Version > C:\Users\%UserName%\Documents\AppList.txt")

And even the following way but still I have issues.

Dim wmicProd As New ProcessStartInfo("WMIC Product")
        wmicProd.Arguments = "get Description, InstallDate, Version > C:\Users\%UserName%\Documents\AppList.txt"
        Process.Start(wmicProd)
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,578 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 81,741 Reputation points
    2020-12-09T13:56:38.933+00:00

    This test works for me =>

        Dim sUserPath As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
        sUserPath += "\AppList.txt"
        Dim proc = New Process With {
            .StartInfo = New ProcessStartInfo With {
            .FileName = "wmic.exe",
            .Arguments = "/output:" + sUserPath + " product get Description, InstallDate, Version",
            .UseShellExecute = False,
            .RedirectStandardError = True,
            .CreateNoWindow = True
        }
        }
        proc.Start()
        proc.WaitForExit()
        Dim sStdErr As String = proc.StandardError.ReadToEnd()
        Console.WriteLine("Exit code : {0}", proc.ExitCode)
        Console.WriteLine("StdErr : {0}", sStdErr)
    
    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. RLWA32 40,571 Reputation points
    2020-12-09T13:23:03.703+00:00

    I/O redirection using ">" is done by the command processor. So have cmd.exe run your command.