Problem with Process.Start

alainb

New member
Joined
Jun 15, 2008
Messages
3
Programming Experience
Beginner
Hello Fellows,

I'm not new with VB6 but rather new on VB.Net.

I wanted to experiment with Process.Start; it works when I just do Process.Start("notepad.exe") but it doesn't work with vbc.exe as shown in the code below. I have even created a Debug.Print(CommandLine) instruction to copy and paste in cmd manually: it does work whereas it doesn't work from the VB.Net program :confused:

VB.NET:
Imports System.Diagnostics

Module Module1

    Sub Main()

        Dim CompilerPath As String
        Dim CompilerName As String
        Dim CommandLineCommand As String

        Dim SourceName As String
        Dim SourcePath As String
        Dim CommandLineParameter As String

        Dim CommandLine As String

        CompilerPath = "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727"
        CompilerName = "vbc.exe"
        SourcePath = Environment.CurrentDirectory()

        CommandLineCommand = Chr(34) + CompilerPath + "\" + CompilerName + Chr(34)

        Console.WriteLine("To compile with " + CommandLineCommand)
        Console.WriteLine("Enter the source name to compile in " + Chr(34) + SourcePath + Chr(34))
        SourceName = Console.ReadLine()
        CommandLineParameter = Chr(34) + SourcePath + "\" + SourceName + Chr(34)

        CommandLine = CommandLineCommand + " " + CommandLineParameter
        Debug.Print(CommandLine)

        Try
            Process.Start(CommandLine)
        Catch Exception As Exception
            'Console.WriteLine("Cannot find Compiler Path")
            Console.WriteLine(Exception.Message)
            Console.WriteLine(CommandLineParameter)

        End Try

        Console.ReadLine()
    End Sub

End Module
 
Either use Process.Start("filename", "arguments") or fill in ProcessStartInfo.
 
Back
Top