Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- REM Three files follow
- REM ListConsole.bat
- REM This file compiles ListConsole.vb to ListConsole.exe using the system VB.NET compiler.
- REM ListConsole.exe list the processes in the console and returns an errorlevel saying how many.
- C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc "%~dp0\ListConsole.vb" /out:"%~dp0\ListConsole.exe" /target:exe
- --------------------------------------------------
- REM ListConsoleTest.bat
- REM Shows ListConsole.exe in action.
- "%~dp0\ListConsole.exe"
- Echo Number of Processes is %errorlevel%
- pause
- --------------------------------------------------
- Sample Output
- Level = 2
- PID : 6380 Command line : C:\Windows\system32\cmd.exe /c ""C:\Users\User\Desktop\Bat+Vbs\ListConsole\ListConsole
- Test.bat" "
- PID : 4320 Command line : cmd /c "C:\Users\User\Desktop\Bat+Vbs\ListConsole\ListConsole.exe"
- --------------------------------------------------
- 'ListConsole.vb
- imports System.Runtime.InteropServices
- Public Module MyApplication
- Public Declare Function GetConsoleProcessList Lib "Kernel32" (ByRef ProcessList as Integer, ByVal Count as Integer) As Integer
- Public Sub Main ()
- Dim ProcessList(0 To 9) As Integer
- Dim Count As Integer
- Dim Ret As Integer
- Dim x as Integer
- Dim ColItems as Object
- Dim objWMIService As Object
- objWMIService = GetObject("winmgmts:\\.\root\cimv2")
- Count = 10
- 'subtract one to account for this program
- Ret = GetConsoleProcessList(ProcessList(0), 10) - 1
- Console.Writeline("Level = " & Ret)
- For x = Ret to 1 step -1
- colItems = objWMIService.ExecQuery("Select * From Win32_Process where ProcessID=" & ProcessList(x))
- For Each objItem in colItems
- Console.writeline("PID : " & objItem.ProcessID & " Command line : " & objItem.CommandLine)
- Next
- Next
- Environment.ExitCode = Ret
- End Sub
- End Module
Advertisement
Add Comment
Please, Sign In to add comment