Link to home
Start Free TrialLog in
Avatar of Juilette
Juilette

asked on

How to get the hwnd to sendkeys to an app?

I have a file with a WS extension.
Under properties it says..DosName = s390.WS

I have tried to shell this file and I have tried to shell the lnk file pertaining to it but it won't shell

If I use shelldef it will open.

Using shelldef, is there a way to get the hwnd so I can send keys to it...

the file is s390.ws and I need to talk to it so I can sign on to workstation.

Wayne
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

can you not use FindWindow() if you know it's caption?
Avatar of Juilette
Juilette

ASKER

I could if I knew how...maybe...
You have the code?
Never mind I have the API...I'll give it a shot.
Wayne

This will not work to execute the pgm s390
 
 Shell "c:\Program Files \Personal communications\private\s390.ws"

or

dim retVal
retVal = Shell("C:\Program Files\Personal Communications\private\390.ws")

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
<<<<THIS WORKS >>>>>>>>

ShellDef ("C:\Program Files\Personal Communications\private\s390.ws")

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


''' this doesn't work

I have tried this to get the handle using this.

'this is in a bas module

Public Declare Function FindWindow Lib _
"user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

This is in the form event of caller

Dim h
 h = FindWindow("s390", vbNullString)

No success...
I assume that the s390.ws is a file used to gain access to a mainframe or as/400 using the personal communications terminal emulation. I am using the pc5250 emulation to access an as/400 in a similar way in fact. In order to do the login from vb all I have to do is

AppActivate "Session A - [24 x 80]"
Sendkeys "username{TAB}password{ENTER}"

where "Session A - [24 x 80]" is the caption of the terminal emulation window.

Hope this helps.
Tim, you are correct...it is a terminal emulation window...however when I try your suggestion (as below) I get an error (as below).
Since days are passing and I now have a whole of 30 some odd points..I will give what I have for an answer that works.

Wayne

Ps...where are the big guys...the top 15...someone must be able to lend a hand! I'm sure anyone with exposure to such things can walk me through the sign on.

'execute the ibm sign on

   ShellDef ("C:\Program Files\Personal Communications\private\s390.ws")

   DoEvents

   Dim session, username, password As String
   session = "CICS"
   username = "userme"
   password = "mypassword"

'activatge the app as per caption on the sign on screen (ibm emulator)
 
   AppActivate "Session A - {24 x 80]"
 
  SendKeys "session {TAB} username {TAB} password {ENTER}"
   
      DoEvents
',,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

'gives run time error 5 on AppActivate "Session A - [24 x 80]"
'[invalid procedure call or argument]

The capiton of the emulator  is Session A - [24 x 80]



ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

Tim, thanks...
gone to test...
Wayne
Tim:
Thanks a million...now on to the next step....I used your shell funciton and it worked fine...seems out system admin didn't include the full path when he set out the properties for the sc390...and the second problem was the ctrl key is the enter key...haven't tried it yet but I assume instead of ener I use Ctrl

Thanks for your patience.
Wayne
Tim, I tried to change the points and it didn't take effect...the balance are as new Question...TimCottee Only.
Tim:
Are you still on the thread..I'm having a little difficulty with this last part of your code.

SendKeys username & "{TAB}" & password & "{ENTER}"
sendkeys
sendkeys
etc.      
  DoEvents
    Timer1.Interval = 0


When I leave the timer.interval = o, I can't get past the second sendkeys..if I take it out I do all my sendkeys but of course it keeps sending keys...tried larger and smaller increments and anything else I can tink of...

How do I turn off the timer but only after the last sendkeys..and I have about 15 or so...

even tried putting a doevents after each send and then a disable after the last sendkeys but it still keeps sending.
Wayne
OK I think I understand, you need to set a wait period between each sendkeys in order to allow the emulator to process the commands and be ready to receive the next message.

Change the code to something like:

Private strSendKeys() as String
Private intMessage As Integer

Private Sub Command1_Click()
'execute the ibm sign on
   Shell "c:\program files\ibm\Client Access\Emulator\pcsws.exe private\as400.ws"
   Dim session, username, password As String
   session = "CICS"
   username = "Username"
   password = "Password"

'activatge the app as per caption on the sign on screen (ibm emulator)
   redim preserve strSendKeys(15) ' where 15 is number of messages to send
   strSendKeys(0) = username & "{TAB}" & password & "{ENTER}"
   strSendKeys(1) = "Message 1"
   strSendKeys(2) = "Message 2"
   '.... and so on
   intMessage = 0
   Timer1.Interval = 5000
   DoEvents
End Sub

Private Sub Timer1_Timer()
  AppActivate "Session A - [24 x 80]"
  Sendkeys strSendKeys(intMessage)
  intMessage = intMessage + 1
  IF intMessage > 15 Then ' or your max no of messages
    Timer1.Interval = 0
  End If
End Sub


I haven't tested this, just typed it from the top of my head so you may want to check it through and I cannot guarantee that it will work first time but the theory is ok.


Thanks,
Wayne

Theory is fine...I'll work out the rest.