VBScript from VBA excel / wshShell.Run failed, error 80070483

R

rhXX

hi,

i am trying to run a vb script from a VBA module in excel.

fn = "test.vbs
Set wshShell = CreateObject("Wscript.Shell")
wshShell.Run (fn)

in the line wshShell.Run (fn) i obtain an error error 80070483

method Run of object IWshShell3 failed

it is the first time i do this, so i am not shure if i need to have
done something before, some references???

in windows extension .vbs is not related to any application (is it
ok???)

tks in advance
 
G

Guest

Maybe its just the path:

Sub samples()
fn = "C:\hithere.vbs"
Set wshShell = CreateObject("Wscript.Shell")
wshShell.Run (fn)
End Sub


works just fine.
 
R

rhXX

Maybe its just the path:

Sub samples()
fn = "C:\hithere.vbs"
Set wshShell = CreateObject("Wscript.Shell")
wshShell.Run (fn)
End Sub

works just fine.

tks, but i think there is other problem

my sub is:

Sub bypass()
fn = "c:\tmp\bypass.vbs"
Set fso = CreateObject("Scripting.FileSystemObject")

Set fsoFile = fso.CreateTextFile(fn)
fsoFile.WriteLine "Set fso = CreateTextFile(""c:\tmp
\toto.txt"")"
fsoFile.WriteLine "fsoFile.WriteLine ""Hello world"""
fsoFile.WriteLine "fsoFile.Close"

fsoFile.Close

Set wshShell = CreateObject("Wscript.Shell")
wshShell.Run (fn)

End Sub

the bypass file was created ok:

Set fso = CreateTextFile("c:\tmp\toto.txt")
fsoFile.WriteLine "Hello world"
fsoFile.Close

the error is in the line

wshShell.Run (fn)

and the file toto.txt, wich must be created by the vbscript was not
created

question: when i try to run the vbscript by hand, it does not run
because .vbs extension is NOT associated by any application. is this
ok????

tks in advance
 
G

Guest

Not O.K.
from any folder:
Tools > Folder Options > File Types
and then register .vbs with the Microsoft (r) Windows Based Script Host
 
S

Steve Yandl

If you're not needing the "WScript.Shell" object for any other reason than
launching your vbs file, you could just use the 'Shell' function within VBA.
Either way, you need to launch either WScript.exe or CScript.exe and pass
the path to your vbs file to the executable as an argument rather than
trying to "run" the vbs file.

Steve Yandl
 
R

rhXX

If you're not needing the "WScript.Shell" object for any other reason than
launching your vbs file, you could just use the 'Shell' function within VBA.
Either way, you need to launch either WScript.exe or CScript.exe and pass
the path to your vbs file to the executable as an argument rather than
trying to "run" the vbs file.

Steve Yandl

Not O.K.
from any folder:
Tools > Folder Options > File Types
and then register .vbs with the Microsoft (r) Windows Based Script
Host
--
Gary''s Student - gsnu200730


gary / steve, tks a lot!

gary after i sent the mail, i tested to register .vbs with some
program, i found .vbe, and i done "an equivalent not encoced"

VBScript Script File
open: C:\WINDOWS\System32\WScript.exe "%1" %*

and worked fine!

i will check Microsoft (r) Windows Based Script Host

steve, i like more ur method, so is indepent from any previus
register. i will check now

tks again to all!!!
 
G

Guest

rhXX said:
gary / steve, tks a lot!

gary after i sent the mail, i tested to register .vbs with some
program, i found .vbe, and i done "an equivalent not encoced"

VBScript Script File
open: C:\WINDOWS\System32\WScript.exe "%1" %*

and worked fine!

i will check Microsoft (r) Windows Based Script Host

steve, i like more ur method, so is indepent from any previus
register. i will check now

tks again to all!!!

I think you also have a problem with your bypass.vbs. It should look
something like this:

Set fso = CreateObject ("Scripting.FileSystemObject")
Set fsoFile = fso.CreateTextFile("c:\tmp\toto.txt")
fsoFile.WriteLine "Hello world"
fsoFile.Close

So your sub could look like this:

Sub bypass()

fn = "c:\tmp\bypass.vbs"
Set fso = CreateObject("Scripting.FileSystemObject")

Set fsoFile = fso.CreateTextFile(fn)
fsoFile.WriteLine "Set fso = CreateObject (""Scripting.FileSystemObject"")"
fsoFile.WriteLine "Set fsoFile = fso.CreateTextFile(""c:\tmp\toto.txt"")"
fsoFile.WriteLine "fsoFile.WriteLine ""Hello world"""
fsoFile.WriteLine "fsoFile.Close"

fsoFile.Close

'Set wshShell = CreateObject("Wscript.Shell")
'wshShell.Run ("C:\WINDOWS\system32\Wscript.exe " & fn)

Shell "C:\WINDOWS\system32\Wscript.exe " & fn, vbHide

End Sub

Both wshShell.Run and Shell will do if you pass in the name of the
executable (in my case "C:\WINDOWS\system32\Wscript.exe ") followed by the
script name ("c:\tmp\bypass.vbs"). If you register .vbs file type to be
opened by WSH executable you can use wshShell.Run (fn) without having to
specify the name of the WSH executable.

Hope this is of some help.
 
R

rhXX

'Set wshShell = CreateObject("Wscript.Shell")
'wshShell.Run ("C:\WINDOWS\system32\Wscript.exe " & fn)

Shell "C:\WINDOWS\system32\Wscript.exe " & fn, vbHide
Both wshShell.Run and Shell will do if you pass in the name of the
executable (in my case "C:\WINDOWS\system32\Wscript.exe ") followed by the
script name ("c:\tmp\bypass.vbs"). If you register .vbs file type to be
opened by WSH executable you can use wshShell.Run (fn) without having to
specify the name of the WSH executable.

tks urkec, yes i did found a mistake of my first bypass, i wrote
directly to forum and noto copy and paste ...

ok about wshSell.Run and Shell, now they are working ok writting
explicity Wscript.exe

tks a lot for the help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top