-
Sep 4th, 2012, 07:34 AM
#1
Thread Starter
Hyperactive Member
Check if a process is running on Win7 64bit
I have a vb6 function that determines if a process is running. This worked on 32bit systems, but it is not working 64bit Win7. How can I check if a process is running on a 64bit OS?
Thanks!
Brian
-
Sep 4th, 2012, 07:43 AM
#2
Re: Check if a process is running on Win7 64bit
-
Sep 4th, 2012, 07:59 AM
#3
Thread Starter
Hyperactive Member
Re: Check if a process is running on Win7 64bit
Here is the code I have...
Public Function GetProcesses(ByVal EXEName As String) As Boolean
Dim booResult As Boolean
Dim lngLength As Long
Dim lngProcessID As Long
Dim strProcessName As String
Dim lngSnapHwnd As Long
Dim udtProcEntry As PROCESSENTRY32
Dim lngCBSize As Long 'Specifies the size, In bytes, of the lpidProcess array
Dim lngCBSizeReturned As Long 'Receives the number of bytes returned
Dim lngNumElements As Long
Dim lngProcessIDs() As Long
Dim lngCBSize2 As Long
Dim lngModules(1 To 200) As Long
Dim lngReturn As Long
Dim strModuleName As String
Dim lngSize As Long
Dim lngHwndProcess As Long
Dim lngLoop As Long
Dim b As Long
Dim c As Long
Dim e As Long
Dim d As Long
Dim pmc As PROCESS_MEMORY_COUNTERS
Dim lret As Long
Dim strProcName2 As String
Dim strProcName As String
Dim MyPos_Instr As Integer
'Turn on Error handler
On Error GoTo Error_handler
booResult = False
GetProcesses = False
EXEName = UCase$(Trim$(EXEName))
lngLength = Len(EXEName)
'ProcessInfo.bolRunning = False
' Select Case getVersion()
' 'I'm not bothered about windows 95/98 becasue this class probably wont be used on it anyway.
' Case WIN95_System_Found 'Windows 95/98
'
' Case WINNT_System_Found 'Windows NT
lngCBSize = 8 ' Really needs To be 16, but Loop will increment prior to calling API
lngCBSizeReturned = 96
Do While lngCBSize <= lngCBSizeReturned
DoEvents
'Increment Size
lngCBSize = lngCBSize * 2
'Allocate Memory for Array
ReDim lngProcessIDs(lngCBSize / 4) As Long
'Get Process ID's
lngReturn = EnumProcesses(lngProcessIDs(1), lngCBSize, lngCBSizeReturned)
Loop
'Count number of processes returned
lngNumElements = lngCBSizeReturned / 4
'Loop thru each process
For lngLoop = 1 To lngNumElements
DoEvents
'Get a handle to the Process and Open
lngHwndProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ, 0, lngProcessIDs(lngLoop))
If lngHwndProcess <> 0 Then
'Get an array of the module handles for the specified process
lngReturn = EnumProcessModules(lngHwndProcess, lngModules(1), 200, lngCBSize2)
'If the Module Array is retrieved, Get the ModuleFileName
If lngReturn <> 0 Then
'Buffer with spaces first to allocate memory for byte array
strModuleName = Space(MAX_PATH)
'Must be set prior to calling API
lngSize = 500
'Get Process Name
lngReturn = GetModuleFileNameExA(lngHwndProcess, lngModules(1), strModuleName, lngSize)
'Remove trailing spaces
strProcessName = Left(strModuleName, lngReturn)
'Check for Matching Upper case result
strProcessName = UCase$(Trim$(strProcessName))
strProcName2 = GetElement(Trim(Replace(strProcessName, Chr$(0), "")), "\", 0, 0, GetNumElements(Trim(Replace(strProcessName, Chr$(0), "")), "\") - 1)
If strProcName2 = EXEName Then
'Get the Site of the Memory Structure
'pmc.cb = LenB(pmc)
'lret = GetProcessMemoryInfo(lngHwndProcess, pmc, pmc.cb)
'Debug.Print EXEName & "::" & CStr(pmc.WorkingSetSize / 1024)
'MsgBox EXEName & "::" & CStr(pmc.WorkingSetSize / 1024)
GetProcesses = True
End If
End If
End If
'Close the handle to this process
lngReturn = CloseHandle(lngHwndProcess)
DoEvents
Next
' End Select
IsProcessRunning_Exit:
'Exit early to avoid error handler
Exit Function
Error_handler:
Err.Raise Err, Err.Source, "ProcessInfo", Error
Resume Next
End Function
-
Sep 4th, 2012, 08:25 AM
#4
Re: Check if a process is running on Win7 64bit
Ugh, please use Code-Tags and mark the line where the error occurs.
On a guess, i'd say it has to do with you wanting to look up a 64-Bit-Process from a 32-Bit application
Maybe this will give you some clues (Scroll down until the end where the comments are): http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
-
Sep 4th, 2012, 08:47 AM
#5
Thread Starter
Hyperactive Member
Re: Check if a process is running on Win7 64bit
For some strange reason, I don't have the code tag. I have tags for links, email, and images, but the code tag seems to be missing. I've used it many times in previous posts, but it seems to be missing for me at the moment. Anyway, I found this code which works. If I can figure out why the code tag is missing, I'll come back and edit this so it doesn't look so messy.
Function getProcessInfo(ByVal EXEName As String) As Boolean
Dim objProcess As Object, process As Object, strNameOfUser As String, ComputerName As String
getProcessInfo = False
ComputerName = "."
Set objProcess = GetObject("winmgmts:{impersonationLevel=impersonate}\\" _
& ComputerName & "\root\cimv2").ExecQuery("Select * From Win32_Process")
For Each process In objProcess
If process.Name = EXEName Then '<> "System Idle Process" And process.Name <> "System" Then
getProcessInfo = True
End If
Next
Set objProcess = Nothing
End Function
-
Sep 4th, 2012, 08:49 AM
#6
Re: Check if a process is running on Win7 64bit
You can insert Code-Tags manually
[ code]
[/ code]
without the blanks
Ugh, the damned WMI!
Anyway: scroll down to the last post
http://social.msdn.microsoft.com/For...2-398e8f03238a
Last edited by Zvoni; Sep 4th, 2012 at 08:57 AM.
Tags for this Thread
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
|