Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To 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 January 22nd, 2007, 12:31 PM
Authorized User
 
Join Date: Dec 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to execute a VBScript file from a VB6 subrouti

Hello,
I was wondering if anyone could share with me the VB6 code that would execute a VBScript file named
test.vbs
in the subdirectory
D:\testthanks in advance,
david

 
Old January 23rd, 2007, 12:36 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 221
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello

Set oShell = CreateObject("WScript.Shell")
oshell.Run "D:\Raghavendra_MS\RandD\NEW\WshShell_Object_Examp le\hm1.vbs"

Hope this helps

With Regards,
Raghavendra Mudugal
 
Old January 25th, 2007, 06:25 PM
Authorized User
 
Join Date: Dec 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Raghavendra,
I'm using your code:
Code:
Set oshell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
oshell.Run "D:\test\test.vbs"
and I'm getting the error:
run-time error "-2147024894 (80070002)":
Method 'Run' of object "IWshShell3' failed
and the code stops on the oshell.Run line

Why is there error happening and how do I fix it?
thanks in advance,
david

 
Old January 27th, 2007, 05:23 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 221
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello David (sorry in delay to reply)

The component i am using here is wscript.exe on windows 2000 professional

Name:Microsoft (r) Windows Based Script Host
Ver: 5.6.0.6626

Some points:
1) check that "test.vbs" script file is executing properly by itself (Standalone)
you can check this double clicking on the file and it executes.
2) If it executed as desired, then check with component version in the system folder and its proper registration in the registry base.
3)If #1 failed, check the code for errors, what causing the execution to through error.

Because this component comes by the operating system itself, and you don't have install as a third party, and this component is running successful from Y2001.
So, check this and tell me as soon, will look it here, if any. and let me know which ver is that component and what os you are running (but this should not be an issue).

hope this helps and gives some idea.

With Regards,
Raghavendra Mudugal
 
Old January 29th, 2007, 11:20 AM
Authorized User
 
Join Date: Dec 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hello,
thanks for the assistance.
Yes, the .vbs does execute fine if you run it from File Explorer.
I got the VB script execution code to work with some help from another person on another message board. Below's the functioning code:

[code]
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
                   (ByVal hwnd As Long, ByVal lpszOp As String, _
                    ByVal lpszFile As String, ByVal lpszParams As String, _
                    ByVal LpszDir As String, ByVal FsShowCmd As Long) _
                    As Long

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub RunScriptFile()

Const SW_SHOWNORMAL = 1

ShellExecute 0&, "Open", "D:\B D client data\PRTC\PRTCFTPtoDAKCS&DeleteACK.vbs", "", "D:\B D client data\PRTC\", SW_SHOWNORMAL

End Sub
[\code]

 
Old January 30th, 2007, 12:50 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 221
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ShellExecute Or ShellExecuteEx, these to functions can be used not only on scripts but also on exe files and documents(any). So when you are executing a script file, in generally scripting object's functionality is used to fulfill the need. I guess, the problem lies in that component registry, may be if you reinstall it, might get the error fixed.

Anyway, your problem had got different solution now, and its working. :)

With Regards,
Raghavendra Mudugal





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to Execute a file during setup akhilesh_g Pro VB 6 3 January 22nd, 2008 03:20 PM
Execute Oracle Procedure in VBScript JunoFS Oracle 0 September 12th, 2007 10:18 AM
Execute a File arunmohanmp Perl 1 June 19th, 2006 06:23 AM
Cron Jobs - Execute File itHighway Beginning PHP 0 November 20th, 2005 10:52 PM
Execute .exe file and terminate it Wayang_Mbeling Classic ASP Basics 9 October 18th, 2005 02:42 AM





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