0

I'm trying to make automation using vbs and I'm wondering if it possible to build some simple gui with file chooser (or couple of them)? Googling didn't help me here.

I need this not to hardcode some input parameters of the script.

The original problem is ssh commands automation. I'm using XShell (ssh client) vbs scripts for this now, but I have to hardcode parameters everytime I use it. It would be better if I can just type ip/choose file, instaed of editing script.
Maybe it worth to consider any other ways of automation and if anybody can suggest any tools to automate sending ssh commands to remote server it would be great!

Thank you all in advance!

mr.nothing
  • 5,141
  • 10
  • 53
  • 77
  • Even if you could, it's going to be a world of pain. Why not using something more suited to the task? Python springs to mind. – David Heffernan Jan 11 '13 at 12:42
  • @DavidHeffernan, the thing is that i'm using XShell ssh client to connect to linux machines and it uses vbs for automation (Python is great instrument, but not applicable here, unfortunately). Maybe it worth to consider any other ways of automation. Can you suggest any tools to send ssh commands to remote server? Thanks. – mr.nothing Jan 11 '13 at 12:46
  • Python can do COM automation just the same as VBS. Your automation is not tied to VBS. – David Heffernan Jan 11 '13 at 13:01
  • @DavidHeffernan, I need tool to automate ssh commands, which senвы these commands from windows to linux server. I don't see any way of how python can be applied here (besides writing new python based ssh application). For now I'm using Xshell ssh client + vbs as such a tool. But I have to hardcode parameters of vbs scripts everytime I launch them. – mr.nothing Jan 11 '13 at 13:15
  • The vbs automation of Xshell can be done from Python. Anything you can do in vbs can be done in any other language that does COM automation. You are not tied to vbs. But in any case, you can still do it in vbs if you made your vbs script accept parameters. Stop hard-coding things. Read params and it's all good. – David Heffernan Jan 11 '13 at 13:20
  • 1
    you might be able to use VBScript in an [HTA](http://msdn.microsoft.com/en-us/library/ms536473(v=vs.85).aspx)? –  Jan 11 '13 at 14:16
  • Check [this WSH VBS GUI](https://stackoverflow.com/a/47111556/2165759) solution. – omegastripes Nov 09 '17 at 15:17

3 Answers3

4

For people who know HTML it's very viable to write GUIs controled by VBScript (or any other ActiveScript language: Perl, Python, Ruby, JScript, ...). The technique is called HTML Application (HTA) and there is even a wizard/designer (of mediocre quality).

While command line VBScripts are hosted by C/WScript.exe, HTAs are browser (i.e. IE) based. That is not aproblem if you can do the SSH work via shelling out or COM objects. But Mr. Nothing's SSH client seems to be a console style application that hosts/uses VBScript code internally; in this case HTA is no option. OTOH: If - as "I need this not to hardcode some input parameters of the script" seems to indicate - the real work is done by starting VBScript scripts, then selecting/constructing parameters for such scripts in a HTA GUI should be easy (for HTML savvy people).

Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
2

Writing a GUI in VBScript is not really viable. No doubt it's possible, but there aren't any toolkits that make it easy. It's not what VBScript was designed for.

There are a number of options that occur to me:

  • Write your GUI in another language, whatever you fancy. Then send commands to your VBscript code as command line arguments. That's the easiest option for you. All you need to do is write the GUI, and replace your hard-coded values in the VBscript code with some code that pulls values off the command line.
  • Do the COM automation of Xshell in a different language that supports COM automation. The majority of languages do. And write the GUI there too. For example, Python would be my choice.
  • Switch wholesale to a different language for both GUI and your ssh code. Again many languages exist with good modules for ssh.
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Thanks for your patience, David! Could you, please, provide some links with clarification of COM automation and exmaples of how Python or, maybe, Perl can be used here. – mr.nothing Jan 11 '13 at 14:11
  • There's lots of examples on the web. Here's one for automating Excel: http://excelicious.wordpress.com/2009/05/09/why-id-like-python-at-work-part-2/ Having said all that, the Xshell vbscript appears a bit odd. It looks like the scripts run inside the Xshell GUI. To be perfectly honest with you, Xshell doesn't look like such a great option to me. – David Heffernan Jan 11 '13 at 14:43
1

Most of the problems involved with creating a VBScript UI is it lack of an event driven programming model. I have gotten past this problem by using Javascript and Internet Explorer events.

Declare the Internet Explorer object like below to enable events.

Set oIE = WScript.CreateObject("InternetExplorer.Application", "oIE_")

Declare the quit event like below. In this event quit the script.

Sub oIE_onQuit 

Declare the TitleChange event like below. In this event you will handle all the UI functions.

Sub oIE_TitleChange(text)

In the html the buttons that you want to trigger an even must have a javascript to change the title.

document.title = document.title;

Here is a link to the full source code.

Threekill
  • 189
  • 7