URGENT-Problems with FindWindow API function

In my code I need to retrieve the handle to an explorer window if it's running. The Window name is "C:\Test"

I used FindWindow and it worked great. Here is my code:

Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr

 ptrRet = FindWindow(vbNullString, "C:\Test")
       
       
        If ptrRet.ToInt32 > 0 Then
           
            MsgBox("Window found")
        Else
            MsgBox("Window not found")
        End If
        If ptrRet.ToInt32 = 0 Then
            Dim temp As Int32 = Marshal.GetLastWin32Error()
            Dim errMsg As String = New Win32Exception(Marshal.GetLastWin32Error()).Message
            MsgBox("ERROR: " & temp & " - " & errMsg)
        End If

I ran this program on Windows XP and it was fine, but when I tried running it on Windows XP Embedded, FindWindow started returning 0

and the error I retrive is Error 5 - Access Denied

I was wondering if there is an equivalent of FindWindow that I could use instead?
LVL 35
YZlatAsked:
Who is Participating?
 
PAQ_ManConnect With a Mentor Commented:
Closed, 500 points refunded.
PAQ_Man
Community Support Moderator
0
 
AlexFMCommented:
Try to declare lpClassName parameter as IntPtr and pass IntPtr.Zero to the function.
0
 
YZlatAuthor Commented:
Alex, that didn't help - same result
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
AlexFMCommented:
Interesting that FindWindow API description for WinCE doesn't  say that lpClassName can be NULL. Return to string parameter and try to provide class name.
0
 
YZlatAuthor Commented:
yes, class name can be null. And it works on Windows Xp. The problem occurs on Windows XP Embedded
0
 
YZlatAuthor Commented:
Problem resolved - on Windows XP Embedded it does not show the full path in the title bar, and that's why it couldn't find the window since I was passing the function full title bar. I changed the settings in Folder Options and it worked
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.