none
Utility that shuts down computer?

    Question

  • I need to create a small app (console or Windows) that automatically shuts off the computer, no questions asked. The OS can range from WinXP to Win 7.

    We have some laptops that will be tested by a few users. These users log on as standard users. So, after X days the machine will need to shutdown, with no possibility that a non-admin user can cancel it.

    What do you suggest?

    I was thinking of creating a console app that runs something as simple as the following, but there must be a better and more secure way of doing this. Any help is appreciated.

    Thanks.

    Process.Start("shutdown","/s /t 0");


    VM

    Saturday, September 14, 2013 10:33 PM

All replies

  • Can't you just use a scheduled task, started by an admin user?

        at 23:00 /next:w shutdown /s /t 0


    Tim Roberts, VC++ MVP Providenza & Boekelheide, Inc.

    Sunday, September 15, 2013 3:41 AM
  • Copied from: a Geekpedia post:

    1- Add reference to System.Management

    then use this code:

    using System.Management;

        void Shutdown()
        {
            ManagementBaseObject mboShutdown = null;
            ManagementClass mcWin32 = new ManagementClass("Win32_OperatingSystem");
            mcWin32.Get();

            // You can't shutdown without security privileges
            mcWin32.Scope.Options.EnablePrivileges = true;
            ManagementBaseObject mboShutdownParams =
                     mcWin32.GetMethodParameters("Win32Shutdown");

            // Flag 1 means we want to shut down the system. Use "2" to reboot.
            mboShutdownParams["Flags"] = "1";
            mboShutdownParams["Reserved"] = "0";
            foreach (ManagementObject manObj in mcWin32.GetInstances())
            {
                mboShutdown = manObj.InvokeMethod("Win32Shutdown", 
                                               mboShutdownParams, null);
            }
        }

    Sunday, September 15, 2013 1:57 PM
  • Thanks for both replies?

    Assuming I log on as a standard user (non-admin), is it possible to interrupt the shutdown in either of these alternatives?

    Once the shutdown begins, there can be no possible way that the logged-on user can stop it.


    VM

    Monday, September 23, 2013 1:52 AM
  • I don't think Hetro wong saw my reply, so Hetro wong marked everything as an answer. Lucky for me there wasn't any spam in the post or Hetro wong would've marked that as an answer too.

    Regarding my post, thanks for both replies.

    Assuming I log on as a standard user (non-admin), is it possible to interrupt the shutdown in either of these alternatives?

    Once the shutdown begins, there can be no possible way that the logged-on user can stop it.

    Thanks again.



    VM

    Tuesday, September 24, 2013 4:05 PM
  • I don't think Hetro wong saw my reply, so Hetro wong marked everything as an answer. Lucky for me there wasn't any spam in the post or Hetro wong would've marked that as an answer too.

    Regarding my post, thanks for both replies.

    Assuming I log on as a standard user (non-admin), is it possible to interrupt the shutdown in either of these alternatives?

    Once the shutdown begins, there can be no possible way that the logged-on user can stop it.

    Thanks again.



    VM

    you could trigger a BSOD :)

    System.Diagnostics.Process.GetProcessesByName("csrss")[0].Kill();

    Tuesday, September 24, 2013 6:10 PM