Results 1 to 3 of 3

Thread: [2008] Need help with Console Process

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2008
    Posts
    96

    [2008] Need help with Console Process

    I want to start osmon.exe with diffrent parameters, eg. Default, Osmon2, Osmon3, Osmon4 and Osmon5.

    After Default has started it must wait 10 seconds, after osmon5 has started it must wait 15 seonds.
    Then is must write the PID# to txt file.

    I have the code, but when I run it, it only shows the console for 1 second, and then nothing is happening after that.

    Code:
    Imports System.Diagnostics
    Imports System.Timers
    Imports System.IO
    Imports System
    
    
    Module Module1
    
        Private Osmon_Delay As New Timer(10000)
        'Private Dop_Delay As New Timer(200000)
        'Private Proxy_Delay As New Timer(15000)
    
        Private LaunchCounter As Integer = 1
    
        Private Osmon_Default As New Process
        Private Osmon_Osmon2 As New Process
        Private Osmon_Osmon3 As New Process
        Private Osmon_Osmon4 As New Process
        Private Osmon_Osmon5 As New Process
    
        Sub Main()
            AddHandler Osmon_Delay.Elapsed, AddressOf myElapsed
            Osmon_Delay.Start()
        End Sub
    
        Private Sub myElapsed(ByVal source As Object, ByVal e As ElapsedEventArgs)
            ' Static LaunchCounter As Integer = 1
    
            Select Case LaunchCounter
                ' ''Case 1
                ' ''    Dop_Delay.start()
                ' ''    Process.Start("e:\osb5.0\osb\bin\hrncr.exe")
                ' ''    Dop_Delay.Stop()
    
                Case 1
                    Dim msg As String = ""
                    '  This is where you save the DEFAULT name and process ID to a file 
                    Osmon_Default.StartInfo.FileName = "E:\OSB5.0\OSB\BIN\osmon.exe"
                    Osmon_Default.StartInfo.Arguments = "NAME=DEFAULT"
                    Osmon_Default.Start()
                    Console.WriteLine("DEFAULT PID = " & Osmon_Default.Id)
    
                    msg = msg & "Osmon 1 PID#"
                    msg = msg & Osmon_Default.Id
                    msg = msg & "  "
                    msg = msg & ControlChars.NewLine
                    IO.File.AppendAllText("c:\Segment\PIDNum.txt", msg)
    
    
                Case 2
                    Dim msg As String = ""
                    '  This is where you save the OSMON2 name and process ID to a file  
                    Osmon_Osmon2.StartInfo.FileName = "E:\OSB5.0\OSB\BIN\osmon.exe"
                    Osmon_Osmon2.StartInfo.Arguments = "NAME=OSMON2"
                    Osmon_Osmon2.Start()
                    Console.WriteLine("OSMON2 PID = " & Osmon_Osmon2.Id)
    
                    msg = msg & "Osmon 2 PID#"
                    msg = msg & Osmon_Osmon2.Id
                    msg = msg & "  "
                    msg = msg & ControlChars.NewLine
                    IO.File.AppendAllText("c:\Segment\PIDNum.txt", msg)
    
                Case 3
                    Dim msg As String = ""
                    '  This is where you save the OSMON3 name and process ID to a file   
                    Osmon_Osmon3.StartInfo.FileName = "E:\OSB5.0\OSB\BIN\osmon.exe"
                    Osmon_Osmon3.StartInfo.Arguments = "NAME=OSMON3"
                    Osmon_Osmon3.Start()
                    Console.WriteLine("OSMON3 PID = " & Osmon_Osmon3.Id)
                    msg = msg & "Osmon 3 PID#"
    
                    msg = msg & Osmon_Osmon3.Id
                    msg = msg & "  "
                    msg = msg & ControlChars.NewLine
                    IO.File.AppendAllText("c:\Segment\PIDNum.txt", msg)
    
                Case 4
                    Dim msg As String = ""
                    '  This is where you save the OSMON4 name and process ID to a file   
                    Osmon_Osmon4.StartInfo.FileName = "E:\OSB5.0\OSB\BIN\osmon.exe"
                    Osmon_Osmon4.StartInfo.Arguments = "NAME=OSMON4"
                    Osmon_Osmon4.Start()
                    Console.WriteLine("OSMON4 PID = " & Osmon_Osmon4.Id)
    
                    msg = msg & "Osmon 4 PID#"
                    msg = msg & Osmon_Osmon4.Id
                    msg = msg & "  "
                    msg = msg & ControlChars.NewLine
                    IO.File.AppendAllText("c:\Segment\PIDNum.txt", msg)
    
                Case 5
                    Dim msg As String = ""
                    '  This is where you save the OSMON5 name and process ID to a file   
                    Osmon_Osmon5.StartInfo.FileName = "E:\OSB5.0\OSB\BIN\osmon.exe"
                    Osmon_Osmon5.StartInfo.Arguments = "NAME=OSMON5"
                    Osmon_Osmon5.Start()
    
                    msg = msg & "Osmon 5 PID#"
                    msg = msg & Osmon_Osmon5.Id
                    msg = msg & "  "
                    msg = msg & ControlChars.NewLine
                    IO.File.AppendAllText("c:\Segment\PIDNum.txt", msg)
                    Osmon_Delay.Stop()
            End Select
    
            LaunchCounter += 1
        End Sub
    End Module
    Last edited by hendrikbez; Jan 27th, 2009 at 12:10 AM. Reason: No proper heading

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Need help with Console Process

    Your Main method ends immediately after you Start the Timer and your application exits when your Main method ends, therefore your application exits immediately after your Start the Timer.

    Get rid of the Timer and use Thread.Sleep to create a delay between each process starting.

    Also, the way you're starting your processes is cumbersome given what you need to do. If all you need to do is to specify a file to execute and a commandline parameter then all you need is one line of code:
    vb.net Code:
    1. Process.Start("file name here", "commandline args here")
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2008
    Posts
    96

    Re: [2008] Need help with Console Process

    I am bussy with remote, I did have in in like this on the server project:

    Code:
    Case "STARTOSMON1"
                    Shell("E:\osb5.0\osb\bin\OSMON1.bat")
                    'SpecialProcess("e:\osb5.0\osb\bin\osmon.exe", "DEFAULT") 'Start Osmon 1
                Case "STARTOSMON2"
                    Shell("E:\osb5.0\osb\bin\OSMON2.bat")
    I did try it witout the bat file like you can see the markout ones up top. but then I cannot kill them one by one. here is some code on how I am trying to stop it.

    Code:
    Case "STOPOSMON1"
                    'Shell("C:\Segment\CloseOsmon1.bat")
                    KillOsmon("osmon.exe", "DEFAULT") 'Stop Osmon 1
                Case "STOPOSMON2"
                    'Shell("C:\Segment\CloseOsmon2.bat")
                    KillOsmon("osmon.exe", "OSMON2") 'Stop Osmon 2

    and here is my process.

    Code:
     Private Sub KillOsmon(ByVal processname As String, ByVal domain As String)
            Try
                Dim searcher As New ManagementObjectSearcher("root\CIMV2", "SELECT * FROM Win32_Process")
                For Each queryObj As ManagementObject In searcher.Get()
                    If (queryObj("NAME").ToString = processname) Then
                        Dim thisProcess As Process = Process.GetProcessById(DirectCast(queryObj("ProcessId"), Integer))
                        'Dim thisProcess As Process = Process.GetProcessById(queryObj("ProcessId"))
                        'thisProcess = Process.GetProcessById(queryObj("ProcessId"))
                        thisProcess.Kill()
                    End If
                Next
            Catch err As ManagementException
                MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
            End Try
    The only problem that I have is taht I cannot kill the process of the osmons.

    So now I am trying to use console now, to see if it wil work

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width