user3335078
user3335078

Reputation: 85

Vbscript. How do you sendkeys to a SWbemObject?

I feel like this should be easy, but I haven't figured it out yet.

I have an executable that is already running when I run my vbscript. I want to find the executable and call sendkeys to give it input.

Here is what I have so far:

dim service, Process, myObject

set service = GetObject ("winmgmts:")

for each Process in Service.InstancesOf ("Win32_Process")
    if Process.Name = "abc.exe" then
        myObject = Process
    end if
next
myObject.SendKeys "This is a test."

This doesn't work, but I think it would look similar to this. I basically just want to sendkeys to myObject.

NOTE: I do not want to run a new instance of abc.exe, I want to send input to the one that is already running

Upvotes: 0

Views: 1176

Answers (1)

Rich
Rich

Reputation: 4170

You are trying to activate a wscript submethod(sendkeys) off of a process, this does not have a sendkeys submethod. Try the "App Activate" submethod off of the wscript shell....

Set objShell = WScript.CreateObject("WScript.Shell")
Do Until Success = True
    Success = objShell.AppActivate("ABC")
    Wscript.Sleep 1000
Loop
objShell.SendKeys "This is a test."

Reference

Upvotes: 1

Related Questions