command name can be APP_COMMAND_NAME as const

            Friend Module Program

Private CurrentString As String = String.Empty
Public Const APP_RUNNING As String = "Running"
Public Const APP_TITLE As String = "Console"
Public State_Output As String
Public State_List As List(Of String) = New List(Of String)
Private commandlist_ As Dictionary(Of String, Action)

Private State As String = String.Empty

Public APP_USER As String

Event Command_Run()

Sub Main()
    APP_USER = String.Empty
    Program.State_Output = "App is " & State.ToString & CStr(Program.APP_RUNNING)
    'Program.State_List = New List(Of String)

    Console.Title = APP_TITLE
    AddHandler Command_Run, AddressOf RunCommand
    Program.commandlist_ = New Dictionary(Of String, Action)
    Program.commandlist_.Add("Notepad", New Action(AddressOf Notepad))

    Console.Write(">>")
    'Program.CurrentString = Console.ReadLine()
    ' Console.WriteLine(CurrentString)

    State = Program.APP_RUNNING

    While State = Program.APP_RUNNING
        Console.Write("?")
        'Program.CurrentString = Program.State_Output
        Console.WriteLine(Program.CurrentString)
        'Program.CurrentString = String.Empty = Console.ReadLine
        RaiseEvent Command_Run()
    End While

    'Call Main()

End Sub
Private Sub Notepad()
    Dim proc As Process
    proc = Program.RetrieveProcessStatus(Process.Start("Notepad.exe"))
    Program.APP_USER = proc.MachineName
    Console.WriteLine("Running:" & "With" & Program.APP_USER & "Process:" & proc.ToString)
End Sub
Private Sub LoadStateList()

    If Not IsNothing(Program.State_List) Then
        Console.WriteLine("App State is loaded")
        Program.State_List = Nothing
        Program.State_List = New List(Of String)
        Program.State_List.Add(APP_RUNNING)
        Program.State_List.Add(Program.State_Output)
    Else
        Dim nullcept As New Exception("Cannot load null list")
        Console.WriteLine(nullcept.Message)
        Exit Sub
    End If

End Sub

Private Sub RunCommand()
    Program.LoadStateList()

    Select Case Program.State_List(0) = Program.APP_RUNNING
        Case True
            Console.WriteLine("Ready to run command")

        Case False
            Console.WriteLine("Command Run Failed")
    End Select

    Console.WriteLine("Enter CMD Name.")
    Program.CurrentString = Console.ReadLine

    For Each a As Action In Program.commandlist_.Values
        If Not IsNothing(Program.commandlist_(Program.CurrentString)) Then

            commandlist_(Program.CurrentString).Invoke()

        End If
    Next
End Sub

Function RetrieveProcessStatus(ByVal p As Process)
    Return p
End Function

This looks oddly similar to what we read at https://msdn.microsoft.com/en-us/library/system.diagnostics.process.machinename(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1

But today's SECURITY MODELS should cause this to fail. That's vaguely hinted at the link with this line:

for full trust for the immediate caller. This member cannot be used by partially trusted code.

So my bet is this used to work, or only works on a stock clean OS.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.