6 Replies - 1379 Views - Last Post: 18 January 2013 - 11:46 AM Rate Topic: -----

#1 swiftvb_5  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-January 13

Sendkeys send before window open

Posted 17 January 2013 - 12:09 PM

Hi,

I am writing a program that uses putty to telnet to a printer so I can set the ip,subnet mask, default gateway.

The problem that I get is that when I use sendkeys to the putty window, It will send it before the window is open. Also It seems to send even if putty is open but sends the sendkeys to the window behind it. Ive tried thread.sleep, me.refresh, application.doevents,appactivate, waitforeinputidle, anything to the delay the send.

Thanks in advance




p = Process.Start(CurDir() + "\programs\putty.exe", "telnet://192.168.1.2")

            x = p.WaitForInputIdle(10000)
            If x = True Then



                AppActivate("putty")
                Me.Refresh()

                SendKeys.Send("192.168.1.2" + "~")

                AppActivate("putty")
                Me.Refresh()

                SendKeys.Send("subnet-mask 255.255.255.0" + "~")

                AppActivate("putty")
                Me.Refresh()

                SendKeys.Send"(192.168.1.1" + "~")
                
                AppActivate("putty")
                Me.Refresh()

                'SendKeys.Send("save" & "~")
                
                Me.Refresh()

           Else:
                    msgbox("error")
                



Is This A Good Question/Topic? 0
  • +

Replies To: Sendkeys send before window open

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1067
  • View blog
  • Posts: 4,176
  • Joined: 02-July 08

Re: Sendkeys send before window open

Posted 17 January 2013 - 12:27 PM

SendKeys is notorious for being inconsistent. Me.Refresh is activating your form and is after you are trying to activate putty - could be the problem.
Was This Post Helpful? 0
  • +
  • -

#3 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Sendkeys send before window open

Posted 17 January 2013 - 12:29 PM

View Postswiftvb_5, on 17 January 2013 - 01:09 PM, said:

I am writing a program that uses putty to telnet to a printer so I can set the ip,subnet mask, default gateway.

The problem that I get is that when I use sendkeys to the putty window, It will send it before the window is open. Also It seems to send even if putty is open but sends the sendkeys to the window behind it. Ive tried thread.sleep, me.refresh, application.doevents,appactivate, waitforeinputidle, anything to the delay the send.


There's a library available on SourceForge that might do the trick for you. If I remember correctly, the main prblem with trying to use Windows putty is that it opens in a window and doesn't use stdin/out that could otherwise have been redirected to/from your program.
Was This Post Helpful? 1
  • +
  • -

#4 swiftvb_5  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-January 13

Re: Sendkeys send before window open

Posted 17 January 2013 - 02:42 PM

Thanks for your help, could this be done more effectively in C++ or C# or using another program instead of putty?
Was This Post Helpful? 0
  • +
  • -

#5 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Sendkeys send before window open

Posted 18 January 2013 - 06:37 AM

View Postswiftvb_5, on 17 January 2013 - 03:42 PM, said:

Thanks for your help, could this be done more effectively in C++ or C# or using another program instead of putty?

The library in that link is written for .Net, and should be all you need to use either VB.Net or C#
I don't use C#, but from what I hear, either that or VB.Net are pretty much equally effective for working with the .Net Framework.

There's also a program or library called ExtraPutty that is said to be easier to use than putty, though I have not looked into it betpnd noticing it.
Was This Post Helpful? 0
  • +
  • -

#6 swiftvb_5  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-January 13

Re: Sendkeys send before window open

Posted 18 January 2013 - 10:24 AM

View Postlar3ry, on 18 January 2013 - 06:37 AM, said:

View Postswiftvb_5, on 17 January 2013 - 03:42 PM, said:

Thanks for your help, could this be done more effectively in C++ or C# or using another program instead of putty?

The library in that link is written for .Net, and should be all you need to use either VB.Net or C#
I don't use C#, but from what I hear, either that or VB.Net are pretty much equally effective for working with the .Net Framework.

There's also a program or library called ExtraPutty that is said to be easier to use than putty, though I have not looked into it betpnd noticing it.



I will definitely try that library, but I also found another of setting the IP,subnet,gateway. The printer comes with a web interface. I had my friend who is a web developer show how to automate changing the ip, gateway...thru the web interface of the printer. I used curl for this.

Shell("cmd.exe /k curl  --data " & ChrW(34) & "ipv4config_type=Manual&IPv4_InternetAddress=192.168.1.3&secret=&IPv4_NetMask=255.255.255.0&IPv4_DefaultRouter=192.168.1.1&Apply=Apply" & ChrW(34) & " http://192.168.1.2/tcpipv4.htm/config")



Again,

Thanks for your help.
Was This Post Helpful? 0
  • +
  • -

#7 swiftvb_5  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-January 13

Re: Sendkeys send before window open

Posted 18 January 2013 - 11:46 AM

Ok,

Ive downloaded the .NET Telnet 1.0, It comes with a Telnet.dll and TestClient.exe. I don't know where to put the dll file. The documentation is weak. Ive googled for tutorials or examples of how to use this class? All I found was other .net paid telnet clients. How do I open a connection or send a command.

Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1