Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to list all running processes 1

Status
Not open for further replies.

Trevil

Programmer
Jun 19, 2003
459
US
Does anyone have code that I can insert into VB6 to list all processes?

I have a VB6 application running on 70 different server workstations around the world. 95% of the time, the application will run in about 10 minutes, but I have noticed that sometimes the application is running for as many as 8 or 10 hours. The job runs from a scheduled task in the early morning (i.e. 5AM) before users come to work.

I have a log file that tells me what actions are being taken internally, and when there is a long delay, it is always while accessing a MS Access 2000 database that is located on the server. Normally it takes 1/10 th of a second to process 30 records, but when it's bad, it may take 2 minutes.

Since the job runs unattended and the problem is so random, I can't ask someone to sit and watch.

My first idea is to be able to list all processes that are running, but I need some code that will do that. I tried the code from another thread (Set objWMIService = GetObject...) but it didn't run on the server.

Thank you for any suggestions!



"Have a great day today and a better day tomorrow!
 
You can run plist.exe via the Shell command. You can download plist from sysinternals.com. It may not work on the 9x versions of Windows.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Thank you Chip.
I found the program you mentioned, but I am not permitted to install any executable program that comes from a third party without getting grey hair from the government approval process.

Any other ideas?

"Have a great day today and a better day tomorrow!
 
See thread222-837273. You need slight modification in the code to get a list of all running processes.
 
Here is a shorter version if you are running W2K or above...

Code:
    Dim wmgts As Object
    Dim Proc As Object

    
    Set wmgts = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\localhost\root\cimv2")
    For Each Proc In wmgts.instancesof("Win32_Process")
        Debug.Print Proc.Name
    Next
 
Thank you Hypetia -- I modified the code to list all PID's and their names, now need to test overseas.

Thank you bjd4jc, but I had tried to use that type of code, and although it ran fine on my W2K workstation, it failed overseas on the server with "Error: -2147221020 Automation error Invalid syntax" when it tried to execute that first "Set". I wasn't sure if their configuration lacks some software or if it was due to some security restriction.

Thank you both. Will update this as soon as I can test!

"Have a great day today and a better day tomorrow!
 
I'm just curious- not really a solution
So you say 30 records and 8-10 hours? A'm I assuming this incorrectly? Anyway my 2 cents- I like access and still use it for my personal programs.. but with hard hitting programs I gave it up and kicked it to the curb with no remorse. But maybe yours isn't high demand.. anyway I went with MySql and I love it. I noticed slow preformance when calling my history tables with say 500,000 records. I then learned about Indexes which cut a lot of time down. Maybe most people know about indexes and fully understand database function but i never went to school so I do everything the hard way. Anyway what are the sizes of the database tables? It was hard to get away from access but i'de never go back, mostly with multiple stations involved.

Tom
 
Thanks TLowder. Yes, 8-10 hours! But it is completely random and appears to have started within the past 10 days or so. In the 70 countries, my program runs over 2,000 times a month (since March), and there have been about 15 times that the slow down occurs. I'm guessing some other process may be the culprit (i.e. some new backup job?), so before trying to analyze individual I/O to the database, I wanted to see if I could find some similar job running when there is the slow down.

And YES, we will be replacing the application with SQL Server, etc. late this year.
Thank you again!

"Have a great day today and a better day tomorrow!
 
OK, the modified code (see below) has been tested and will list the processes. After analyzing the log files I will let everyone know if I can isolate the 'guilty party' or if I still need help.

Thank You!

'Code to list all processes (Note: 'Write_To_Log' is a subroutine that writes text to a log file)
Option Explicit

Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessId As Long) As Long
Private Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)
Const PROCESS_TERMINATE = (&H1)
Const TH32CS_SNAPPROCESS = 2
Const MAX_PATH = 260
Private Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * MAX_PATH
End Type
Function GetProcessList() As Long
Dim hSnapShot As Long
Dim pe32 As PROCESSENTRY32
Dim i As Integer
Dim strProcesssName As String
Dim PID As Long

Write_To_Log "", True
hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, ByVal 0)
pe32.dwSize = Len(pe32)
ProcessFirst hSnapShot, pe32
Do
i = InStr(1, pe32.szExeFile, vbNullChar, vbTextCompare)
PID = pe32.th32ProcessID
strProcesssName = Left(pe32.szExeFile, i)
Write_To_Log PID & vbTab & strProcesssName
Loop While ProcessNext(hSnapShot, pe32)
CloseHandle hSnapShot
Write_To_Log "", True
End Function


"Have a great day today and a better day tomorrow!
 
WHEW! As suspected, it was not my program causing the 10+ hour delay. Seems that Norton LiveUpdate downloaded a "faulty" update that caused the server to chew up 100% of the processor.

Thanks to all that helped (I did get the code to list all processes to run, but only on our XP servers. Seems we must not have "CreateToolhelp32Snapshot" on the Win-2K servers).

"Have a great day today and a better day tomorrow!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top