Phil Chapman
asked on
Application Name
Application Name
How can I get the name of an application within a DLL.
Example:
Application Name = MyApplication.EXE
Dll Name = MyDLL.DLL
MyDLL.DLL is accessed by MyApplication.EXE
If you do MsgBox App.EXEName within MyDLL.DLL it returns MyDLL . How can I get the name of the application? In this case MyApplication
How can I get the name of an application within a DLL.
Example:
Application Name = MyApplication.EXE
Dll Name = MyDLL.DLL
MyDLL.DLL is accessed by MyApplication.EXE
If you do MsgBox App.EXEName within MyDLL.DLL it returns MyDLL . How can I get the name of the application? In this case MyApplication
I am sorry ignore my comment, that is for VB.Net
ASKER
Epaclm,
This code appears to return the language identifier and not the EXE parent name.
This code appears to return the language identifier and not the EXE parent name.
Sorry, the best I could find. Maybe it can be updated to find more info. Try and see what you get with this file.
Curt
Find-DLL-details.xls
Curt
Find-DLL-details.xls
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
' Here is the so called correct way to do this thanks for the points.
Option Explicit
Private Declare Function GetModuleFileNameExW Lib "Psapi" (ByVal hProcess As Long, ByVal hModule As Long, ByVal lpFilename As Long, ByVal nSize As Long) 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 CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Private Const PROCESS_QUERY_INFORMATION As Long = &H400
Private Const PROCESS_VM_READ As Long = &H10
Public Function ModuleFilename() As String
Dim Buffer(1024) As Byte
Dim hProcess As Long
Dim dwLength As Long
Dim dwPid As Long
' * get this applications process id
dwPid = GetCurrentProcessId
' * get the real process handle with correct access masks.
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ, 0, dwPid)
' * get the name of the application
dwLength = GetModuleFileNameExW(hProcess, 0, VarPtr(Buffer(0)), UBound(Buffer))
' * ToString
ModuleFilename = Left$(Buffer, dwLength)
' * cleanup the process handle
CloseHandle hProcess
' * cleanup the buffer
Erase Buffer
End Function
ASKER
Thanks
try, example from MSDN
http://msdn.microsoft.com/en-us/library/system.reflection.assembly.getcallingassembly.aspx
Dim SampleAssembly As [Assembly]
' Instantiate a target object.
Dim Integer1 As New Int32()
Dim Type1 As Type
' Set the Type instance to the target class type.
Type1 = Integer1.GetType()
' Instantiate an Assembly class to the assembly housing the Integer type.
SampleAssembly = [Assembly].GetAssembly(Int
' Display the name of the assembly that is calling the method.
Console.WriteLine(("GetCal