|
-
Nov 15th, 2000, 04:24 PM
#1
Thread Starter
Hyperactive Member
I want to make a small program, and its only purpose is to show a list of running tasks (all tasks, not just the ones shown in the task list) ie including all services, in VB. Does anyone have a link or some code, to help me along this path?
Any help would be appreciated.
BW
-
Nov 15th, 2000, 04:47 PM
#2
Frenzied Member
Code:
Private Declare Function GetWindow Lib "user32" _
(ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowText Lib "user32" _
Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal _
lpString As String, ByVal cch As Long) As Long
Const GW_HWNDFIRST = 0
Const GW_HWNDNEXT = 2
Private Sub Command1_Click()
Dim CurrWnd As Long
Dim Length As Long
Dim TaskName As String
Dim Parent As Long
List1.Clear 'add a listbox
CurrWnd = GetWindow(Form1.hwnd, GW_HWNDFIRST)
Do While CurrWnd <> 0
TaskName = Space(255)
Length = GetWindowText(CurrWnd, TaskName, 255)
If Length > 0 Then
List1.AddItem TaskName
End If
CurrWnd = GetWindow(CurrWnd, GW_HWNDNEXT)
Loop
End Sub
-
Nov 15th, 2000, 04:51 PM
#3
_______
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Nov 15th, 2000, 05:15 PM
#4
Thread Starter
Hyperactive Member
it sure does. but..
can i go a step further and show the associated exe files for each item shown?
Is that possible? Thats exactly what i wanted in the code above, but i want to also relate each item to the exe or dll it comes from. Sorta like what MSInfo32 does.
BW 
PS Thanks guys for the quick replies.
-
Nov 16th, 2000, 04:01 AM
#5
transcendental analytic
Why not enumarating the processes instead?
Code:
Public Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Public Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Public Declare Function CloseHandle Lib "Kernel32.dll" (ByVal Handle As Long) As Long
Public Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
Public Declare Function EnumProcesses Lib "psapi.dll" (ByRef lpidProcess As Long, ByVal cb As Long, ByRef cbNeeded As Long) As Long
Public Declare Function GetModuleFileNameExA Lib "psapi.dll" (ByVal hProcess As Long, ByVal hModule As Long, ByVal ModuleName As String, ByVal nSize As Long) As Long
Public Declare Function EnumProcessModules Lib "psapi.dll" (ByVal hProcess As Long, ByRef lphModule As Long, ByVal cb As Long, ByRef cbNeeded As Long) As Long
Public Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
Public Declare Function GetVersionExA Lib "kernel32" (lpVersionInformation As OSVERSIONINFO) As Integer
Public Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long ' This process
th32DefaultHeapID As Long
th32ModuleID As Long ' Associated exe
cntThreads As Long
th32ParentProcessID As Long ' This process's parent process
pcPriClassBase As Long ' Base priority of process threads
dwFlags As Long
szExeFile As String * 260 ' MAX_PATH
End Type
Public Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long '1 = Windows 95.
'2 = Windows NT
szCSDVersion As String * 128
End Type
Public Const PROCESS_QUERY_INFORMATION = 1024
Public Const PROCESS_VM_READ = 16
Public Const MAX_PATH = 260
Public Const STANDARD_RIGHTS_REQUIRED = &HF0000
Public Const SYNCHRONIZE = &H100000
'STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF
Public Const PROCESS_ALL_ACCESS = &H1F0FFF
Public Const TH32CS_SNAPPROCESS = &H2&
Public Const hNull = 0
Function StrZToStr(s As String) As String
StrZToStr = Left$(s, Len(s) - 1)
End Function
Public Function getVersion() As Long
Dim osinfo As OSVERSIONINFO
Dim retvalue As Integer
osinfo.dwOSVersionInfoSize = 148
osinfo.szCSDVersion = Space$(128)
retvalue = GetVersionExA(osinfo)
getVersion = osinfo.dwPlatformId
End Function
Function Processes() As String()
Dim Arr$(): ReDim Arr(0)
Select Case getVersion()
Case 1 'Windows 95/98
Dim f&, sname$, hSnap&, proc As PROCESSENTRY32
hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
If hSnap = hNull Then Exit Function
proc.dwSize = Len(proc)
' Iterate through the processes
f = Process32First(hSnap, proc)
Do While f
Arr(UBound(Arr)) = StrZToStr(proc.szExeFile)
ReDim Preserve Arr(UBound(Arr) + 1)
f = Process32Next(hSnap, proc)
Loop
Case 2 'Windows NT
Dim cb&, cbNeeded&, NumElements&, ProcessIDs&(), cbNeeded2&, NumElements2&, Modules&(1 To 200), lRet&, ModuleName$, nSize&, hProcess&, i&
'Get the array containing the process id's for each process object
cb = 8
cbNeeded = 96
Do While cb <= cbNeeded
cb = cb * 2
ReDim ProcessIDs(cb / 4) As Long
lRet = EnumProcesses(ProcessIDs(1), cb, cbNeeded)
Loop
NumElements = cbNeeded / 4
For i = 1 To NumElements
'Get a handle to the Process
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ, 0, ProcessIDs(i))
'Got a Process handle
If hProcess <> 0 Then
'Get an array of the module handles for the specified process
lRet = EnumProcessModules(hProcess, Modules(1), 200, cbNeeded2)
'If the Module Array is retrieved, Get the ModuleFileName
If lRet <> 0 Then
ModuleName = Space(MAX_PATH)
nSize = 500
lRet = GetModuleFileNameExA(hProcess, Modules(1), ModuleName, nSize)
Arr(UBound(Arr)) = Left(ModuleName, lRet)
ReDim Preserve Arr(UBound(Arr) + 1)
End If
End If 'Close the handle to the process
lRet = CloseHandle(hProcess)
Next
End Select
ReDim Preserve Arr(UBound(Arr) - 1)
Processes = Arr
End Function
'usage:
'place a commandbutton and a listbox on the form:
Private Sub Command1_Click()
Dim n
For Each n In Processes
List1.AddItem n
Next n
End Sub
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 16th, 2000, 02:18 PM
#6
Thread Starter
Hyperactive Member
Excellent
That was just what i was after... Thanks heaps for that kedaman. And you other guys..
Its all good now.
BW 
PS just a thought, is it possible to get the company name and comments etc of a dll or exe file (like when you go to the properties of exe files, and it has all the details).
If you could just point me in the right direction to add that to it? I'm just trying to make my little program look more professional so its not urgent, if you could just suggest some apis or something to do that... cheers.
[Edited by But_Why on 11-16-2000 at 02:22 PM]
-
Nov 16th, 2000, 03:28 PM
#7
Thread Starter
Hyperactive Member
Just an Update
I have got the file version working sort of and product version working, again sort of. And File Type.
I am unsure of the File OS, Companyname, productname, comments, Internal name, Language and original filename. I know not all of these are entered in all files, but does anyone have any idea how to get these? And maybe a better way to get file version and product version? I tried using GetFileVersionInfo, but i don't think i am using it right.
Any Ideas?
BW
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|