Solved

creating "winbatch" type batches

Posted on 2001-09-10
6
289 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
Comment Utility
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
Comment Utility
By the way, i don't know what is "winbatch"...sorry.
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 50 total points
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
"...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
Comment Utility
>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
Comment Utility
thank you very much.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now