
Using WScript object in WSC components
Actually, I need to restart a Win2K service.
I am using ADSI and creating the service objects
Set myServiceObj = GetObject("Winnt://./<ServiceName>")
The only way to restart is to do separate calls to start and to stop the
service as there is no single "restart call".
myServiceObj .Stop
myServiceObj .start
Now while the service is stopping, if we issue the start command, it is just
ignored. So the only way is to wait for the service to completely stop and
then to issue the start command.
In order to see if the service is stopped, I can continuously poll the
service status, but this will lead to my ASP hogging the CPU, and hence, I
want to put in a sleep command.
So now my code looks like
on error resume next
Set myServiceObj = GetObject("Winnt://./<ServiceName>")
'Issue the stop
myServiceObj .Stop
t_nStatus = 999 'need this as the following call will crash if service is
stopping
t_nStatus = IISObject.Status
'poll for the status of stopped
do while (NOT (t_nStatus = ADS_SERVICE_STOPPED))
'Get the status again
t_nStatus = 999
t_nStatus = IISObject.Status
loop
'Service has stopped. Restart...
myServiceObj .Start
Is there any other way to do this??
Thanks,
Nagaraj
A WSC is not hosted by wscript.exe or cscript.exe. Only those 2 hosts
create and expose the WScript object. If you *really* need to sleep with a
WSC method called from server side ASP, then you'll need to use a 3rd party
component (like ScriptX from www.meadroid.com). Or rethink your design -
sleeping in server side ASP code may not make you very popular with the IIS
admin ;-)...
--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--
Quote:
> Hi,
> I have created a wsc component and would like to use the WScript object
from
> within this method. Is this permitted ? My code is in JavaScript and I
keep
> get an error that WScript is undefined. I want to use the WScript.Sleep( )
> method.
> I am accessing this WSC component from an ASP page.
> Can I use the WScript object from within a WSC component? Am I missing
> something here?
> Thanks,
> Nagaraj