Link to home
Start Free TrialLog in
Avatar of DDB
DDBFlag for United States of America

asked on

Needed References for WScript

Hello,

Which reference I need to use in VB6 for this code

Dim WshShell  As Object
Set WshShell = WScript.CreateObject("WScript.Shell")

'WScript object used to echo information
WScript.Echo "Hello World!" 'VBScript
WScript.Echo ("Hello World!") 'JScript

'WScript object used to terminate scripts
WScript.Quit


I am getting run-time error 424 object required.

thanks in advance,
ddb
Avatar of wraith821
wraith821

Windows Script Host Object Model
"Windows Script Host Object Model"

HTH,
Lynn
I thought the same as the previous suggestions, but I continue getting the error after selecting it as a reference -- Microsoft Scripting Runtime does not work either.

Is the code incorrect?
wscript.echo doesn't work in Visual Basic... it is for VBScript only... use MsgBox instead
>>>  it is for VBScript only. <<<  I should have said for script only (it works for Javascript, also).  Additionally, wscript.quit isn't for Visual Basic either... your app will terminate naturally after it executes the last line of your "Sub Main()", or you unload the main form.

-- Lynn
Avatar of DDB

ASKER

Sorry I brought some confusion.  Let say in VB6 the folloing code give 424  errorr:

Dim WshShell  As Object
Set WshShell = WScript.CreateObject("WScript.Shell")

 
Avatar of DDB

ASKER

Also,

Could you please give me not only the name but file name with extention so I could look uit up on my pC.

Thanks, ddb
Given the short example you cited, here is the proper syntax for VB6 (note it's slightly different from the VBScript syntax)

     Dim WshShell As Object
     Set WshShell = CreateObject("Wscript.Shell")

Here is an example of using the object just created to execute another program...

     WshShell.Run("SomeProg.exe")

I believe there maybe more than one dll involved in Windows Scripting Host... here is a link to Microsoft's site where you can download the most recent version:   http://msdn.microsoft.com/library/default.asp?url=/downloads/list/webdev.asp

I know that one of the dll's is scrrun.dll

If you're running XP, or if you have IE 6 installed, then WSH 5.6 (the latest version) is already installed.

HTH,
Lynn
Avatar of DDB

ASKER


 Yesterday I updated my Scripting library just like you suggested( I have W2K). I also have references to scrrun.dll which is Microsoft scripting Runtime library and I added all possible DLLs that I have for Windows scripting in VB reference box and nothing helps, I still getting this error.
Coule you please list a larger section of your code relevant to this problem and all the references you have set?  I think I might be guessing too much about the actual code being used.

In the meantime, here is a test script to see if your WSH is installed properly...

''' Save this file as "TestMe.vbs"
'''
''' Then, run it like this:  cscript testme.vbs from a command prompt
'''
Source  = "C:\"
BatFile = "C:\___RunMe.BAT"
Cmnd    = "DIR /ad " & Source

  Set oFSO     = CreateObject("Scripting.FileSystemObject")
  Set oBatFile = oFSO.CreateTextFile(BatFile)
  Set oShell   = CreateObject("Wscript.Shell")

  oBatFile.WriteLine Cmnd
  oBatFile.WriteLine "pause"
  oBatFIle.Close

  oShell.run BatFile,,True


If the above script works properly, it will open another command prompt window then display all the directory names in the root folder of your "C" drive and pause waiting for you to press ENTER.

HTH,
Lynn
Avatar of DDB

ASKER

 I got error for your code on this line.

  Set oShell   = CreateObject("Wscript.Shell")

 Automation error. The specified procedure could not be found

The refernces that I had:

Microsoft Scripting Runtime
Microsoft VBScript Regular Expression 5.5
Microsoft Script Control 1.0
Microsoft Shell Controls and Automation
WSHControllerLibrary
Windows Script Host Object Model

thank you for your time and help!

If you got that error running the TestMe.vbs code then it sounds as if WSH isn't properly installed.  Try uninstalling it (see the link below for how-to instructions), then reinstall it.  Be sure to use the installation package that should be part of the official Microsoft download... there are some other sites packaging just the dll's which then must be manually registered).

   http://www.superiornet.net/security/archive/scripthosting.htm

When this is complete, retry the TestMe.vbs script again to see if it now works.

BTW, you seem to have all the VB References you need (perhaps some you don't need, too) so that part of the equation seems ok.

-- Lynn
ASKER CERTIFIED SOLUTION
Avatar of Burbble
Burbble
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
lol. Guess it worked.