I tried using the the Kernel32.DLL entrypoint GetsystemDirectory and that give me the following:
C:Windows\system32
What I really want is the path to the application: for example C:Programfiles\E!PC\WGSSS.exe
Is this possible or should I not be trying to get the information using API calls?
Here is my current code...
Imports System.Runtime.InteropServices
Imports System.Diagnostics
Imports System.Text
Module MyExtraOpenWindows
Public Delegate Function CallBack(ByVal hwnd As IntPtr, ByVal lParam As Integer) As Boolean
Public Declare Function EnumWindows Lib "user32" (ByVal Adress As CallBack, ByVal y As Integer) As Integer
Public Declare Function IsWindowVisible Lib "user32.dll" (ByVal hwnd As IntPtr) As Boolean
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As IntPtr, ByVal lpWindowText As String, ByVal cch As Integer) As Integer
Private Const SW_HIDE As Integer = 0
Private Const SW_RESTORE As Integer = 9
Private hWnd As Integer
Public selectedIndex As Integer
Private ActiveWindows As New System.Collections.ObjectModel.Collection(Of IntPtr)
<DllImport("KERNEL32.DLL", EntryPoint:="GetSystemDirectoryW", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Function GetSystemDirectory(ByVal Buffer _
As StringBuilder, ByVal Size As Integer) As Long
' Leave function empty - DLLImport attribute
' forces calls to GetSystemDirectory to
' be forwarded to GetSystemDirectory in KERNEL32.DLL
End Function
Public Const MAX_PATH As Integer = 256
<DllImport("User32")> Private Function ShowWindow(ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer
End Function
Public Function GetActiveWindows() As ObjectModel.Collection(Of IntPtr)
UserInfoForm.cboSessions.Items.Clear()
EnumWindows(AddressOf Enumerator, 0)
Return ActiveWindows
End Function
Private Function Enumerator(ByVal hwnd As IntPtr, ByVal lParam As Integer) As Boolean
Dim Windwtext As String = Space(Int16.MaxValue)
Dim WinName As System.Text.StringBuilder
Dim winDir As New StringBuilder(MAX_PATH)
Dim extradir As String
If IsWindowVisible(hwnd) Then
GetWindowText(hwnd, Windwtext, Int16.MaxValue)
GetSystemDirectory(winDir, MAX_PATH)
WinName = New System.Text.StringBuilder(UCase(Windwtext))
If InStr(WinName.ToString, "MYEXTRA") > 0 Then
WinName.Replace("~1 - MYEXTRA! ENTERPRISE", " ")
extradir = winDir.ToString
UserInfoForm.cboSessions.Items.Add(WinName.ToString)
End If
End If
Return True
End Function
End Module

New Topic/Question
Reply




MultiQuote







|