shutdown 
Author Message
 shutdown

Hi,

I have written the following script to shutdown my computer after office
hours . I have the following question.

1. Is there a way to force all my application to close and shutdown ?
2. How can I modify this script so that at a specific date and time the
script will shutdown ?

Set colOperatingSystems =
GetObject("winmgmts:{(Shutdown)}").ExecQuery("Select * from
Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Win32Shutdown(1)
Next

I hope someone could help because most of the time I am out of office and I
need my computer to turn on to process some data backup.

Thanks



Mon, 25 Jul 2005 19:36:56 GMT  
 shutdown
For the 2nd point you can easily use the Task Scheduler of Windows ...
Start>Control Pannel>Task Scheduler ....



Quote:
> Hi,

> I have written the following script to shutdown my computer after office
> hours . I have the following question.

> 1. Is there a way to force all my application to close and shutdown ?
> 2. How can I modify this script so that at a specific date and time the
> script will shutdown ?

> Set colOperatingSystems =
> GetObject("winmgmts:{(Shutdown)}").ExecQuery("Select * from
> Win32_OperatingSystem")
> For Each objOperatingSystem in colOperatingSystems
> ObjOperatingSystem.Win32Shutdown(1)
> Next

> I hope someone could help because most of the time I am out of office and
I
> need my computer to turn on to process some data backup.

> Thanks



Mon, 25 Jul 2005 21:42:45 GMT  
 shutdown
How about the 1st point, whenever I run the outlook, I can't shutdown it
prompt me to close the application. How can I force the shutdown.


Quote:
> For the 2nd point you can easily use the Task Scheduler of Windows ...
> Start>Control Pannel>Task Scheduler ....



> > Hi,

> > I have written the following script to shutdown my computer after office
> > hours . I have the following question.

> > 1. Is there a way to force all my application to close and shutdown ?
> > 2. How can I modify this script so that at a specific date and time the
> > script will shutdown ?

> > Set colOperatingSystems =
> > GetObject("winmgmts:{(Shutdown)}").ExecQuery("Select * from
> > Win32_OperatingSystem")
> > For Each objOperatingSystem in colOperatingSystems
> > ObjOperatingSystem.Win32Shutdown(1)
> > Next

> > I hope someone could help because most of the time I am out of office
and
> I
> > need my computer to turn on to process some data backup.

> > Thanks



Tue, 26 Jul 2005 00:02:11 GMT  
 shutdown
Hi,

On the first point, you have the right code, just
the wrong numeric parameter.

From a Torgeir Bakken post:

----

sComputer = "."    ' use "." for local computer

' Use "Reboot_Force" for a forced reboot
ShutDown sComputer, "Reboot"

Sub ShutDown(sNode, sAction)

  Const EWX_LOGOFF = 0
  Const EWX_SHUTDOWN = 1
  Const EWX_REBOOT = 2
  Const EWX_FORCE = 4
  Const EWX_POWEROFF = 8

  Set oWMI = GetObject("winmgmts:" _
     & "{impersonationLevel=impersonate,(Shutdown)}!\\" _
     & sNode & "\root\cimv2")

  Set colOperatingSystems = oWMI.ExecQuery _
     ("Select * from Win32_OperatingSystem")
  For Each obj in colOperatingSystems
    Set oOS = obj :  Exit For
  Next

  sAction = LCase(sAction)

  Select Case sAction
    Case "logoff"
      iCmd = EWX_LOGOFF
    Case "logoff_force"
      iCmd = EWX_LOGOFF + EWX_FORCE
    Case "shutdown"
      iCmd = EWX_SHUTDOWN
    Case "shutdown_force"
      iCmd = EWX_SHUTDOWN + EWX_FORCE
    Case "reboot"
      iCmd = EWX_REBOOT
    Case "reboot_force"
      iCmd = EWX_REBOOT + EWX_FORCE
    Case "poweroff"
      iCmd = EWX_POWEROFF
    Case "poweroff_force"
      iCmd = EWX_POWEROFF + EWX_FORCE
    Case Else
      ' Default value
      iCmd = EWX_POWEROFF
  End Select

  oOS.Win32shutdown iCmd

End Sub

----

Joe Earnest



Quote:
> Hi,

> I have written the following script to shutdown my computer after office
> hours . I have the following question.

> 1. Is there a way to force all my application to close and shutdown ?
> 2. How can I modify this script so that at a specific date and time the
> script will shutdown ?

> Set colOperatingSystems =
> GetObject("winmgmts:{(Shutdown)}").ExecQuery("Select * from
> Win32_OperatingSystem")
> For Each objOperatingSystem in colOperatingSystems
> ObjOperatingSystem.Win32Shutdown(1)
> Next

> I hope someone could help because most of the time I am out of office and
I
> need my computer to turn on to process some data backup.

> Thanks



Tue, 26 Jul 2005 00:53:29 GMT  
 shutdown
Hi Joe,

Thanks for your reply. How about the second point, can I use script to do
it.

Pls advice.


Quote:
> Hi,

> On the first point, you have the right code, just
> the wrong numeric parameter.

> From a Torgeir Bakken post:

> ----

> sComputer = "."    ' use "." for local computer

> ' Use "Reboot_Force" for a forced reboot
> ShutDown sComputer, "Reboot"

> Sub ShutDown(sNode, sAction)

>   Const EWX_LOGOFF = 0
>   Const EWX_SHUTDOWN = 1
>   Const EWX_REBOOT = 2
>   Const EWX_FORCE = 4
>   Const EWX_POWEROFF = 8

>   Set oWMI = GetObject("winmgmts:" _
>      & "{impersonationLevel=impersonate,(Shutdown)}!\\" _
>      & sNode & "\root\cimv2")

>   Set colOperatingSystems = oWMI.ExecQuery _
>      ("Select * from Win32_OperatingSystem")
>   For Each obj in colOperatingSystems
>     Set oOS = obj :  Exit For
>   Next

>   sAction = LCase(sAction)

>   Select Case sAction
>     Case "logoff"
>       iCmd = EWX_LOGOFF
>     Case "logoff_force"
>       iCmd = EWX_LOGOFF + EWX_FORCE
>     Case "shutdown"
>       iCmd = EWX_SHUTDOWN
>     Case "shutdown_force"
>       iCmd = EWX_SHUTDOWN + EWX_FORCE
>     Case "reboot"
>       iCmd = EWX_REBOOT
>     Case "reboot_force"
>       iCmd = EWX_REBOOT + EWX_FORCE
>     Case "poweroff"
>       iCmd = EWX_POWEROFF
>     Case "poweroff_force"
>       iCmd = EWX_POWEROFF + EWX_FORCE
>     Case Else
>       ' Default value
>       iCmd = EWX_POWEROFF
>   End Select

>   oOS.Win32shutdown iCmd

> End Sub

> ----

> Joe Earnest



> > Hi,

> > I have written the following script to shutdown my computer after office
> > hours . I have the following question.

> > 1. Is there a way to force all my application to close and shutdown ?
> > 2. How can I modify this script so that at a specific date and time the
> > script will shutdown ?

> > Set colOperatingSystems =
> > GetObject("winmgmts:{(Shutdown)}").ExecQuery("Select * from
> > Win32_OperatingSystem")
> > For Each objOperatingSystem in colOperatingSystems
> > ObjOperatingSystem.Win32Shutdown(1)
> > Next

> > I hope someone could help because most of the time I am out of office
and
> I
> > need my computer to turn on to process some data backup.

> > Thanks



Tue, 26 Jul 2005 12:49:28 GMT  
 shutdown
Hi,

If you don't want to use task scheduler (per Fabrice's post),
you can use a simple loop to check the time and date using the
Now and Date functions.  Note that this will require VBS v5.1
or greater.  A sleep function is necessary to keep the loop from
consuming processor resources.  If you decided to use AutoItX
for shutdown, it also has a sleep function.  Then just place a
shortcut to your script in the startup folder (or reference it in the
registry run locations).

Something like (air code, so modify or test for errors) ...

---
yShutdown= CDate(...)  'your shutdown date, time

Do
WScript.Sleep 1000  '1-second interval, adjust as you wish
Loop Until (yShutdown>CDate(Now))

... 'your shutdown routine

---
There's also a Timer function that measures
seconds since midnight.  All MS VBS downloads are
here.  Select "documentation" from the left column.  The
downloaded file will install a chm file with the VBS
documentation.  This will give you the synatx for these
functions.

(URL WILL WRAP)
http://msdn.microsoft.com/downloads/default.asp?url=/downloads/topic....
=/msdn-files/028/001/175/topic.xml

Regards,
Joe Earnest



Quote:
> Hi Joe,

> Thanks for your reply. How about the second point, can I use script to do
> it.

> Pls advice.



> > Hi,

> > On the first point, you have the right code, just
> > the wrong numeric parameter.

> > From a Torgeir Bakken post:

> > ----

> > sComputer = "."    ' use "." for local computer

> > ' Use "Reboot_Force" for a forced reboot
> > ShutDown sComputer, "Reboot"

> > Sub ShutDown(sNode, sAction)

> >   Const EWX_LOGOFF = 0
> >   Const EWX_SHUTDOWN = 1
> >   Const EWX_REBOOT = 2
> >   Const EWX_FORCE = 4
> >   Const EWX_POWEROFF = 8

> >   Set oWMI = GetObject("winmgmts:" _
> >      & "{impersonationLevel=impersonate,(Shutdown)}!\\" _
> >      & sNode & "\root\cimv2")

> >   Set colOperatingSystems = oWMI.ExecQuery _
> >      ("Select * from Win32_OperatingSystem")
> >   For Each obj in colOperatingSystems
> >     Set oOS = obj :  Exit For
> >   Next

> >   sAction = LCase(sAction)

> >   Select Case sAction
> >     Case "logoff"
> >       iCmd = EWX_LOGOFF
> >     Case "logoff_force"
> >       iCmd = EWX_LOGOFF + EWX_FORCE
> >     Case "shutdown"
> >       iCmd = EWX_SHUTDOWN
> >     Case "shutdown_force"
> >       iCmd = EWX_SHUTDOWN + EWX_FORCE
> >     Case "reboot"
> >       iCmd = EWX_REBOOT
> >     Case "reboot_force"
> >       iCmd = EWX_REBOOT + EWX_FORCE
> >     Case "poweroff"
> >       iCmd = EWX_POWEROFF
> >     Case "poweroff_force"
> >       iCmd = EWX_POWEROFF + EWX_FORCE
> >     Case Else
> >       ' Default value
> >       iCmd = EWX_POWEROFF
> >   End Select

> >   oOS.Win32shutdown iCmd

> > End Sub

> > ----

> > Joe Earnest



> > > Hi,

> > > I have written the following script to shutdown my computer after
office
> > > hours . I have the following question.

> > > 1. Is there a way to force all my application to close and shutdown ?
> > > 2. How can I modify this script so that at a specific date and time
the
> > > script will shutdown ?

> > > Set colOperatingSystems =
> > > GetObject("winmgmts:{(Shutdown)}").ExecQuery("Select * from
> > > Win32_OperatingSystem")
> > > For Each objOperatingSystem in colOperatingSystems
> > > ObjOperatingSystem.Win32Shutdown(1)
> > > Next

> > > I hope someone could help because most of the time I am out of office
> and
> > I
> > > need my computer to turn on to process some data backup.

> > > Thanks



Thu, 28 Jul 2005 05:29:15 GMT  
 shutdown
Hi Joe,

Is your CDate comes with WMI, if not how I integrate it with WMI ?

Pls advice.


Quote:
> Hi,

> If you don't want to use task scheduler (per Fabrice's post),
> you can use a simple loop to check the time and date using the
> Now and Date functions.  Note that this will require VBS v5.1
> or greater.  A sleep function is necessary to keep the loop from
> consuming processor resources.  If you decided to use AutoItX
> for shutdown, it also has a sleep function.  Then just place a
> shortcut to your script in the startup folder (or reference it in the
> registry run locations).

> Something like (air code, so modify or test for errors) ...

> ---
> yShutdown= CDate(...)  'your shutdown date, time

> Do
> WScript.Sleep 1000  '1-second interval, adjust as you wish
> Loop Until (yShutdown>CDate(Now))

> ... 'your shutdown routine

> ---
> There's also a Timer function that measures
> seconds since midnight.  All MS VBS downloads are
> here.  Select "documentation" from the left column.  The
> downloaded file will install a chm file with the VBS
> documentation.  This will give you the synatx for these
> functions.

> (URL WILL WRAP)

http://msdn.microsoft.com/downloads/default.asp?url=/downloads/topic....

- Show quoted text -

Quote:
> =/msdn-files/028/001/175/topic.xml

> Regards,
> Joe Earnest



> > Hi Joe,

> > Thanks for your reply. How about the second point, can I use script to
do
> > it.

> > Pls advice.



> > > Hi,

> > > On the first point, you have the right code, just
> > > the wrong numeric parameter.

> > > From a Torgeir Bakken post:

> > > ----

> > > sComputer = "."    ' use "." for local computer

> > > ' Use "Reboot_Force" for a forced reboot
> > > ShutDown sComputer, "Reboot"

> > > Sub ShutDown(sNode, sAction)

> > >   Const EWX_LOGOFF = 0
> > >   Const EWX_SHUTDOWN = 1
> > >   Const EWX_REBOOT = 2
> > >   Const EWX_FORCE = 4
> > >   Const EWX_POWEROFF = 8

> > >   Set oWMI = GetObject("winmgmts:" _
> > >      & "{impersonationLevel=impersonate,(Shutdown)}!\\" _
> > >      & sNode & "\root\cimv2")

> > >   Set colOperatingSystems = oWMI.ExecQuery _
> > >      ("Select * from Win32_OperatingSystem")
> > >   For Each obj in colOperatingSystems
> > >     Set oOS = obj :  Exit For
> > >   Next

> > >   sAction = LCase(sAction)

> > >   Select Case sAction
> > >     Case "logoff"
> > >       iCmd = EWX_LOGOFF
> > >     Case "logoff_force"
> > >       iCmd = EWX_LOGOFF + EWX_FORCE
> > >     Case "shutdown"
> > >       iCmd = EWX_SHUTDOWN
> > >     Case "shutdown_force"
> > >       iCmd = EWX_SHUTDOWN + EWX_FORCE
> > >     Case "reboot"
> > >       iCmd = EWX_REBOOT
> > >     Case "reboot_force"
> > >       iCmd = EWX_REBOOT + EWX_FORCE
> > >     Case "poweroff"
> > >       iCmd = EWX_POWEROFF
> > >     Case "poweroff_force"
> > >       iCmd = EWX_POWEROFF + EWX_FORCE
> > >     Case Else
> > >       ' Default value
> > >       iCmd = EWX_POWEROFF
> > >   End Select

> > >   oOS.Win32shutdown iCmd

> > > End Sub

> > > ----

> > > Joe Earnest



> > > > Hi,

> > > > I have written the following script to shutdown my computer after
> office
> > > > hours . I have the following question.

> > > > 1. Is there a way to force all my application to close and shutdown
?
> > > > 2. How can I modify this script so that at a specific date and time
> the
> > > > script will shutdown ?

> > > > Set colOperatingSystems =
> > > > GetObject("winmgmts:{(Shutdown)}").ExecQuery("Select * from
> > > > Win32_OperatingSystem")
> > > > For Each objOperatingSystem in colOperatingSystems
> > > > ObjOperatingSystem.Win32Shutdown(1)
> > > > Next

> > > > I hope someone could help because most of the time I am out of
office
> > and
> > > I
> > > > need my computer to turn on to process some data backup.

> > > > Thanks



Fri, 29 Jul 2005 19:54:04 GMT  
 shutdown
Hi,

The date functions (including CDate - which simply converts a date
to a special variable format) are VBS functions.  WMI is an object
that you call from VBS via the script that I posted earlier.  You're
working in VBScript all the time, merely calling and getting returns
from WMI.  Write the timer example script at the top of your VBS file,
then write the WMI shutdown script under it.  The script will progress
to the shutdown segment after it finishes looping through the timer
segment.

For the timer loop, also check out Date and the cross-referenced
date parts in the documentation.  These may be easier to work with.

Joe Earnest



| Hi Joe,
|
| Is your CDate comes with WMI, if not how I integrate it with WMI ?
|
| Pls advice.
|


| > Hi,
| >
| > If you don't want to use task scheduler (per Fabrice's post),
| > you can use a simple loop to check the time and date using the
| > Now and Date functions.  Note that this will require VBS v5.1
| > or greater.  A sleep function is necessary to keep the loop from
| > consuming processor resources.  If you decided to use AutoItX
| > for shutdown, it also has a sleep function.  Then just place a
| > shortcut to your script in the startup folder (or reference it in the
| > registry run locations).
| >
| > Something like (air code, so modify or test for errors) ...
| >
| > ---
| > yShutdown= CDate(...)  'your shutdown date, time
| >
| > Do
| > WScript.Sleep 1000  '1-second interval, adjust as you wish
| > Loop Until (yShutdown>CDate(Now))
| >
| > ... 'your shutdown routine
| >
| > ---
| > There's also a Timer function that measures
| > seconds since midnight.  All MS VBS downloads are
| > here.  Select "documentation" from the left column.  The
| > downloaded file will install a chm file with the VBS
| > documentation.  This will give you the synatx for these
| > functions.
| >
| > (URL WILL WRAP)
| >
|
http://msdn.microsoft.com/downloads/default.asp?url=/downloads/topic....
| > =/msdn-files/028/001/175/topic.xml
| >
| > Regards,
| > Joe Earnest
| >


| > > Hi Joe,
| > >
| > > Thanks for your reply. How about the second point, can I use script to
| do
| > > it.
| > >
| > > Pls advice.
| > >


| > > > Hi,
| > > >
| > > > On the first point, you have the right code, just
| > > > the wrong numeric parameter.
| > > >
| > > > From a Torgeir Bakken post:
| > > >
| > > > ----
| > > >
| > > > sComputer = "."    ' use "." for local computer
| > > >
| > > > ' Use "Reboot_Force" for a forced reboot
| > > > ShutDown sComputer, "Reboot"
| > > >
| > > > Sub ShutDown(sNode, sAction)
| > > >
| > > >   Const EWX_LOGOFF = 0
| > > >   Const EWX_SHUTDOWN = 1
| > > >   Const EWX_REBOOT = 2
| > > >   Const EWX_FORCE = 4
| > > >   Const EWX_POWEROFF = 8
| > > >
| > > >   Set oWMI = GetObject("winmgmts:" _
| > > >      & "{impersonationLevel=impersonate,(Shutdown)}!\\" _
| > > >      & sNode & "\root\cimv2")
| > > >
| > > >   Set colOperatingSystems = oWMI.ExecQuery _
| > > >      ("Select * from Win32_OperatingSystem")
| > > >   For Each obj in colOperatingSystems
| > > >     Set oOS = obj :  Exit For
| > > >   Next
| > > >
| > > >   sAction = LCase(sAction)
| > > >
| > > >   Select Case sAction
| > > >     Case "logoff"
| > > >       iCmd = EWX_LOGOFF
| > > >     Case "logoff_force"
| > > >       iCmd = EWX_LOGOFF + EWX_FORCE
| > > >     Case "shutdown"
| > > >       iCmd = EWX_SHUTDOWN
| > > >     Case "shutdown_force"
| > > >       iCmd = EWX_SHUTDOWN + EWX_FORCE
| > > >     Case "reboot"
| > > >       iCmd = EWX_REBOOT
| > > >     Case "reboot_force"
| > > >       iCmd = EWX_REBOOT + EWX_FORCE
| > > >     Case "poweroff"
| > > >       iCmd = EWX_POWEROFF
| > > >     Case "poweroff_force"
| > > >       iCmd = EWX_POWEROFF + EWX_FORCE
| > > >     Case Else
| > > >       ' Default value
| > > >       iCmd = EWX_POWEROFF
| > > >   End Select
| > > >
| > > >   oOS.Win32shutdown iCmd
| > > >
| > > > End Sub
| > > >
| > > > ----
| > > >
| > > > Joe Earnest
| > > >


| > > > > Hi,
| > > > >
| > > > > I have written the following script to shutdown my computer after
| > office
| > > > > hours . I have the following question.
| > > > >
| > > > > 1. Is there a way to force all my application to close and
shutdown
| ?
| > > > > 2. How can I modify this script so that at a specific date and
time
| > the
| > > > > script will shutdown ?
| > > > >
| > > > >
| > > > > Set colOperatingSystems =
| > > > > GetObject("winmgmts:{(Shutdown)}").ExecQuery("Select * from
| > > > > Win32_OperatingSystem")
| > > > > For Each objOperatingSystem in colOperatingSystems
| > > > > ObjOperatingSystem.Win32Shutdown(1)
| > > > > Next
| > > > >
| > > > > I hope someone could help because most of the time I am out of
| office
| > > and
| > > > I
| > > > > need my computer to turn on to process some data backup.
| > > > >
| > > > > Thanks
| > > > >
| > > > >
| > > >
| > > >
| > >
| > >
| >
| >
|
|

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.410 / Virus Database: 231 - Release Date: 10-31-02



Fri, 29 Jul 2005 22:45:17 GMT  
 shutdown
Hi Joe,

Any sample on how to set the timer.

Thanks


Quote:
> Hi,

> The date functions (including CDate - which simply converts a date
> to a special variable format) are VBS functions.  WMI is an object
> that you call from VBS via the script that I posted earlier.  You're
> working in VBScript all the time, merely calling and getting returns
> from WMI.  Write the timer example script at the top of your VBS file,
> then write the WMI shutdown script under it.  The script will progress
> to the shutdown segment after it finishes looping through the timer
> segment.

> For the timer loop, also check out Date and the cross-referenced
> date parts in the documentation.  These may be easier to work with.

> Joe Earnest



> | Hi Joe,
> |
> | Is your CDate comes with WMI, if not how I integrate it with WMI ?
> |
> | Pls advice.
> |


> | > Hi,
> | >
> | > If you don't want to use task scheduler (per Fabrice's post),
> | > you can use a simple loop to check the time and date using the
> | > Now and Date functions.  Note that this will require VBS v5.1
> | > or greater.  A sleep function is necessary to keep the loop from
> | > consuming processor resources.  If you decided to use AutoItX
> | > for shutdown, it also has a sleep function.  Then just place a
> | > shortcut to your script in the startup folder (or reference it in the
> | > registry run locations).
> | >
> | > Something like (air code, so modify or test for errors) ...
> | >
> | > ---
> | > yShutdown= CDate(...)  'your shutdown date, time
> | >
> | > Do
> | > WScript.Sleep 1000  '1-second interval, adjust as you wish
> | > Loop Until (yShutdown>CDate(Now))
> | >
> | > ... 'your shutdown routine
> | >
> | > ---
> | > There's also a Timer function that measures
> | > seconds since midnight.  All MS VBS downloads are
> | > here.  Select "documentation" from the left column.  The
> | > downloaded file will install a chm file with the VBS
> | > documentation.  This will give you the synatx for these
> | > functions.
> | >
> | > (URL WILL WRAP)
> | >
> |

http://msdn.microsoft.com/downloads/default.asp?url=/downloads/topic....

- Show quoted text -

Quote:
> | > =/msdn-files/028/001/175/topic.xml
> | >
> | > Regards,
> | > Joe Earnest
> | >


> | > > Hi Joe,
> | > >
> | > > Thanks for your reply. How about the second point, can I use script
to
> | do
> | > > it.
> | > >
> | > > Pls advice.
> | > >


> | > > > Hi,
> | > > >
> | > > > On the first point, you have the right code, just
> | > > > the wrong numeric parameter.
> | > > >
> | > > > From a Torgeir Bakken post:
> | > > >
> | > > > ----
> | > > >
> | > > > sComputer = "."    ' use "." for local computer
> | > > >
> | > > > ' Use "Reboot_Force" for a forced reboot
> | > > > ShutDown sComputer, "Reboot"
> | > > >
> | > > > Sub ShutDown(sNode, sAction)
> | > > >
> | > > >   Const EWX_LOGOFF = 0
> | > > >   Const EWX_SHUTDOWN = 1
> | > > >   Const EWX_REBOOT = 2
> | > > >   Const EWX_FORCE = 4
> | > > >   Const EWX_POWEROFF = 8
> | > > >
> | > > >   Set oWMI = GetObject("winmgmts:" _
> | > > >      & "{impersonationLevel=impersonate,(Shutdown)}!\\" _
> | > > >      & sNode & "\root\cimv2")
> | > > >
> | > > >   Set colOperatingSystems = oWMI.ExecQuery _
> | > > >      ("Select * from Win32_OperatingSystem")
> | > > >   For Each obj in colOperatingSystems
> | > > >     Set oOS = obj :  Exit For
> | > > >   Next
> | > > >
> | > > >   sAction = LCase(sAction)
> | > > >
> | > > >   Select Case sAction
> | > > >     Case "logoff"
> | > > >       iCmd = EWX_LOGOFF
> | > > >     Case "logoff_force"
> | > > >       iCmd = EWX_LOGOFF + EWX_FORCE
> | > > >     Case "shutdown"
> | > > >       iCmd = EWX_SHUTDOWN
> | > > >     Case "shutdown_force"
> | > > >       iCmd = EWX_SHUTDOWN + EWX_FORCE
> | > > >     Case "reboot"
> | > > >       iCmd = EWX_REBOOT
> | > > >     Case "reboot_force"
> | > > >       iCmd = EWX_REBOOT + EWX_FORCE
> | > > >     Case "poweroff"
> | > > >       iCmd = EWX_POWEROFF
> | > > >     Case "poweroff_force"
> | > > >       iCmd = EWX_POWEROFF + EWX_FORCE
> | > > >     Case Else
> | > > >       ' Default value
> | > > >       iCmd = EWX_POWEROFF
> | > > >   End Select
> | > > >
> | > > >   oOS.Win32shutdown iCmd
> | > > >
> | > > > End Sub
> | > > >
> | > > > ----
> | > > >
> | > > > Joe Earnest
> | > > >


> | > > > > Hi,
> | > > > >
> | > > > > I have written the following script to shutdown my computer
after
> | > office
> | > > > > hours . I have the following question.
> | > > > >
> | > > > > 1. Is there a way to force all my application to close and
> shutdown
> | ?
> | > > > > 2. How can I modify this script so that at a specific date and
> time
> | > the
> | > > > > script will shutdown ?
> | > > > >
> | > > > >
> | > > > > Set colOperatingSystems =
> | > > > > GetObject("winmgmts:{(Shutdown)}").ExecQuery("Select * from
> | > > > > Win32_OperatingSystem")
> | > > > > For Each objOperatingSystem in colOperatingSystems
> | > > > > ObjOperatingSystem.Win32Shutdown(1)
> | > > > > Next
> | > > > >
> | > > > > I hope someone could help because most of the time I am out of
> | office
> | > > and
> | > > > I
> | > > > > need my computer to turn on to process some data backup.
> | > > > >
> | > > > > Thanks
> | > > > >
> | > > > >
> | > > >
> | > > >
> | > >
> | > >
> | >
> | >
> |
> |

> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.410 / Virus Database: 231 - Release Date: 10-31-02



Sat, 30 Jul 2005 17:16:36 GMT  
 shutdown
Hi

The timer cumulates the number of seconds from midnight,
so to turn it off at 10:00pm each day, use 22 x 60 x 60
(79200).

Do
  WScript.Sleep 1000  '1-second interval, adjust as you wish
Loop Until (Timer>79200)

If you actually want to time the length of a session of less
than 24 hours, just get a start and end time.  Add 86400
(24x60x60) if you might cross midnight.  For a 6-hour
maximum (60x60=3600):

OffTime= 6 *3600: StartTime= Timer
Do
  WScript.Sleep 1000
  NowTime= Timer
  If (NowTime<StartTime) Then
    NowTime= NowTime +86400
  End If
Loop Until ((NowTime -StartTime)>OffTime)

Simply put the shutdown code after the loop.

Joe Earnest



| Hi Joe,
|
| Any sample on how to set the timer.
|
| Thanks

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.410 / Virus Database: 231 - Release Date: 10-31-02



Sat, 30 Jul 2005 22:22:05 GMT  
 shutdown
Hi Joe,

How can I set the date ?

Thanks


Quote:
> Hi

> The timer cumulates the number of seconds from midnight,
> so to turn it off at 10:00pm each day, use 22 x 60 x 60
> (79200).

> Do
>   WScript.Sleep 1000  '1-second interval, adjust as you wish
> Loop Until (Timer>79200)

> If you actually want to time the length of a session of less
> than 24 hours, just get a start and end time.  Add 86400
> (24x60x60) if you might cross midnight.  For a 6-hour
> maximum (60x60=3600):

> OffTime= 6 *3600: StartTime= Timer
> Do
>   WScript.Sleep 1000
>   NowTime= Timer
>   If (NowTime<StartTime) Then
>     NowTime= NowTime +86400
>   End If
> Loop Until ((NowTime -StartTime)>OffTime)

> Simply put the shutdown code after the loop.

> Joe Earnest



> | Hi Joe,
> |
> | Any sample on how to set the timer.
> |
> | Thanks

> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.410 / Virus Database: 231 - Release Date: 10-31-02



Fri, 05 Aug 2005 09:58:33 GMT  
 shutdown
Hi,

From the WSH documentation:

Use the IsDate function to determine if date can be converted to a date or
time. CDate recognizes date literals and time literals as well as some
numbers that fall within the range of acceptable dates. When converting a
number to a date, the whole number portion is converted to a date. Any
fractional part of the number is converted to a time of day, starting at
midnight.

CDate recognizes date formats according to the locale setting of your
system. The correct order of day, month, and year may not be determined if
it is provided in a format other than one of the recognized date settings.
In addition, a long date format is not recognized if it also contains the
day-of-the-week string.

The following example uses the CDate function to convert a string to a date.
In general, hard coding dates and times as strings (as shown in this
example) is not recommended. Use date and time literals (such as
#10/19/1962#, #4:45:23 PM#) instead.

MyDate = "October 19, 1962"   ' Define date.
MyShortDate = CDate(MyDate)   ' Convert to Date data type.
MyTime = "4:35:47 PM"         ' Define time.
MyShortTime = CDate(MyTime)   ' Convert to Date data type.Joe Earnest



| Hi Joe,
|
| How can I set the date ?
|
| Thanks
|


| > Hi
| >
| > The timer cumulates the number of seconds from midnight,
| > so to turn it off at 10:00pm each day, use 22 x 60 x 60
| > (79200).
| >
| > Do
| >   WScript.Sleep 1000  '1-second interval, adjust as you wish
| > Loop Until (Timer>79200)
| >
| > If you actually want to time the length of a session of less
| > than 24 hours, just get a start and end time.  Add 86400
| > (24x60x60) if you might cross midnight.  For a 6-hour
| > maximum (60x60=3600):
| >
| > OffTime= 6 *3600: StartTime= Timer
| > Do
| >   WScript.Sleep 1000
| >   NowTime= Timer
| >   If (NowTime<StartTime) Then
| >     NowTime= NowTime +86400
| >   End If
| > Loop Until ((NowTime -StartTime)>OffTime)
| >
| > Simply put the shutdown code after the loop.
| >
| > Joe Earnest
| >


| > | Hi Joe,
| > |
| > | Any sample on how to set the timer.
| > |
| > | Thanks
| >
| >
| >
| >
| > ---
| > Outgoing mail is certified Virus Free.
| > Checked by AVG anti-virus system (http://www.grisoft.com).
| > Version: 6.0.410 / Virus Database: 231 - Release Date: 10-31-02
| >
| >
|
|

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.410 / Virus Database: 231 - Release Date: 10-31-02



Sat, 06 Aug 2005 00:42:56 GMT  
 shutdown

Hi,
Please I want to shutdown a computer after an inactivity period...
How could I do tihs???



Quote:
> Hi,

> If you don't want to use task scheduler (per Fabrice's post),
> you can use a simple loop to check the time and date using the
> Now and Date functions.  Note that this will require VBS v5.1
> or greater.  A sleep function is necessary to keep the loop from
> consuming processor resources.  If you decided to use AutoItX
> for shutdown, it also has a sleep function.  Then just place a
> shortcut to your script in the startup folder (or reference it in the
> registry run locations).

> Something like (air code, so modify or test for errors) ...

> ---
> yShutdown= CDate(...)  'your shutdown date, time

> Do
> WScript.Sleep 1000  '1-second interval, adjust as you wish
> Loop Until (yShutdown>CDate(Now))

> ... 'your shutdown routine

> ---
> There's also a Timer function that measures
> seconds since midnight.  All MS VBS downloads are
> here.  Select "documentation" from the left column.  The
> downloaded file will install a chm file with the VBS
> documentation.  This will give you the synatx for these
> functions.

> (URL WILL WRAP)

http://msdn.microsoft.com/downloads/default.asp?url=/downloads/topic....

- Show quoted text -

Quote:
> =/msdn-files/028/001/175/topic.xml

> Regards,
> Joe Earnest



> > Hi Joe,

> > Thanks for your reply. How about the second point, can I use script to
do
> > it.

> > Pls advice.



> > > Hi,

> > > On the first point, you have the right code, just
> > > the wrong numeric parameter.

> > > From a Torgeir Bakken post:

> > > ----

> > > sComputer = "."    ' use "." for local computer

> > > ' Use "Reboot_Force" for a forced reboot
> > > ShutDown sComputer, "Reboot"

> > > Sub ShutDown(sNode, sAction)

> > >   Const EWX_LOGOFF = 0
> > >   Const EWX_SHUTDOWN = 1
> > >   Const EWX_REBOOT = 2
> > >   Const EWX_FORCE = 4
> > >   Const EWX_POWEROFF = 8

> > >   Set oWMI = GetObject("winmgmts:" _
> > >      & "{impersonationLevel=impersonate,(Shutdown)}!\\" _
> > >      & sNode & "\root\cimv2")

> > >   Set colOperatingSystems = oWMI.ExecQuery _
> > >      ("Select * from Win32_OperatingSystem")
> > >   For Each obj in colOperatingSystems
> > >     Set oOS = obj :  Exit For
> > >   Next

> > >   sAction = LCase(sAction)

> > >   Select Case sAction
> > >     Case "logoff"
> > >       iCmd = EWX_LOGOFF
> > >     Case "logoff_force"
> > >       iCmd = EWX_LOGOFF + EWX_FORCE
> > >     Case "shutdown"
> > >       iCmd = EWX_SHUTDOWN
> > >     Case "shutdown_force"
> > >       iCmd = EWX_SHUTDOWN + EWX_FORCE
> > >     Case "reboot"
> > >       iCmd = EWX_REBOOT
> > >     Case "reboot_force"
> > >       iCmd = EWX_REBOOT + EWX_FORCE
> > >     Case "poweroff"
> > >       iCmd = EWX_POWEROFF
> > >     Case "poweroff_force"
> > >       iCmd = EWX_POWEROFF + EWX_FORCE
> > >     Case Else
> > >       ' Default value
> > >       iCmd = EWX_POWEROFF
> > >   End Select

> > >   oOS.Win32shutdown iCmd

> > > End Sub

> > > ----

> > > Joe Earnest



> > > > Hi,

> > > > I have written the following script to shutdown my computer after
> office
> > > > hours . I have the following question.

> > > > 1. Is there a way to force all my application to close and shutdown
?
> > > > 2. How can I modify this script so that at a specific date and time
> the
> > > > script will shutdown ?

> > > > Set colOperatingSystems =
> > > > GetObject("winmgmts:{(Shutdown)}").ExecQuery("Select * from
> > > > Win32_OperatingSystem")
> > > > For Each objOperatingSystem in colOperatingSystems
> > > > ObjOperatingSystem.Win32Shutdown(1)
> > > > Next

> > > > I hope someone could help because most of the time I am out of
office
> > and
> > > I
> > > > need my computer to turn on to process some data backup.

> > > > Thanks



Sat, 10 Sep 2005 00:57:25 GMT  
 
 [ 13 post ] 

 Relevant Pages 

1. Rerun a program automatically in wsh if it dies or is shutdown

2. How can I detect Browser shutdown?

3. Shutdown browser

4. How to shutdown windows from a web page

5. Shutdown windows using vbscript

6. Help: Modify shutdown routine

7. Windows Shutdown

8. how do i shutdown an IIS aplication

9. Shutdown using WSH??

10. Shutdown

11. HOW DO I SHUTDOWN

12. Shutdown and restart windows

 

 
Powered by phpBB® Forum Software