Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to use external application with Javascript and WSH

Posted on 2007-12-05
10
Medium Priority
?
1,238 Views
Last Modified: 2012-05-05
Hi,

  I would like to know how to use an external application like getting field info, cliking on button, menu etc.. with Javascript and WSH unless it can be done with something else that does not require a licensing fee.

Thank you
0
Comment
Question by:Dogofwars
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 15

Expert Comment

by:bpmurray
ID: 20414840
External to what? Do you mean a standalone app? If so, perhaps using HTC/HTA is a good solution, if all you want is a Web UI.  Have a look at http://msdn2.microsoft.com/en-us/library/ms536496.aspx and http://www.microsoft.com/technet/scriptcenter/hubs/htas.mspx.

You could also try SilverLight.

If you don't want too fancy a UI, then WSH is easy to use.
0
 

Author Comment

by:Dogofwars
ID: 20415229
I don't need a really fancy UI, all I need is a way to get the information I need from few field in an application. By that I need to click on certain button in the application that use a database of client. I do not have access to the database itself but I do have access to the information from the application. Anyhow I have a list of account number and than I need to lookup every account one by one and get the amount of balance of every account. I use javascript, I saw that there is the WSH but I do not find any goot example in doing that other than opening an application and sending key message to the app.
0
 
LVL 15

Expert Comment

by:bpmurray
ID: 20415411
OK, now I understand - you want to automate a local application and retrieve information from the fields, often referred to as UI Automation.

Unfortunately, I'm in a rush right now, so I can't spend any time on this. However, have a look at these examples - they may help direct you to the correct result: http://www.scala.com/advancedscripting/infochannel3/vbjscript.html

0
What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

 

Author Comment

by:Dogofwars
ID: 20424755
Ok I'll wait for your reply
0
 

Author Comment

by:Dogofwars
ID: 20444767
Anybody to explain how it work
0
 
LVL 15

Expert Comment

by:bpmurray
ID: 20452825
It's really difficult to guess what your app has, but this is something that launches an app (here, calculator), finds its window and brings it to the top, and presses a bunch of keys to emulate playing with your app.
'********* CHANGE THIS STUFF BELOW **********
Const APPLICATION_NAME = "C:\Windows\System32\calc.exe"
Const WINDOW_TITLE = "Calculator"
'********* CHANGE THIS STUFF ABOVE **********
 
' Start the application
Set objShell = CreateObject("WScript.Shell")
objShell.Run APPLICATION_NAME, 1, False
 
' Grab the window, using the window's title
isAppRunning = False
Wscript.Sleep 200 'Make sure it's running
Do While isAppRunning = False
   isAppRunning = objShell.AppActivate(WINDOW_TITLE)
Loop
Wscript.Sleep 200 'Make sure it's pulled to the front.
 
'********* CHANGE THIS STUFF BELOW **********
' Now send keys to the app
objShell.SendKeys "2{+}2{+}2=" ' Should show "6" in the screen
objShell.SendKeys "+{Home}"    ' Highlight the answer (Shift-Home)
objShell.SendKeys "^C"         ' Copy to the clipboard (CTRL-C)
 
' We're finished so quit
Wscript.Sleep 2000 ' Wait so we can see that it's correct
objShell.SendKeys "%{F4}"      ' Exit (Alt-F4)

Open in new window

0
 

Author Comment

by:Dogofwars
ID: 20453316
IS there a way to get a field like for instance after it has done the calculation can you get the result, it's really important to do so otherwise I cannot probe the database through the interface. Thank you so far.
0
 
LVL 15

Accepted Solution

by:
bpmurray earned 2000 total points
ID: 20453846
Unless you give a lot more detail, it's pretty much impossible to guess the correct solution. The code above illustrates how to start the application, input the data into the appropriate fields and cause the correct result to be displayed. Have you managed to make that happen? If so, you can now copy the data from the result field (or fields) into a file, and then read the contents of that file. It's not elegant, but it'll work - the main problem being that WSH doesn't have any clipboard support. Here's a little more detail:

'********* CHANGE THIS STUFF BELOW **********
Const APPLICATION_NAME = "C:\Windows\System32\calc.exe"
Const WINDOW_TITLE = "Calculator"
'********* CHANGE THIS STUFF ABOVE **********
 
Set objShell = CreateObject("WScript.Shell")
 
' Start the application
RunApp APPLICATION_NAME, WINDOW_TITLE
 
'********* CHANGE THIS STUFF BELOW **********
' Now send keys to the app
objShell.SendKeys "2{+}2{+}2=" ' Should show "6" in the screen
objShell.SendKeys "+{Home}"    ' Highlight the answer (Shift-Home)
objShell.SendKeys "^C"         ' Copy to the clipboard (CTRL-C)
 
' We're finished so quit
objShell.SendKeys "%{F4}"      ' Exit (Alt-F4)
 
' Now start Notepad to copy the data to a file
RunApp "notepad.exe", "Notepad"
objShell.SendKeys "^V"         ' Paste the content
objShell.SendKeys "%FAC:\work.txt" ' File/Save As/filename
objShell.SendKeys "%S"         ' Save
objShell.SendKeys "%{F4}"      ' Exit (Alt-F4)
 
' Read the data from the file
Const OpenFileForReading = 1
Set fso = CreateObject("Scripting.FileSystemObject")
Set textStream = fso.OpenTextFile("c:\work.txt", OpenFileForReading, True)
MyResults = textStream.ReadAll
textStream.Close
FSO.DeleteFile("c:\test.txt")
 
 
MsgBox MyResults,0,"Results field contents"
 
' Launch the application & bring it to the foreground
Sub RunApp(ApplicationName, Title)
   objShell.Run ApplicationName, 1, False
   isAppRunning = False
   Wscript.Sleep 200 'Make sure it's running
   Do While isAppRunning = False
      isAppRunning = objShell.AppActivate(Title)
   Loop
   Wscript.Sleep 200 'Make sure it's pulled to the front.
End Sub

Open in new window

0
 

Author Comment

by:Dogofwars
ID: 20454146
I guess you have no way to specify a field directly than!?
0
 
LVL 15

Expert Comment

by:bpmurray
ID: 20458637
Not by name, but you can use a number of mechanisms to drill down to the field: number of tabs, accelerator key, etc. If you know the application, you can simply track (exactly) what it takes to do this manually and then transpose that to the automation in your script.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question