Wrox Programmer Forums
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 28th, 2007, 05:19 PM
Authorized User
 
Join Date: Jun 2003
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default Translating VBScript in VB

Hi,

Was wondering if it is easy to 'migrate' VBScript code to VB? Currently I have written an automatic installation procedure (like install SQL, then Java, then Office etc) in VBScript. This works fine and I'm using an IE explorer window to display the progress. However, since the script is critical and there isn't that much you can do with the IE page container, I was planning to do this in VB (form control is a lot better). But since I'm not that experienced in VB, I already ran in the following:

Where e.g. the Script uses (from WScript.Shell):
Shell.Run "notepad.exe", 0, True
VB instead uses Shell "notepad.exe" but without that many parameters where True states the script waits for execution until the application is out of the computer's memory.

It annoys me that this looks all very straightforward, but the syntax and logic (VBScript for procedures vs VB for logicc) is just so different.

So what I want to do is:

1. Display a form
2. Put on a label "Installing MS Office" while using the installation parameters in silent mode.
3. Once office is installed, put on a new label "Installing Java" while using parameters in silent mode.
4. and so on ..

So the form only has the purpose to display the installation progress.

Or should I just forget about it.

Your help is appreciated.

Sebastiaan.
 
Old June 28th, 2007, 06:14 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

I don't think you should forget about it. It is going to be a little tougher, to be sure, but you're going to like the results. And it will be stable, easily modifiable, and so on.

I think you are going to want to use CreateProcess and WaitForSingleObject APIs.

You'll have to search around a little for more details, but the brief looking I have just done myself turned up
Code:
  if(CreateProcess("c:\\winnt\\notepad.exe", NULL, 
      NULL,NULL,FALSE,0,NULL,
      NULL,&StartupInfo,&ProcessInfo))
  { 
      WaitForSingleObject(ProcessInfo.hProcess,INFINITE);
      CloseHandle(ProcessInfo.hThread);
      CloseHandle(ProcessInfo.hProcess);
  }  
  else
  {
      MessageBox("The process could not be started...");
  }
  Translated to VB this should be like
Code:
    Dim ProcessInf As ProcInfoType  ' I'm not sure the parts of this type
Code:
    Dim StartUpInf As StrtInfoType  ' I'm not sure the parts of this type

    If CreateProcess("""c:\winnt\notepad.exe""", , , , False, 0, , , _
                     StartUpInf, ProcessInf)

        ' Fill in your form here;  the process started.
        WaitForSingleObject(ProcessInfo.hProcess,INFINITE);
        CloseHandle(ProcessInfo.hThread);
        CloseHandle(ProcessInfo.hProcess);

    Else

        MsgBox "The process could not be started..."

    End If
    You will need to declare the types and the three API routines CreateProcess(), WaitForSingleObject() and CloseHandle().





Similar Threads
Thread Thread Starter Forum Replies Last Post
Translating WorkSheet Formula in VBA AndyL Beginning VB 6 2 June 11th, 2008 04:13 AM
translating XML into CSV file vxc2222 XSLT 1 December 29th, 2007 12:01 PM
Translating si function to HTML mcw22 Javascript How-To 1 October 27th, 2007 09:43 AM
Translating symbols to their unicode values Pankaj C XSLT 24 September 11th, 2007 03:35 AM
Translating graphics to text faridahhani Pro PHP 1 July 2nd, 2003 02:37 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.