hainansyndrome
asked on
call vb6 click from vb.net 22008
There is a vb6 app called scold1.exe
I want to call the code from dot net to make it open with out having to touch the vb6 app
the vb6 code is, I am new to dotnet and programming in general so any help would be appreciated
Private Sub mnuSetup_Click()
Timer1.Enabled = False
bSetup = True
frmWizard.Show vbModal
If UCase(Trim(Command())) <> "/ADMIN" Then
Me.Hide
End If
bSetup = False
Timer1.Interval = 10000
Timer1.Enabled = True
End Sub
I want to call the code from dot net to make it open with out having to touch the vb6 app
the vb6 code is, I am new to dotnet and programming in general so any help would be appreciated
Private Sub mnuSetup_Click()
Timer1.Enabled = False
bSetup = True
frmWizard.Show vbModal
If UCase(Trim(Command())) <> "/ADMIN" Then
Me.Hide
End If
bSetup = False
Timer1.Interval = 10000
Timer1.Enabled = True
End Sub
ASKER
I am already opening it with this
If (File.Exists("c:\scold1.ex e")) Then
System.Diagnostics.Process .Start("C: \scold1.ex e", "/setup")
Else
MsgBox("Scold is Not Installed In C:\", , "Scoldis not here!")
End If
What i want to do is call the info in my post if it is already running, we want to avoid closing scold1.exe
If (File.Exists("c:\scold1.ex
System.Diagnostics.Process
Else
MsgBox("Scold is Not Installed In C:\", , "Scoldis not here!")
End If
What i want to do is call the info in my post if it is already running, we want to avoid closing scold1.exe
If you want to automatically click that button then your best bet is to get a handle to the main window:
Dim P As Process = Process.Start("c:\some\pat h\scold1.e xe")
P.WaitForInputIdle()
Dim pHandle As IntPtr = P.MainWindowHandle
Now you can use "pHandle" with the FindWindowEx() API to get a handle to the target button. If there is more than one button then you may need to get a handle to the first one and then iterate until you find the correct one. Once you have a handle to the button, you can use SendMessage() with BM_CLICK to click it.
https://www.experts-exchange.com/questions/23787272/How-to-send-click-event-to-button-on-other-application.html
Dim P As Process = Process.Start("c:\some\pat
P.WaitForInputIdle()
Dim pHandle As IntPtr = P.MainWindowHandle
Now you can use "pHandle" with the FindWindowEx() API to get a handle to the target button. If there is more than one button then you may need to get a handle to the first one and then iterate until you find the correct one. Once you have a handle to the button, you can use SendMessage() with BM_CLICK to click it.
https://www.experts-exchange.com/questions/23787272/How-to-send-click-event-to-button-on-other-application.html
ASKER
What I am trying to do is have 2 buttons
1 opens the app if it is closed
the other will pass the above posted info to cause it to open to the admin page
Ill research what you posted Idle_mind but not sure it is what i am looking for
1 opens the app if it is closed
the other will pass the above posted info to cause it to open to the admin page
Ill research what you posted Idle_mind but not sure it is what i am looking for
You can check to see if it is open already with code like this:
Dim FileName As String = "c:\some\path\scold1.exe"
Dim ps() As Process = Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(FileName))
If ps.Length = 0 Then
Process.Start(FileName) ' not running...so start it up
Else
' it is already running...
End If
ASKER
IT is close
Here is my button 1
What I want is to code a button 2 so if itis open it can pass in the code to make it open, accessing the vb6 exe directly, is that possible? someone sugested teh Shell_NotifyIcon
Dim T() As Process = Process.GetProcessesByName ("Scold1") '
If T.Length > 0 Then
MsgBox("TScold already Running.", , "Can not Open Scold")
Else
If (File.Exists("c:\scold1.ex e")) Then
System.Diagnostics.Process .Start("c: \scold1.ex e", "/setup")
Else
MsgBox("Scold is Not Installed In C:\", , "Scold is not here!")
End If
End If
Here is my button 1
What I want is to code a button 2 so if itis open it can pass in the code to make it open, accessing the vb6 exe directly, is that possible? someone sugested teh Shell_NotifyIcon
Dim T() As Process = Process.GetProcessesByName
If T.Length > 0 Then
MsgBox("TScold already Running.", , "Can not Open Scold")
Else
If (File.Exists("c:\scold1.ex
System.Diagnostics.Process
Else
MsgBox("Scold is Not Installed In C:\", , "Scold is not here!")
End If
End If
Does passing in "/setup" as a command line parameter make it do EVERYTHING that you want?
...or do you still need to simulate the user manually clicking on a button in Scold1?
...or do you still need to simulate the user manually clicking on a button in Scold1?
ASKER
i need to simulate the user clicking
if i launch the app with the /setup when the app is closed all goes correct
but i dont want to open it if it is already running so I need a way to simulate the clicks
as you put it
or call the running exe directly
if i launch the app with the /setup when the app is closed all goes correct
but i dont want to open it if it is already running so I need a way to simulate the clicks
as you put it
or call the running exe directly
Gotcha. Grab yourself WinSpector (Free):
http://www.windows-spy.com/
This will allow you to easily the hierarchy of controls along with their classnames in your target app.
See the image below. It shows the buttons in Calculator.
Here is some code that can click the "C" (clear button) in Calculator. Note that it is looking for a window, starting with the main window handle, that has a ClassName of "Button" AND a Value of "C":
Dim cBtnHandle As IntPtr = FindWindowEx(P.MainWindowH andle, IntPtr.Zero, "Button", "C")
The code:
http://www.windows-spy.com/
This will allow you to easily the hierarchy of controls along with their classnames in your target app.
See the image below. It shows the buttons in Calculator.
Here is some code that can click the "C" (clear button) in Calculator. Note that it is looking for a window, starting with the main window handle, that has a ClassName of "Button" AND a Value of "C":
Dim cBtnHandle As IntPtr = FindWindowEx(P.MainWindowH
The code:
Public Class Form1
Private Const BM_CLICK As Integer = &HF5
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal handle As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As IntPtr, ByVal hWnd2 As IntPtr, ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim P As Process
Dim ps() As Process = Process.GetProcessesByName("calc")
If ps.Length = 0 Then
P = Process.Start("calc")
P.WaitForInputIdle()
Else
P = ps(0)
End If
Dim cBtnHandle As IntPtr = FindWindowEx(P.MainWindowHandle, IntPtr.Zero, "Button", "C")
If Not cBtnHandle.Equals(IntPtr.Zero) Then
SendMessage(cBtnHandle, BM_CLICK, 0, 0)
End If
End Sub
End Class
WinspectorWithCalc.jpg
*In VB6, I believe all the controls start with "Thunder", so you'll have to find the correct classname for your VB6 button with Winspector and replace "Button" with "ThunderXXXXX"...whatever the XXX is....
ASKER
ok I think I have it
maybe like i said I am a newbie
so ThunderRT6CommandButton is what i found
so
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim P As Process
Dim ps() As Process = Process.GetProcessesByName ("Scold1")
If ps.Length = 0 Then
P = Process.Start("Scold1")
P.WaitForInputIdle()
Else
P = ps(0)
End If
Dim cBtnHandle As IntPtr = FindWindowEx(P.MainWindowH andle, IntPtr.Zero, "ThunderRT6CommandButton", "C")
If Not cBtnHandle.Equals(IntPtr.Z ero) Then
SendMessage(cBtnHandle, BM_CLICK, 0, 0)
End If
End Sub
End Class
maybe like i said I am a newbie
so ThunderRT6CommandButton is what i found
so
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim P As Process
Dim ps() As Process = Process.GetProcessesByName
If ps.Length = 0 Then
P = Process.Start("Scold1")
P.WaitForInputIdle()
Else
P = ps(0)
End If
Dim cBtnHandle As IntPtr = FindWindowEx(P.MainWindowH
If Not cBtnHandle.Equals(IntPtr.Z
SendMessage(cBtnHandle, BM_CLICK, 0, 0)
End If
End Sub
End Class
ASKER
illplay tonight and let you know later
thanks for the stear in the right
directions
thanks for the stear in the right
directions
In this line:
Dim cBtnHandle As IntPtr = FindWindowEx(P.MainWindowH andle, IntPtr.Zero, "ThunderRT6CommandButton", "C")
Change the "C" to whatever the button says (the "caption" in VB6)...it might be "Setup"?
Dim cBtnHandle As IntPtr = FindWindowEx(P.MainWindowH
Change the "C" to whatever the button says (the "caption" in VB6)...it might be "Setup"?
ASKER
actually there is not button
when scoold is running
there is a icon in the tasktry
i have to right click it and choose setup from 3 options
this does the same as opening it with the command line
scold.exe /setup
when scoold is running
there is a icon in the tasktry
i have to right click it and choose setup from 3 options
this does the same as opening it with the command line
scold.exe /setup
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
yes see here is the kicker Number #2
when scold is running it could be accessing a dll and doing some dat aback up
i am wanting to write the app to open it so we can see if it is running
if you open then it just pauses the data backup
I dont want to kill it, just pause it when i need to check something
but any ideas in the right direction would be nice
thanks for all the time and effort
when scold is running it could be accessing a dll and doing some dat aback up
i am wanting to write the app to open it so we can see if it is running
if you open then it just pauses the data backup
I dont want to kill it, just pause it when i need to check something
but any ideas in the right direction would be nice
thanks for all the time and effort
System.Diagnostics.Process
You can also create a new process object and actually keep track of the process as it runs. Doing it that way will give you more detailed control over the process. See this example:
http://www.freevbcode.com/ShowCode.asp?ID=5879