【问题标题】:Visual Studio - How to inject textbox text into an external application?Visual Studio - 如何将文本框文本注入外部应用程序?
【发布时间】:2023-03-12 09:30:01
【问题描述】:

我正在尝试构建一个在 IBM i (AS400) 上运行的应用程序。到目前为止,我可以让应用程序打开并登录,但我正在寻找一个动态解决方案,而不是使用静态发送密钥

Imports System.Threading
Public Class Form1
Dim a As New Process
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    a.StartInfo.FileName = "C:\Program Files\reflection\default scripts\as400.rsf"
    a.Start()
    Thread.Sleep(3000)
    SendKeys.SendWait("UserID {TAB}")
    Thread.Sleep(1000)
    SendKeys.SendWait("Password {Enter}")
End Sub
End Class

我可以运行一个宏,它会显示一个输入密码的弹出框

Sub Macro1()
'
' Generated by the Reflection Macro Recorder on 03-18-2015  13:03:31.50
' Generated by Reflection for IBM for Windows 8.00
'
With Session
    Dim hostpassword As String

    .WaitForEvent rcEnterPos, "30", "0", 6, 53
    .WaitForDisplayString ".", "30", 6, 49
    .TransmitANSI "USERID"
    .TransmitTerminalKey rcIBMTabKey

    hostpassword = "PASSWORD"
    .TransmitANSI hostpassword
    .TransmitTerminalKey rcIBMEnterKey
End With
End Sub

我不能只是将它复制并粘贴到 Visual Studio 中并让它以这种方式工作。所以我的问题是如何让文本框将输入的内容注入外部应用程序的命令行?我已经进行了大量的研究,但是我发现的大多数内容都不适用于我正在尝试的内容,因为我发现的每个教程都主要针对 MS Office,Excel。有人可以指出我正确的方向吗?

【问题讨论】:

    标签: visual-studio ibm-midrange sendkeys inputbox


    【解决方案1】:

    请参阅Host Access Class Library Automation Objects

    这是我多年前编写的用于重新连接会话的示例 VB 脚本:

    Option Explicit
    Dim autECLConnList As Object
    Dim i As Integer
    
    Set autECLConnList = CreateObject("PCOMM.autECLConnList")
    autECLConnList.Refresh
    If autECLConnList.Count > 0 Then
        For i = 1 to autECLConnList.Count
            If autECLConnList(i).CommStarted Then
                autECLConnList(i).StopCommunication()
            End If
            autECLConnList(i).StartCommunication()
        Next
    End If
    

    【讨论】:

      【解决方案2】:

      感谢您的回复,但是当程序打开并登录时我没有任何连接问题,我只是想弄清楚如何将文本从表单中获取到 AS400 中,但我没有意识到解决方案就是这么简单,我很惊讶没有人回答,或者他们在等我自己解决

      Imports System.Threading
      Public Class Form1
      
      Dim a As New Process
      
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          a.StartInfo.FileName = "C:\Program Files\reflection\default scripts\as400.rsf"
          a.Start()
          Thread.Sleep(1000)
          SendKeys.SendWait(TextBox1.Text)
          Thread.Sleep(1000)
          SendKeys.SendWait("{TAB}")
          Thread.Sleep(1000)
          SendKeys.SendWait(TextBox2.Text)
          Thread.Sleep(1000)
          SendKeys.SendWait("{ENTER}")
      End Sub
      End Class
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-11-25
        • 2012-12-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-31
        • 2013-03-07
        相关资源
        最近更新 更多