Solved

creating "winbatch" type batches

Posted on 2001-09-10
6
290 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

895 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

11 Experts available now in Live!

Get 1:1 Help Now