We help IT Professionals succeed at work.

Know computer, application path and current path of DLL.

awehme
awehme asked
on
480 Views
Last Modified: 2012-05-09
I have had a simliar question answered.

https://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_26285289.html

What I would like to know now is how to know..

what is the computer name of the computer that called the DLL.??
what is the current path of the DLL.??
what is the complete path ( along with file name ) of the application that is calling the DLL.??
What is the logged on user name that is calling the DLL.??

Thanks
Comment
Watch Question

Top Expert 2010

Commented:
See code block, and for determining the path of the DLL just call App.Path inside your class / DLL.

Option Explicit
 
Private Declare Function GetComputerNameW Lib "Kernel32.dll" ( _
    ByVal lpBuffer As Long, _
    ByRef lpnSize As Long) As Long
    
Private Declare Function GetUserNameW Lib "Advapi32.dll" ( _
    ByVal lpBuffer As Long, _
    ByRef lpnSize As Long) As Long

Public Function GetComputerName() As String
    
    Dim Buffer(512)     As Byte
    Dim lpSize          As Long
    
    lpSize = 256
    ' lpSize returns *not including the terminating null character.
    If GetComputerNameW(VarPtr(Buffer(0)), lpSize) Then
        GetComputerName = Left$(Buffer, lpSize)
    Else
        GetComputerName = vbNullString
    End If
    
End Function

Public Function GetUserName() As String
    
    Dim Buffer(512)     As Byte
    Dim lpSize          As Long
    
    lpSize = 256
    ' lpSize returns including the terminating null character.
    If GetUserNameW(VarPtr(Buffer(0)), lpSize) Then
        GetUserName = Left$(Buffer, lpSize - 1)
    Else
        GetUserName = vbNullString
    End If
    
End Function

Open in new window

Author

Commented:
Thanks for the code.  

How about the 3rd question.??
what is the complete path ( along with file name ) of the application that is calling the DLL.??

Thanks
Top Expert 2010
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
It appears that this returns the .exe that is calling the .dll.


So I'm using VBscript and it's returning c:\windows\system32\wscript.exe

Is there a way to return the path of the .vbs file that is calling the DLL, like "f:\myfolder\myscript.vbs"??

Thanks
Top Expert 2010

Commented:
No, Wscript.exe is what hosts the .vbs file and it's the process that has loaded the DLL. You could add your own check if CScript.exe or WScript.exe you can assume a script file.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.