Helpe needed with Script

Posted on 2011-10-23
Last Modified: 2012-12-24
I need help creating a script to do the following:

reboot & force apps that are hung closed on weekdays at around 11PM. I want to be able to control which machines this executed on by manipulating a text file that will hold the  host names.

Thank you.
Question by:bahti1777
    LVL 7

    Expert Comment

    SHUTDOWN -r -f -t 01

    thats the command from MSDODS prompt.

    -r) reboot
    -f) force close apps
    -t 1) wait 1 second

    Please refer to this MS reference for the reboot command:

    You could alternatively:

    SHUTDOWN -r -f -t 01 -m \\computername

    This will restart a computer remotely if it's part of a workgroup or domain and has NetBIOS up and running.
    LVL 14

    Accepted Solution

    If you want to do reboot multiple computers I would recommend to use the PsShutdown tool from the Microsoft's Sysinternals Suite - is freeware, will not need an install to the "admin PC" from where you will shutdown remoteley all the required PC's/Servers and the most important thing - it will allow you to set the HOUR:MINUTE at which to execute the shutdown command - the "normal" shutdown command from operating system will allow to set the INTERVAL (in seconds) from the current time before will do the shutdown which is pretty hard to calculate if you want to run the command NOW to be executed at 11 PM.

    So the command witl be like this:

    PSSHUTDOWN @ComputerList.txt -r -f -t 23:00

    For more options for PSSHUTDOWN command see the download link mentioned above.
    LVL 43

    Assisted Solution

    by:Steve Knight
    To add to the first post you can do that wth multiple entries in a rtext file with a for loop:

    @echo off
    for /f "tokens=*" %%a in ('type serverlist.txt') do SHUTDOWN -r -f -t 01 -m \\%%a

    If using  from command line rather than batch file (don't call it shutdown.cmd or it will be a big loop...) change the %% for single %


    LVL 10

    Expert Comment

    Use dragon-it's batch file to be run by a schedules task, at 11PM every day.

    Also, If you call it directly from a scheduled task, without a batch file, use only one % as described by dragon-it, include the full path of "serverlist.txt", and between double quots " if it includes spaces.

    for /f "tokens=*" %a in ('type "C:\Batch Files\serverlist.txt"') do SHUTDOWN -r -f -t 01 -m \\%a

    Another version would be:
    for /f "usebackq delims=" %a in ("C:\Batch Files\serverlist.txt") do SHUTDOWN -r -f -t 1 -m \\%a

    LVL 43

    Expert Comment

    by:Steve Knight
    good points.  also of course make sure scheduled with rights to shutdown other workstations, e.g. Domain admin a/c or given the required user rights on those machines security polcieisy and ntfs perms to serverlist file
    LVL 10

    Expert Comment

    And by the way, it's better to use a local or domain account that will have limmited rights to perform a scheduled task on a PC that will run a batch file. That gives unlimmited power to a knolwdgable user, my modifying the batch file.
    LVL 43

    Expert Comment

    by:Steve Knight
    true, as suggested would only really need the user right in security to shutdown which could be added using a group policy most easily.

    LVL 26

    Expert Comment

    This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Companies that have implemented Microsoft’s Active Directory need to ensure that the Active Directory is configured and operating properly. If there are issues found and not resolved, it eventually leads the components to fail or stop working and fi…
    Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
    This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
    This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now