Shutdown start up script

From: David (anonymous_at_discussions.microsoft.com)
Date: 02/22/04

  • Next message: Al Dunbar [MS-MVP]: "Re: Custom Attributes"
    Date: Sun, 22 Feb 2004 07:33:11 -0800
    
    

    >-----Original Message-----
    >I am wanted to create a script to shutdown my PC at 9:02pm
    >on Monday - Thursday and 5:02pm on Friday - Sunday. Is
    >this an easy task in NT, 2000, and XP?
    >.
    >

    I wanted to do something similar to this, but I only
    wanted machines to be rebooted only if they have been left
    on longer than x days.

    Heres what I came up with:

    I used a machine startup script (startupscript.cmd) to
    copy uptime.exe and uptimecheck.cmd to a local directory.
    It then creates a task that runs daily at 3am. The task
    does nothing if they are rebooted daily. You will need to
    replace %logonserver% with the name of a valid DC. This
    variable is not set until someone logs on.

    startupscript.cmd
    ---------------
    REM Create OIT directory under Windows directory and copy
    Uptime files to it
    if not exist %windir%\oit md %windir%\oit
    xcopy %logonserver%\netlogon\uptime.exe /d /c %windir%
    \oit\.
    xcopy %logonserver%\netlogon\uptimecheck.cmd /d /c %windir%
    \oit\.

    REM Schedule UptimeCheck Task
    Wscript shutdown.vbs
    exit

    shutdown.vbs
    ---------------
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:"
    & "{impersonationLevel=impersonate}!\\" & strComputer
    & "\root\cimv2")
    Set objNewJob = objWMIService.Get("Win32_ScheduledJob")

    errJobCreated = objNewJob.Create("%windir%
    \oit\uptimecheck.cmd", "********112200.000000-360", True ,
    1 OR 2 OR 4 OR 8 OR 16 OR 32 OR 64, , , JobID)

    uptimecheck.cmd
    ---------------
    c:
    cd %windir%\oit
    uptime > %computername%.txt
    FOR /f "eol=, tokens=6*" %%1 in (%computername%.txt) do if
    %%1 GEQ 7 shutdown.exe -r -f -t 120 -d p -c "OIT is
    restarting your computer in 2 minutes. Please save any
    work now. Thank you."


  • Next message: Al Dunbar [MS-MVP]: "Re: Custom Attributes"

    Relevant Pages

    • Re: Need Help..
      ... strComputer, strName, strModel, etc. works, then I can only guess the ... this part of the script is working. ... The part where we must add disconnected computers to the database i can't ... Dim strComputerName ' The Computer Name to be queried via WMI ...
      (microsoft.public.windows.server.scripting)
    • Re: Loop with out Do
      ... Set objLog = ... & vbNewLine & vbNewLine ... Also, strComputer will never be False, but ... When I fixed the problems in the second script, ...
      (microsoft.public.windows.server.scripting)
    • Re: VBScript and Out Put to Excel Worksheet
      ... removed them from the list and now the script works. ... Dim strComputer, strDN ... On Error GoTo 0 ...
      (microsoft.public.windows.server.scripting)
    • RE: This script wont run on a workgroup server
      ... Set objService = objLocator.ConnectServer(strComputer, "Root\Default", ... strUser, strPassword) ... > I have this script that I use on domain member servers and it runs just fine. ... > strPassword = objExplorer.Document.Body.All.UserPassword.Value ...
      (microsoft.public.scripting.wsh)
    • Re: Modifiy this script to read a nested "Computers" container
      ... I ran the below script and received the following error. ... There are computer accounts in both the top level OU called Site1 and ... ' input: strComputer ... Sub GetLocalAdmins ...
      (microsoft.public.scripting.wsh)