Fabulous Adventures In Coding
Eric Lippert is a principal developer on the C# compiler team. Learn more about Eric.
am always completely mystified by why people ask this! Why would you WANT to
create the WScript object
in a VB app? What would it do for you? It isn't creatable as an in-process
object because it represents the state of a WSH process, and a VB app is not a WSH
process! The whole point of the WScript object
is that it represents everything about the presently running Windows Script Host.
You can get from it all kinds of properties: the name and version of the script host,
the path of the running script, the arguments which were passed in, the standard streams
of the process, and whether the script was set to time out or not. None of
these properties make the slightest bit of sense to access outside of a running instance
of WSH! What the heck could this possibly mean?
timeout of what? You've just got some object there, not a running instance of
the script host.
about the methods on the object? Again, all of them are deeply tied into the
underlying script hosting mechanisms. WScript.CreateObject, GetObject, ConnectObject and DisconnectObject manipulate
WSH-owned event sinks on the script dispatch. I discussed yesterday how deeply
tied WScript.Sleep is
to the underlying hosting mechanism, and WScript.Echo is
not particularly interesting -- there are better ways to create a message box in VB
just don't get it. Why do people keep asking me to make the WScript object
creatable? I can't figure out what they think they're going to do with it once
they've created it and no one ever gives me a straight answer when I ask. It's
like asking for the ability to create the Response object
without starting ASP! What could it possibly mean to have a Response object
but no web server process? It doesn't make any sense, so we don't let you
We do provide
an object model whereby you can spawn off WSH processes (both locally and remotely)
and query their status as they run. Perhaps that is what these people are looking
for? Remote WSH is a complicated topic in of itself, so perhaps I'll talk about
that in a later blog entry.
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
This won't spike your cpu usage either.
the issue is really trivial. asp classic never implemented its own sleep function. for a runtime that needs to be running async XMLHTTP requests & performing other async ops, not being able to enter a waitstate is... bloody criminal. wsh is sweet, its just tragic the asp runtime is comparatively barren. i'm sorry most people dont understand the discrepancy, but i hope you can understand asp users' frustration at a functionally incomplete runtime. hopefully you can forgive people for not understanding that they're two totally seperate runtimes. you did such a good job with WSH's exposed api that asp couldnt match up.
if all you need is a simple sleep() function within ASP object model, you can use the WScript Shell popup sub timeout property to implement. It's a dirty hack, but if your w3svc service doesn't have "interact with desktop" property enabled you won't see anything on the console, and it'll do the trick for you without any impact on the CPU.
I was just wondering if the inner loop inside Popup does a call to win32::Sleep() and wait for events triggered by the popup window itself, or it has any additional overhead.
start: [<%= time() %>]
waiting 10 seconds...
Set objShell = Server.CreateObject("WScript.Shell")
objShell.Popup "", 10
finish: [<%= time() %>]
Just to get it this out there because I searched EVERYWHERE and couldn't find a reference to this:
It appears that the bug referenced in KB 311269 (enabling remote script host by running "wscript -regserver") is also present in Windows Vista, but just running that command isn't sufficient due to all the UAC stuff. My workaround was to create a cmd file, "regservice.cmd" with a single line, the "wscript -regserver", then right-click that command file and choose "run as administrator". Evidently UAC wasn't bright enough to prompt for access on wscript, since it didn't know that the command line "-regserver" would require administrator access.
Hope this helps somebody.
Let's forget Sleep in VB. I need Sleep in VBScript that is not bound to VB or WScript.exe. I have third party product that implements user exits via VBScript (don't have to license VBA) so I have to live within the cobstraints of their developers who don't provide a Sleep feature. I know i've seen a mechanism for instantiating WScript in an old vb 4 or 5 book; it's a wierd hack, and i've used it, but i can't find my copy of the usage. Sleep is the one function missing from VBScript that is needed outside WScript.
I know it can be done, it has been published, please just show us how.
to A G: I found 2 ways of solving this problem.
When using it in ASP, it doesn't show any windows, but make a timeout for 1 second, so "Loop" or "For Next" can't use 100% CPU
Basicly use COM coponent with Sleep function in it.
I still searching for using Wscript.Sleep in ASP.
to Eric Lippert's
is it possible to use WScript.CreateObject() with Event handling and WScript.ConnectObject and so on, as in VBSript ?
P.S Excuse my english please. I'm russian.