Page 1 of 2 12 LastLast
Results 1 to 40 of 49

Thread: [RESOLVED] How to pass an IP to VNC Viewer

Hybrid View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    70

    Resolved [RESOLVED] How to pass an IP to VNC Viewer

    **Edit** I'm using VB6.

    Hey, I'm looking for a way to pass an IP to VNC. I work at a HelpDesk and remote into users computers all day. Our company only uses VNC to do this.

    What I have is a form with a textbox for the IP. The way I currently have it coded works the majority of the time.

    Here is how I have it working so far.

    1.)When I hit the command button, the program shells the .exe file for vnc.

    2.)I have a timer that trys to AppActivate the title of the VNC Window.

    3.)When it does find the window, I have it using SendKeys to send the IP from my textbox to the VNC window, and then have it press enter.

    4.)Once the IP is entered, it then prompts me for a password. So I have another timer waiting for the password window. When it's found I have it SendKeys the password to it and hit Enter.

    It works, but I since I'm using SendKeys, If I hit a key while it's doing it's thing it throws everything off.

    All help is greatly appreciated!

  2. #2
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: How to pass an IP to VNC Viewer

    Quote Originally Posted by jwetzler

    It works, but I since I'm using SendKeys, If I hit a key while it's doing it's thing it throws everything off.
    Wellcome to VBF

    Try using SendMessage insted of SendKeys. SendMessage works regardless of window forucs.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    70

    Re: How to pass an IP to VNC Viewer

    Quote Originally Posted by Fazi
    Wellcome to VBF

    Try using SendMessage insted of SendKeys. SendMessage works regardless of window forucs.
    Thanks for the reply! If the VNC window doesn't have the focus, how will SendMessage be able to send the IP to the VNC Dialogue box?

    I'll give it a shot when I get off of work. I don't have VB6 up here to play with.

    Any idea if there is a more effecient way of "watching" for the VNC dialogue box to come up? Or a way to pass the IP withouth using SendKeys/SendMessage ?

  4. #4
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: How to pass an IP to VNC Viewer

    Unlike sendKey, SendMessage requir some extra ordinary works if i am correct.
    If you can still solve your issue using sendkey, experts here at VBF will
    help you.

    Anyway to use SendMessage,
    First, You need to have the handle of the VNC Window. To obtain the handle you use FindWindow() API. Then you need to use the FindWindowEx() api to obtain a handle of the chiledwindow. (The child window here is your Text Box Control). Bought of thease functions are explained in the MSDN.

    Once you have the handles, you can use SendMessage API with the appropriate Messages to send the text to the control.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    70

    Re: How to pass an IP to VNC Viewer

    Quote Originally Posted by Fazi
    Unlike sendKey, SendMessage requir some extra ordinary works if i am correct.
    If you can still solve your issue using sendkey, experts here at VBF will
    help you.

    Anyway to use SendMessage,
    First, You need to have the handle of the VNC Window. To obtain the handle you use FindWindow() API. Then you need to use the FindWindowEx() api to obtain a handle of the chiledwindow. (The child window here is your Text Box Control). Bought of thease functions are explained in the MSDN.

    Once you have the handles, you can use SendMessage API with the appropriate Messages to send the text to the control.
    Cool, that sounds like the best way to go then. I knew there would be something better out there, just didn't know what it was called. Do you happen to have any examples of FindWindow or FindWindowEx?

    I'll do some searching and see if I can find any on here, or through google too.

  6. #6
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: How to pass an IP to VNC Viewer

    For more information regading SendMessage or Window functions, you can search the forum too

  7. #7
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: How to pass an IP to VNC Viewer

    You better get the API Guide. http://www.mentalis.org/agnet/apiguide.shtml

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    70

    Re: How to pass an IP to VNC Viewer

    thanks for the link. I can't wait to give this a try once I get home.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    70

    Re: How to pass an IP to VNC Viewer

    Ok so I'm having some trouble getting started on here. I came across this thread: http://www.vbforums.com/showthread.php?t=356751 but Can't seem to figure out how to code it right.

    I have found the Class of the VNC Application, where do I go from here as far as coding? This is the first time I've really messed with API so I'm a little confused.

    Where do I declare the API?

    Private Sub cmdGo_Click()

    '#32770 is the class for this window

    Dim lVNChWnd As Long

    lVNChWnd = FindWindow("#32770", vbNullString)

    'Now that I've told it to find the window, what do I do now to make it
    'find the textbox/combo box?

    End Sub
    VNC Window Handle/Class
    http://i178.photobucket.com/albums/w...VNC_Window.jpg

    VNC IP Textbox/Combo Box Class= ComboBox
    http://i178.photobucket.com/albums/w...C_Combobox.jpg

    VNC OK Button
    http://i178.photobucket.com/albums/w...VNC_Button.jpg

    VNC Authentication
    Last edited by jwetzler; Aug 16th, 2007 at 06:39 PM.

  10. #10
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: How to pass an IP to VNC Viewer

    Quote Originally Posted by jwetzler
    where do I go from here as far as coding? This is the first time I've really messed with API so I'm a little confused.
    Where do I declare the API?
    I have wrote the code for you. i check this code with my start menu run dialog box. it works. so i have replace the window name in the code to your vnc viewer. you need to find the class name of the combo box that holds the ip number and put it in the code. if you have question, reply

    Code:
    Option Explicit
    
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long
    
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    
    Private Const WM_SETTEXT = &HC
    
    
    
    
    Private Sub Command1_Click()
    Dim lhnd As Long 'parent window handle
    Dim lhndChild As Long 'child window handle
    Dim lngresult As Long
    
    lhnd = FindWindow(vbNullString, "VNC Viewer : Connection Details")
    'this will return the 'VNC Viewer : Connection Details " windows Handle
    
    lhndChild = FindWindowEx(lhnd, 0&, "VNC Viewer ComboBox class name here", vbNullString)
    'this will return the combo box handle.
    
    lngresult = SendMessage(lhndChild, WM_SETTEXT, 0&, ByVal "10.32.10.44")
    
    End Sub

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    70

    Re: How to pass an IP to VNC Viewer

    Code:
    Private Sub Command1_Click()
    Dim lhnd As Long 'parent window handle
    Dim lhndChild As Long 'child window handle
    Dim lngresult As Long
    
    lhnd = FindWindow(vbNullString, "VNC Viewer : Connection Details")
    'this will return the 'VNC Viewer : Connection Details " windows Handle
    Code:
    lhndChild = FindWindowEx(lhnd, 0&, "VNC Viewer ComboBox class name here", vbNullString)
    'this will return the combo box handle.
    I noticed that there are two Class names for this combo box.
    Edit is for the white box with out the down arrow & ComboBox is for the White box plus the dropdown arrow.
    Which class do I need to use in the code?

    When I do type the class in the code do I type Edit or "Edit" ? Do I want to put the class name in quotes?

    Code:
    lngresult = SendMessage(lhndChild, WM_SETTEXT, 0&, ByVal "10.32.10.44")
    End Sub
    How do I specify that I want it to send the contents of my textbox on the form txtIP.text? Since I remote into about 50 IP's daily.

    would it be the following?
    Code:
    lngresult = SendMessage(lhndChild, WM_SETTEXT, 0&, ByVal (txtIP.text))
    Thanks again for all the help.

  12. #12
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: How to pass an IP to VNC Viewer

    Quote Originally Posted by jwetzler
    I noticed that there are two Class names for this combo box.
    Edit is for the white box with out the down arrow & ComboBox is for the White box plus the dropdown arrow.
    Which class do I need to use in the code?

    When I do type the class in the code do I type Edit or "Edit" ? Do I want to put the class name in quotes?
    Try running the code one with 'Edit' and once with the 'ComboBox'. you will find the correct one.

    would it be the following?
    Code:
    lngresult = SendMessage(lhndChild, WM_SETTEXT, 0&, ByVal (txtIP.text))
    Thanks again for all the help.
    Yes, it is correct.

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    70

    Re: How to pass an IP to VNC Viewer

    Quote Originally Posted by Fazi
    Try running the code one with 'Edit' and once with the 'ComboBox'. you will find the correct one.
    do I need to put just the Classname or "Classname"? Will I need to put quotations around the class name?

  14. #14
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: How to pass an IP to VNC Viewer

    The IP can be passed as a command line argument... that leaves the password to worry about.

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    70

    Re: How to pass an IP to VNC Viewer

    Quote Originally Posted by leinad31
    The IP can be passed as a command line argument... that leaves the password to worry about.
    cool, do you have an example I could look at and try to adapt it to what I'm doing?

    I'm still interested in using FindWindow() API, FindWindowEx(), and SendMessage as well.

  16. #16
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: How to pass an IP to VNC Viewer

    Code:
    Private Sub Form_Load()
    Dim strIP As String
    
       strIP = "127.0.0.1"
       Shell "C:\Program Files\RealVNC\VNC4\vncviewer.exe " & strIP
    End Sub
    Wrap the shell in a procedure that accepts the IP address and password as parameters.

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    70

    Re: How to pass an IP to VNC Viewer

    Quote Originally Posted by leinad31
    Code:
    Private Sub Form_Load()
    Dim strIP As String
    
       strIP = "127.0.0.1"
       Shell "C:\Program Files\RealVNC\VNC4\vncviewer.exe " & strIP
    End Sub
    Wrap the shell in a procedure that accepts the IP address and password as parameters.
    I was able to test this out real quick and it worked for me. Question is how would I make it pass the password?

    Code:
    dim strIP as String
    dim strPW as String
    
    strIP = txtIP.text
    strPW = txtPW.text
    
    Shell "C:\Program Files\RealVNC\VNC4\vncviewer.exe " & strIP & strPW
    End Sub
    Would that work ^ for the password?

  18. #18
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: How to pass an IP to VNC Viewer

    Quote Originally Posted by jwetzler
    I was able to test this out real quick and it worked for me. Question is how would I make it pass the password?

    Code:
    dim strIP as String
    dim strPW as String
    
    strIP = txtIP.text
    strPW = txtPW.text
    
    Shell "C:\Program Files\RealVNC\VNC4\vncviewer.exe " & strIP & strPW
    End Sub
    Would that work ^ for the password?
    Nope, it will try to open strPW as an IP/destination_name in another window...

  19. #19
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: How to pass an IP to VNC Viewer

    It can also be done by using FindWindow API and PostMessage API.

  20. #20
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: How to pass an IP to VNC Viewer

    zynder, you'd have to do so for two windows (remote host selection and login), by including the IP as a command line argument you'll only have to deal with one window (login window).

    Divide and conquer

  21. #21
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: How to pass an IP to VNC Viewer

    jWetZler,

    It seems you have two solutions there. SendMessage/PostMessage and the solution from leinad31. feelfree to choose the best one . Dont confuse

  22. #22
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: How to pass an IP to VNC Viewer

    I'm not totally disregarding the SendMessage/PostMessage solution... the point was you don't have to implement everything with API when simple string concatenation can minimize development time/effort. It also minimizes possible sources of error or difficulties with debugging and maintenance. And I did say that he still has to content with filling the password... where's the source of confusion in that?

    Its not always black and white, his code or mine... there are shades of gray.

  23. #23
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: How to pass an IP to VNC Viewer

    Quote Originally Posted by leinad31
    I'm not totally disregarding the SendMessage/PostMessage solution... the point was you don't have to implement everything with API when simple string concatenation can minimize development time/effort. It also minimizes possible sources of error or difficulties with debugging and maintenance. And I did say that he still has to content with filling the password... where's the source of confusion in that?

    Its not always black and white, his code or mine... there are shades of gray.
    I really agree with your comment . Actually he has no previous knowledge on API it seems. But now he come to know what it is. but its a bit hard solution at this time.

    Yah, password field is a concern really

  24. #24
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: How to pass an IP to VNC Viewer

    Quote Originally Posted by leinad31
    I'm not totally disregarding the SendMessage/PostMessage solution... the point was you don't have to implement everything with API when simple string concatenation can minimize development time/effort. It also minimizes possible sources of error or difficulties with debugging and maintenance. And I did say that he still has to content with filling the password... where's the source of confusion in that?

    Its not always black and white, his code or mine... there are shades of gray.
    Im giving him options, not the correct and absolute solution that's why I mentioned that it can also be done. Since he's not resolving this thread, there could be problem to the given solution. I also dont have VNC here to test that out and its better to test it coz it may not work everytime.

  25. #25
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: How to pass an IP to VNC Viewer

    Leinad, Actually, cant he set the pass word using SendMessage?

  26. #26
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: How to pass an IP to VNC Viewer

    Don't have Spy++ here, and I don't have VNC at home so I defer the implementation details/code to those who can make actual tests.

  27. #27
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: How to pass an IP to VNC Viewer

    ok. i thing he can. let him answer this matter

  28. #28

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    70

    Re: How to pass an IP to VNC Viewer

    Thanks all for the reply's I'm about to head to work. I'm going to bring my laptop and if we have some down time today, I'll try using both methods of code and report back.

  29. #29
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: How to pass an IP to VNC Viewer

    Yes, you must.

  30. #30

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    70

    Re: How to pass an IP to VNC Viewer

    Also, all of you have proposed excellent solutions for getting
    this working.

    I like the idea of shelling the .exe and passing the IP to it. It's very simple.

    I also like the idea of using FindWindow and Sendmessage since it's something I've never tried before. It's more complicated doing the API's, but it's time for me to learn.

    I have already learned quite a bit from this thread through everyones contributions.

  31. #31
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: How to pass an IP to VNC Viewer

    Cheers

  32. #32

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    70

    Re: How to pass an IP to VNC Viewer

    How do I get it to activate the OK button once the IP is entered into the text/combo box?

    The OK button seems to be the default button for the VNC Viewer screen. Looks like the Class for the command button is "Button"

    VNC OK Button
    Last edited by jwetzler; Aug 15th, 2007 at 04:56 PM.

  33. #33
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: How to pass an IP to VNC Viewer

    Simulate a button click. Try this.

    Code:
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, 
    								      ByVal lpWindowName As String) As Long
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, 
    									  ByVal hWnd2 As Long, 
    									  ByVal lpsz1 As String, 
    									  ByVal lpsz2 As String) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, 
    									ByVal wMsg As Long, 
    									ByVal wParam As Integer, 
    									ByVal lParam As Any) As Long
    
    Private Const BM_CLICK As Long = &HF5&
    
    
    Private Sub Form_Load()
        Dim lHnd As Long
        Dim btnHnd As Long
        lHnd = FindWindow(vbNullString, "VNC Viewer : Connection Details")
        
        If lHnd <> 0 Then
            BtnHnd = FindWindowEx(lHnd, 0, "Button", vbNullString)
            If BtnHnd <> 0 Then
                    SendMessage BtnHnd, BM_CLICK, 0, 0&
            End If
        End If
    End Sub
    That is assuming "button" is the class name.

  34. #34

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    70

    Re: How to pass an IP to VNC Viewer

    So I combined both of the recommended codes from earlier. Tell me if this looks correct. Basically this code right here should pass the IP to the ComboBox, and "click" the OK button. Do you see any errors? I'm at my g/f house and can't test it.

    If the below works, I'm pretty sure I can adapt the code to work with the authentication dialogue box on VNC. I can just change a few classes so that it passes the password to VNC and hits the OK button.

    Last question/scenario. Sometimes depending on where the computer is that I"m trying to VNC to, it will take a 20-30 seconds for the password dialogue box to come up (we have pc's in markets all over the US + VPN users on DSL). How should I code it to pass the password to VNC, and if it doesn't find password box immediately, to have it keep trying for x amount of time. maybe 20 seconds or so?

    Code:
    Private Sub Command1_Click()
    Dim lHnd As Long 'parent window handle
    Dim lhndChild As Long 'child window handle
    Dim lngresult As Long
    Dim btnHnd As Long 'added to hit the OK button as experiment.
    
    lHnd = FindWindow(vbNullString, "VNC Viewer : Connection Details")
    'this will return the 'VNC Viewer : Connection Details " windows Handle
    
    lhndChild = FindWindowEx(lHnd, 0&, "ComboBox", vbNullString)
    'this will return the combo box handle.
    
    lngresult = SendMessage(lhndChild, WM_SETTEXT, 0&, ByVal (txtIP.Text))
    
    lHnd = FindWindow(vbNullString, "VNC Viewer : Connection Details")
        
        If lHnd <> 0 Then
            btnHnd = FindWindowEx(lHnd, 0, "Button", vbNullString)
            If btnHnd <> 0 Then
                    SendMessage btnHnd, BM_CLICK, 0, 0&
            End If
        End If
    End Sub
    Last edited by jwetzler; Aug 15th, 2007 at 10:07 PM.

  35. #35
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: How to pass an IP to VNC Viewer

    Yes, BM_CLICK Code is correct !

  36. #36

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    70

    Re: How to pass an IP to VNC Viewer

    Quote Originally Posted by Fazi
    Yes, BM_CLICK Code is correct !
    Last question/scenario. Sometimes depending on where the computer is that I"m trying to VNC to, it will take a 20-30 seconds for the password dialogue box to come up (we have pc's in markets all over the US + VPN users on DSL,Cable, Aircards etc).

    How should I code it to pass the password to VNC, if it doesn't find password box immediately? Like to have it keep trying for x amount of time. maybe 20 seconds or so and if it still doesn't find it after that, just quit trying.

    Would it be better to use a loop or a timer? Kind of confused on how I would code either of those. Not sure how to code it to where if FindWindow doesn't work, it will go again. I'm sure I could use an If statement, but what value does FindWindow return if it can't find the window?

    Can you show me some code that would work with that please?
    Last edited by jwetzler; Aug 16th, 2007 at 07:01 AM.

  37. #37
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: How to pass an IP to VNC Viewer

    You can change the if statement to do loop.

  38. #38

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    70

    Re: How to pass an IP to VNC Viewer

    Quote Originally Posted by zynder
    You can change the if statement to do loop.
    Can you give me an example please? I'm not sure what value is returned when FindWindow doesn't find the text of the window that it's looking for. I was thinking maybe a Do Until or Do While loop?

  39. #39

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    70

    Re: How to pass an IP to VNC Viewer

    n/m I answered one of my own questions
    Last edited by jwetzler; Aug 16th, 2007 at 07:00 PM.

  40. #40

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    70

    Re: How to pass an IP to VNC Viewer

    I managed to tweak the code and get it to work fine with the first part of my VNC issue.

    The following code passes the IP, and tells it to press the OK Button:

    Code:
    Private Sub Command1_Click()
    Dim lHnd As Long 'parent window handle
    Dim lhndChild As Long 'child window handle
    Dim lngresult As Long
    Dim btnHnd As Long 'added to hit the OK button as experiment.
    
    lHnd = FindWindow(vbNullString, "VNC Viewer : Connection Details")
    'this will return the 'VNC Viewer : Connection Details " windows Handle
    
    lhndChild = FindWindowEx(lHnd, 0&, "ComboBox", vbNullString)
    'this will return the combo box handle.
    
    lngresult = SendMessage(lhndChild, WM_SETTEXT, 0&, ByVal (txtIP.Text))
    'Sends whatever is in the txtIP textbox that I created on my form
    
    lHnd = FindWindow(vbNullString, "VNC Viewer : Connection Details")
        
        If lHnd <> 0 Then
            btnHnd = FindWindowEx(lHnd, 0, "Button", "OK")
             'makes it hit the OK button
    
            If btnHnd <> 0 Then
                    SendMessage btnHnd, BM_CLICK, 0, 0&
            End If
        End If
    End Sub
    Last edited by jwetzler; Aug 16th, 2007 at 06:59 PM.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width