we have used Windows Scripting Host in a VBA environement to successfuly
create shortcuts and determine system information for our Access Database for
over 2 years.
The jist of the working code is this:
Dim objShortcut As Object
Dim wshShell As Object
Set wshShell = VBA.CreateObject("WScript.Shell")
If wshShell Is Nothing Then
fError = True
strError = "Windows Scripting host not instantiated."
If Err.Number <> 0 Then
strError = strError & Err.Description
End If
Else
Set objShortcut = wshShell.CreateShortcut(strTarget & "\" &
strName & ".lnk")
'set arguments icon etc
...
...
end if
Laterly we are finding this code is blowing up on SOME of our customer sites
(but not on our machines and many others) - the Shortcuts are not created and
the WSHShell object is not instantiated. The error reported is 'A dynamic
link library (DLL) initialization routine failed' when the CreateObject is
called.
A test VB script file also fails on these machines, if we run:
dim wshShell
set WshShell = WScript.CreateObject("WScript.Shell")
We get an error :
Unable to create Wscript.Shell object, Error - 2147023782 (Could not create
object named "Wscript.Shell")
We get the same problem if we early bind, by setting a reference to
wshom.ocx and using the object model;
Dim objShortcut IWshRuntimeLibrary.WshShortcut
Dim wshShell As IWshRuntimeLibrary.wshShell
In exploring these issue on one offending machine :
Operating system : Windows XP 5.1.2600 Service Pack 2
Internet Explorer: 6.0.2900 (6 Service Pack 2)
We find the WSH components are version 5.6, the same as on our development
machines were the script works. We have noted that we have our code working
on Win 98, Win ME, Win 2K and Win XP platforms, and have reported failures on
Win 98 and Win XP (not many of out customers have 2in 2k or me so not really
any significance there).
Has anybody any clues as to why we cannot use WSH on some machines. What
unknown dependancies are there? This problem was unkown to us until quite
recently. Has MS kicked in some vulnerability patches.
I look forward to any assistance as we are pulling our hair out now.
Regards
Philip Leicester
3rd Base Ltd
-----------------------------------------------
Mostly, mainly to your question,
-----------------
Objects were not creatable along VBA........
as far as I know under most circumstances
since you tried first and later !
While not most of the time. Sometimes, maybe under
special circumstances.
This group considers special circumstances when applicable.
---------------------------------
Query Google or some other Search enginge using the
espressions below verbatime quoted or not.
CreateObject("WScript.Shell")
or
new ActiveXObject("WScript.Shell")
-----------------------------------------------
And relax.
"3Base" <3B...@discussions.microsoft.com> wrote in message
news:0EF8F76D-6E96-4F46...@microsoft.com...
You can use createobject in VBA, and in anycase early binding also fails.
Also the code works - its just blowing up on SOME machines. So the answer has
to do with dependendancies and not the code - that is not to say the code
could not be refactored to eradicate the problem.
I have googled extensivly for CreateObject("WScript.Shell") to no avail.
I've not tried new ActiveXObject("WScript.Shell") before so I'll explore this.
Regards
3base
> I've not tried new ActiveXObject("WScript.Shell") before so I'll
> explore this.
Just FYI, that's for JScript scripts.
--
Bill Stewart
--------------
Laydown , staydown.
-------------------
"Bill Stewart" <llib.t...@yrautromhcnerf.moc> wrote in message
news:eREa2b7b...@TK2MSFTNGP04.phx.gbl...