|
-
Aug 13th, 2007, 10:02 AM
#1
Thread Starter
Lively Member
[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!
-
Aug 13th, 2007, 12:34 PM
#2
Re: How to pass an IP to VNC Viewer
 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.
-
Aug 13th, 2007, 12:40 PM
#3
Thread Starter
Lively Member
Re: How to pass an IP to VNC Viewer
 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 ?
-
Aug 13th, 2007, 12:56 PM
#4
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.
-
Aug 13th, 2007, 01:03 PM
#5
Re: How to pass an IP to VNC Viewer
For more information regading SendMessage or Window functions, you can search the forum too
-
Aug 13th, 2007, 01:28 PM
#6
Thread Starter
Lively Member
Re: How to pass an IP to VNC Viewer
 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.
-
Aug 13th, 2007, 01:35 PM
#7
Re: How to pass an IP to VNC Viewer
-
Aug 13th, 2007, 04:32 PM
#8
Thread Starter
Lively Member
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.
-
Aug 14th, 2007, 06:39 PM
#9
Thread Starter
Lively Member
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.
-
Aug 14th, 2007, 07:17 PM
#10
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.
-
Aug 14th, 2007, 08:06 PM
#11
Thread Starter
Lively Member
Re: How to pass an IP to VNC Viewer
 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.
-
Aug 15th, 2007, 12:19 AM
#12
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.
-
Aug 15th, 2007, 02:04 AM
#13
Re: How to pass an IP to VNC Viewer
It can also be done by using FindWindow API and PostMessage API.
-
Aug 15th, 2007, 03:36 AM
#14
Re: How to pass an IP to VNC Viewer
 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
-
Aug 15th, 2007, 03:39 AM
#15
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
-
Aug 15th, 2007, 03:45 AM
#16
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
-
Aug 15th, 2007, 03:52 AM
#17
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.
-
Aug 15th, 2007, 04:05 AM
#18
Re: How to pass an IP to VNC Viewer
 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
-
Aug 15th, 2007, 04:10 AM
#19
Re: How to pass an IP to VNC Viewer
Leinad, Actually, cant he set the pass word using SendMessage?
-
Aug 15th, 2007, 04:14 AM
#20
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.
-
Aug 15th, 2007, 04:26 AM
#21
Re: How to pass an IP to VNC Viewer
ok. i thing he can. let him answer this matter
-
Aug 15th, 2007, 07:02 AM
#22
Thread Starter
Lively Member
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.
-
Aug 15th, 2007, 09:50 AM
#23
Thread Starter
Lively Member
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.
-
Aug 15th, 2007, 11:34 AM
#24
Thread Starter
Lively Member
Re: How to pass an IP to VNC Viewer
 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?
-
Aug 15th, 2007, 11:50 AM
#25
Re: How to pass an IP to VNC Viewer
 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.
-
Aug 15th, 2007, 12:15 PM
#26
Re: How to pass an IP to VNC Viewer
 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.
-
Aug 15th, 2007, 12:21 PM
#27
Thread Starter
Lively Member
Re: How to pass an IP to VNC Viewer
 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?
-
Aug 15th, 2007, 12:27 PM
#28
Re: How to pass an IP to VNC Viewer
-
Aug 15th, 2007, 12:30 PM
#29
Thread Starter
Lively Member
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.
-
Aug 15th, 2007, 12:40 PM
#30
Re: How to pass an IP to VNC Viewer
Cheers
-
Aug 15th, 2007, 01:58 PM
#31
Thread Starter
Lively Member
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.
-
Aug 15th, 2007, 07:49 PM
#32
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.
-
Aug 15th, 2007, 09:20 PM
#33
Re: How to pass an IP to VNC Viewer
 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...
-
Aug 15th, 2007, 10:03 PM
#34
Thread Starter
Lively Member
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.
-
Aug 15th, 2007, 10:23 PM
#35
Re: How to pass an IP to VNC Viewer
Yes, BM_CLICK Code is correct !
-
Aug 15th, 2007, 10:54 PM
#36
Thread Starter
Lively Member
Re: How to pass an IP to VNC Viewer
 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.
-
Aug 16th, 2007, 07:24 AM
#37
Re: How to pass an IP to VNC Viewer
You can change the if statement to do loop.
-
Aug 16th, 2007, 08:21 AM
#38
Thread Starter
Lively Member
Re: How to pass an IP to VNC Viewer
 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?
-
Aug 16th, 2007, 09:16 AM
#39
Thread Starter
Lively Member
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.
-
Aug 16th, 2007, 04:29 PM
#40
Thread Starter
Lively Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|