Using WScript object in WSC components 
Author Message
 Using WScript object in WSC components

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



Mon, 20 Sep 2004 08:11:50 GMT  
 Using WScript object in WSC components
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



Mon, 20 Sep 2004 09:06:22 GMT  
 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



Mon, 20 Sep 2004 10:05:32 GMT  
 Using WScript object in WSC components
A hack you can try is to use WshShell.Run to execute another external WSH hosted script that does the wait.  Use True in the 3rd argument of the Run method to wait for the script to return.

WshShell.Run """" & server.mapppath("wait.vbs") & """ 5000", 0, True

=== wait.vbs ===
wscript.sleep wscript.arguments(0)

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--

Quote:

> 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
> --


> > 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



Mon, 20 Sep 2004 10:38:49 GMT  
 Using WScript object in WSC components
Thanks for your help.



A hack you can try is to use WshShell.Run to execute another external WSH
hosted script that does the wait.  Use True in the 3rd argument of the Run
method to wait for the script to return.

WshShell.Run """" & server.mapppath("wait.vbs") & """ 5000", 0, True

=== wait.vbs ===
wscript.sleep wscript.arguments(0)

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--

Quote:
> 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
> --


> > 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



Tue, 21 Sep 2004 01:43:11 GMT  
 Using WScript object in WSC components

Quote:
> A hack you can try is to use WshShell.Run to execute another external
> WSH hosted script that does the wait.  Use True in the 3rd argument of
> the Run method to wait for the script to return.

> WshShell.Run """" & server.mapppath("wait.vbs") & """ 5000", 0, True

> === wait.vbs ===
> wscript.sleep wscript.arguments(0)

Or use VB and make yourself a sleep dll
Project Name (MySleep)

'Sleep.cls

Public Sub Sleep(dwMilliseconds As Long)
    mySleep (dwMilliseconds)
End Sub

'Sleep.bas
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub mySleep(dwMilliseconds As Long)
    Sleep (dwMilliseconds)
End Sub

Compile and register

In your ASP

Set oSleep = Server.CreateObject("MySleep.Sleep")

' Sleep 1 second
oSleep.Sleep(1000);

HTH
   -Kevin



Mon, 11 Oct 2004 23:47:39 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Using Wscript Objects in WSC

2. Using WSCRIPT object in a WSC

3. How to use wscript methods in .wsc components?

4. Attach events of the external COM-object from WSC component

5. pass a COM object reference to a WSC component

6. No WScript object in WSC's?

7. Using WScript in wsc files

8. Using Wscript.Sleep in a script component

9. Interfacing with Access object using WSC written in JScript

10. using "WScript.Shell" in a component (wsc)

11. Syntax Classes and WSC components

12. Class_Initialize in Windows Script Components (WSC)

 

 
Powered by phpBB® Forum Software