-
[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!
-
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.
-
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 ?
-
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.
-
Re: How to pass an IP to VNC Viewer
For more information regading SendMessage or Window functions, you can search the forum too :)
-
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.
-
Re: How to pass an IP to VNC Viewer
-
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.
-
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?
Quote:
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
http://i178.photobucket.com/albums/w...r/VNC_Auth.jpg
-
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.
-
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.
-
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.
-
Re: How to pass an IP to VNC Viewer
It can also be done by using FindWindow API and PostMessage API.
-
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
-
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
-
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 :D
-
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.
-
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 :thumb: . 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. :p
Yah, password field is a concern really :sick:
-
Re: How to pass an IP to VNC Viewer
Leinad, Actually, cant he set the pass word using SendMessage?
-
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.
-
Re: How to pass an IP to VNC Viewer
ok. i thing he can. let him answer this matter :D
-
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.
-
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.
-
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?
-
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.
-
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. :)
Quote:
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. :)
-
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?
-
Re: How to pass an IP to VNC Viewer
-
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. :D
-
Re: How to pass an IP to VNC Viewer
-
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
http://i178.photobucket.com/albums/w...VNC_Button.jpg
-
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. :)
-
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...
-
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
-
Re: How to pass an IP to VNC Viewer
Yes, BM_CLICK Code is correct !
-
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?
-
Re: How to pass an IP to VNC Viewer
You can change the if statement to do loop.
-
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?
-
Re: How to pass an IP to VNC Viewer
n/m I answered one of my own questions :D
-
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
-
Re: How to pass an IP to VNC Viewer
I'm am stuck on the Authentication Screen. The VNC Authentication dialogue box has two text boxes on it. One for Username & one for Password. The username textbox is disabled.
Evidentally both text boxes have the class of "Edit". Both of their handles change everytime as well.
Only difference I found between the two were their "Style"
When I try to have it SendMessage the password, it enters it into the disabled Username Textbox instead of the Password textbox.
How do I make it use the Password Textbox?
Here is a pic, see how "my password" shows up in the disabled text box.
http://i178.photobucket.com/albums/w...Password-1.jpg
-
Re: How to pass an IP to VNC Viewer
Fazi any ideas on the password issue where the two textboxes have the same class??
I can't figure out how to make it sendmessage to the password textbox.
-
Re: How to pass an IP to VNC Viewer
-
Re: How to pass an IP to VNC Viewer
Quote:
Originally Posted by Fazi
I took a look at the thread, but looks like the guy hasn't started on the array yet. I'm unfamiliar with how to create an array, and how to use it to find all the controls of the window.
Can you please help with the code?
-
Re: How to pass an IP to VNC Viewer
The link i pointed has two solutions. I havent try the one RobDog specified.
but i can help you to manipulate the positions using the windowRect. first you must undestand the techinique here.
jwetzler:sick: did you undestand really how the text boxes are going to manipulate using its positions?
GetWindowRect API, when given a handle of a window, it gives the following screen cordinates where the controls have been planted on the screen :) 'those are Left, Right, Top and Bottom. OK? So if we want to manipulate the top positions of the text boxes, the one got the lowest value is the top one. the one with the highest value is the bottom one in your case.
ok? did you undestand?
-
Re: How to pass an IP to VNC Viewer
Quote:
Originally Posted by Fazi
The link i pointed has two solutions. I havent try the one RobDog specified.
but i can help you to manipulate the positions using the windowRect. first you must undestand the techinique here.
jwetzler:sick: did you undestand really how the text boxes are going to manipulate using its positions?
GetWindowRect API, when given a handle of a window, it gives the following screen cordinates where the controls have been planted on the screen :) 'those are Left, Right, Top and Bottom. OK? So if we want to manipulate the top positions of the text boxes, the one got the lowest value is the top one. the one with the highest value is the bottom one in your case.
ok? did you undestand?
Ok, I see what you are saying, this is the first time for me use GetWindowRect API. So this API is going to keep us from having to store the controls in an array.
-
Re: How to pass an IP to VNC Viewer
wait. i just need to try RobDogs post as well. will find a best solution.
Quote:
You can use the GetWindow API with the GW_HWNDNEXT argument constant or you can use the GetDlgCtrlID to retrieve the window control id number and match it with its known number to be able to identify if its the correct window.
-
1 Attachment(s)
Re: How to pass an IP to VNC Viewer
Jwetzler,
I have created a sample project that identifies a perticular control which has identical Class names. You can change it to suit to your project.
First you must run the control.exe file inside the project folder, which is a sample login box. then run the project and click the 'Comman1' Button. now you should see your user name and passworld boxes are correctly filled.
-
Re: How to pass an IP to VNC Viewer
Quote:
Originally Posted by Fazi
Jwetzler,
I have created a sample project that identifies a perticular control which has identical Class names. You can change it to suit to your project.
First you must run the control.exe file inside the project folder, which is a sample login box. then run the project and click the 'Comman1' Button. now you should see your user name and passworld boxes are correctly filled.
Thanks, that is exactly what I'm looking for. This fixed my issue, I was able to adapt it to my code. Fazi you're a genius.
Thanks to everyone else that contributed as well. I'm going to mark this as resolved. When I get more time, I'm going to post an example of my final code incase anyone else ever needs something similar.