Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Is program using a particular DLL

Posted on 2010-09-24
5
Medium Priority
?
576 Views
Last Modified: 2012-05-10
Hi,
I need a way to programmatically find if a program (exe) is using a particular dll, named DINPUT8.dll.

I can do this easily by using Process Explorer, if you right-click on a process and choose Properties, and choose Threads tab, you can see if it is using it.
Now I would need a method to programmatically obtain such an information, and if possible such that would work both on 32 and 64bit systems.
0
Comment
Question by:npaun
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
JonMny earned 999 total points
ID: 33756337
Try this, loops through all processes. (vb.net)



    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
        Dim files As New List(Of String)()

        Dim procList As Process() = Process.GetProcesses()

        For i As Integer = 0 To procList.Length - 1
            Try


                'Get all modules inside the process
                Dim modulesList As Process() = Process.GetProcessesByName(procList(i).ProcessName)
                ' Populate the module collection.
                Dim modules As ProcessModuleCollection = modulesList(0).Modules

                ' Iterate through the module collection.

                For Each objModule As ProcessModule In modules

                    Dim modulePath = objModule.FileName.ToString()
                    files.Add(modulePath)
                Next
                ' add error checking
            Catch generatedExceptionName As Exception


            End Try
        Next
    End Sub
0
 
LVL 29

Assisted Solution

by:nffvrxqgrcfqvvc
nffvrxqgrcfqvvc earned 501 total points
ID: 33757420
You can use CreateToolhelp32Snapshot.
http://msdn.microsoft.com/en-us/library/ms682489(v=VS.85).aspx
You may want to consider using VB.NET if you want to compatability with x64 systems...
" If the specified process is a 64-bit process and the caller is a 32-bit process, this function fails and the last error code is ERROR_PARTIAL_COPY (299)."
TH32CS_SNAPMODULE
TH32CS_SNAPMODULE32

Option Explicit

Private Const TH32CS_SNAPMODULE As Long = &H8&
Private Const TH32CS_SNAPMODULE32 As Long = &H10&

Private Const INVALID_HANDLE_VALUE As Long = (-1)

Private Type MODULEENTRY32W
dwSize As Long
th32ModuleID As Long
th32ProcessID As Long
GlblcntUsage As Long
ProccntUsage As Long
modBaseAddr As Byte
modBaseSize As Long
hModule As Long
szModule As String * 256
szExePath As String * 260
End Type

Private Declare Function CreateToolhelp32Snapshot Lib "kernel32.dll" ( _
  ByVal dwFlags As Long, _
  ByVal th32ProcessID As Long) As Long

Private Declare Function Module32FirstW Lib "kernel32.dll" ( _
  ByVal hSnapshot As Long, _
  ByVal lpme As Long) As Long

Private Declare Function Module32NextW Lib "kernel32.dll" ( _
  ByVal hSnapshot As Long, _
  ByVal lpme As Long) As Long
 
Private Declare Function CloseHandle Lib "kernel32.dll" ( _
  ByVal hObject As Long) As Long
  
Public Sub EnumModuleByProcessId(ByVal pid As Long)
  '// Note: Example doesn't remove null from the buffer.
  Dim hSnapshot     As Long
  Dim entry         As MODULEENTRY32W
  hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid)
  If hSnapshot = (-1) Then
    Debug.Print "Invalid handle"; Err.LastDllError
    Exit Sub
  End If
  entry.dwSize = LenB(entry)
  ' // first module
  If Module32FirstW(hSnapshot, VarPtr(entry)) Then
    Debug.Print entry.szModule
    Debug.Print entry.szExePath
    '// next module
    Do While Module32NextW(hSnapshot, VarPtr(entry)) <> 0
        Debug.Print entry.szModule
        Debug.Print entry.szExePath
    Loop ' or  ERROR_NO_MORE_FILES
  End If
  Debug.Print Err.LastDllError
  
  CloseHandle hSnapshot
End Sub

Open in new window

0
 

Author Comment

by:npaun
ID: 33763447
Hi, thanks, both examples work. Although, I would proffer to avoid use of separate .Net if possible. I realized that this may be easily achievable for both x64/x86 by using WMI, do you maybe know can it and how?
0
 
LVL 9

Assisted Solution

by:JonMny
JonMny earned 999 total points
ID: 33764859
this example will show any process that has Kerne32 loaded , Change Check for to the dll you want.
 
dim checkFor
dim wmi
checkfor= "kernel32"
set wmi = getobject("winmgmts:")
set oProcesses = wmi.ExecQuery("select * from WIN32_Process")
for each oProcess in oProcesses
 set oFileAssociations = wmi.ReferencesTo(oProcess.Path_.path, "CIM_ProcessExecutable")
 for each oFileAssociation in oFileAssociations
  set oFile = wmi.Get(oFileAssociation.Antecedent)
  if oFile.FileName = checkfor and oFile.Extension = "dll" then
   wscript.echo oProcess.name + " has kernel32.dll loaded"
  end if
 next
next
0
 

Author Closing Comment

by:npaun
ID: 33892765
thanks. I accepted all three answers, as all of them have their use and limitations for me. Unfortunately, I have only 500 pts to split.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question