Solved

creating "winbatch" type batches

Posted on 2001-09-10
6
291 Views
Last Modified: 2008-03-06
is it possible to create batch programs, similar to what winbatch can do, in VB6?

for example launch an application from the shell and operate it from VB6; move the mouse, choose menu items,...,do user type of actions.

a simple example would be: from VB6 open internet explorer browser, call hotmail.com, send a message, close IE. Winbatch does that but I was wondering if I could do it from VB6 instead? thank you
0
Comment
Question by:lorynthia
  • 3
  • 2
6 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6472485
This could be done using microsoft html object library.
I did a little app to put password/user in hotmail and go directly to inbox folder:

VERSION 5.00
Begin VB.Form frmHotmail
   Appearance      =   0  'Flat
   BackColor       =   &H80000004&
   Caption         =   "Hotmail login"
   ClientHeight    =   1290
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   3660
   Icon            =   "frmHotmail.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   1290
   ScaleWidth      =   3660
   StartUpPosition =   2  'CenterScreen
   Begin VB.PictureBox Picture1
      Appearance      =   0  'Flat
      AutoSize        =   -1  'True
      BackColor       =   &H80000005&
      ForeColor       =   &H80000008&
      Height          =   525
      Left            =   2100
      Picture         =   "frmHotmail.frx":08CA
      ScaleHeight     =   495
      ScaleWidth      =   1350
      TabIndex        =   5
      Top             =   1680
      Width           =   1380
   End
   Begin VB.CommandButton Command1
      Caption         =   "&Logon"
      Enabled         =   0   'False
      Height          =   375
      Left            =   2340
      TabIndex        =   4
      Top             =   840
      Width           =   1215
   End
   Begin VB.TextBox Text1
      Height          =   315
      IMEMode         =   3  'DISABLE
      Index           =   1
      Left            =   900
      PasswordChar    =   "*"
      TabIndex        =   3
      Top             =   420
      Width           =   2715
   End
   Begin VB.TextBox Text1
      Height          =   315
      Index           =   0
      Left            =   900
      TabIndex        =   1
      Top             =   60
      Width           =   2715
   End
   Begin VB.Label Label1
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "Password:"
      Height          =   195
      Index           =   1
      Left            =   60
      TabIndex        =   2
      Top             =   420
      Width           =   735
   End
   Begin VB.Label Label1
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "Username:"
      Height          =   195
      Index           =   0
      Left            =   60
      TabIndex        =   0
      Top             =   60
      Width           =   765
   End
End
Attribute VB_Name = "frmHotmail"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim WithEvents IE As InternetExplorer
Attribute IE.VB_VarHelpID = -1
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Const SW_MAXIMIZE = 3

Private Sub Command1_Click()
IE.navigate "www.hotmail.com"
End Sub

Private Sub Form_Load()

Set IE = New InternetExplorer
With IE
    .Visible = True
    .navigate "about:blank"
    ShowWindow .hwnd, SW_MAXIMIZE
    Do While .Busy <> False
        DoEvents
    Loop
    Command1.Enabled = True
End With
End Sub



Private Sub IE_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is IE) Then
    On Error Resume Next
    Dim HDoc As HTMLDocument
    Dim txt As HTMLInputElement
    Set HDoc = IE.document
    If InStr(1, URL, "passport.com/cgi-bin/login", vbTextCompare) Then
        For Each txt In HDoc.body.All
            Select Case UCase$(txt.Name)
            Case "LOGIN"
                If Text1(0).Text = "" Then
                    txt.Value = "anonymous"
                Else
                    txt.Value = Text1(0).Text
                End If
            Case "PASSWD"
                If Text1(1).Text = "" Then
                    txt.Value = "pwd"
                Else
                    txt.Value = Text1(1).Text
                End If
            Case "ENTER"
                txt.Click
                Exit For
            End Select
        Next
    Else
        Dim HAnchor As HTMLAnchorElement
        For Each HAnchor In HDoc.body.All
            If UCase$(HAnchor.innerText) = UCase$("inbox") Then
                HAnchor.Click
                Unload Me
            End If
        Next
    End If
   
End If
End Sub
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6472493
By the way, i don't know what is "winbatch"...sorry.
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 50 total points
ID: 6472498
You can do these things, but VB is more geared to creating components and standalone applications than to manipulating other applications, so it isn't always easy.  It generally requires a fair amount of knowledge of Windows API programming to be able to manipulate other programs successfully.

The other main difference between a programming language like VB and a scripting language like Winbatch is that a VB program must be compiled to an executable format to run.  Winbatch scripts are just text files that are interpreted by the winbatch executable which does all the heavy lifting.  

Windows has it's own scripting language, VBScript.  It is fairly limited in what you can do with it in terms of manipulating other programs, but you can extend it with components you create in VB.  Not necessarily easy to do, but possible.

Ultimately, you could even write your own version of Winbatch using VB, but this is a major undertaking.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6473079
"...It is fairly limited in what you can do with it
in terms of manipulating other programs..."
Paul, vbscript is a powerfull scripting language, you could manipulate COM-aware apps just LIKE (note like in uppercase) VB.
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6473158
>you could manipulate COM-aware apps just LIKE (note
like in uppercase) VB.<


Yes, but that requires them to be COM aware.  There are so many programs that aren't.  The main problem in VBScript is no access to the API.  Sending messages to windows using the API, manipulating a windows position, simulating key strokes and menu clicks, this can be done in VB, but not in VBScript.  If you've ever used Winbatch, then you know it allows this kind of macro-like action, but not in VBScript.  

You are right that you have a fair amount of control over the main Microsoft products and a few others that have adopted exposing an object hierarchy through COM.
0
 

Author Comment

by:lorynthia
ID: 6506704
thank you very much.
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

809 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