Re: WScript object not found (???)


T

Tom Ogilvy

How about

Sub aaaa_testscript()

Set WshShell = CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("VOLATILE")
Debug.Print WshSysEnv("LOGONSERVER")
End Sub

or

Sub aaaa_testscript()
Set WshShell = VBA.CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("VOLATILE")
Debug.Print WshSysEnv("LOGONSERVER")
End Sub

remove the Wscript from CreateObject.

Regards,
Tom Ogilvy
 
Ad

Advertisements

R

Randall Arnold

D'oh!

Thanks Tom. Man, I'm an idiot. I should have known that!

-Randy
 
Ad

Advertisements

Joined
Mar 17, 2008
Messages
1
Reaction score
0
CreateObject WScript.Shell

Set oWshShell = CreateObject("WScript.Shell")
vs
Set WshShell = WScript.CreateObject("WScript.Shell")
http://msdn2.microsoft.com/en-us/library/d5fk67ky(VS.85).aspx

Don't feel bad!

Microsoft has this code in red as the documented way to create that object.

What a mess it should break in .vbs files as well! but it doesn't

This works fine in stand-alone .vbs file but will break in any other envrionment!

Option ExplicitDoShell "C:\WINDOWS\notepad.exe"Sub DoShell(ByVal psShellCommand) Dim oWshShell Dim lRet Set oWshShell = WScript.CreateObject("WScript.Shell") lRet = oWshShell.Run(psShellCommand, 1, True) Set oWshShell = NothingEnd Sub This will work both in Stand-alone .vbs and any other vbscript envrionment.Option ExplicitDoShell "C:\WINDOWS\notepad.exe"Sub DoShell(ByVal psShellCommand) Dim oWshShell Dim lRet Set oWshShell = CreateObject("WScript.Shell") lRet = oWshShell.Run(psShellCommand, 1, True) Set oWshShell = NothingEnd SubHow crazy that MS would publish such a horrible bug!

YIKES!
 

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