Wish list : add Shutdown/Restart Windows button

Hello, I love this beta and ‘PE is perfect for me that I don’t use monitor.
At the moment I can confirm that’s all working fine with my 5k+ and with this version of pitool asgaard wrath and senua’s sacrifice working well!
I suggest to add shutdown/restart buttons ( like steam big picture) .
My pc spec:I9 9900k 32gb 2080ti oc

3 Likes

Not sure if this is the same for everyone but my pc always asks for confirmation to shutdown because pitool is prohibiting that

1 Like

I haven’t seen that for a while actually. I think it might only happen if it’s not minimized to tray?

1 Like

Actually, I think it stopped happening after enabling the “Hide to the taskbar when you click the close” option… :wink:

Just checked and it happens when PiTool is not minimized so a combination of the option and pressing close (“hiding it”) is what makes it not happen.

Since I have it starting on Windows start-up (minimized to tray) I would be able to just pick up the headset and handle everything from there… :wink:

2 Likes

Good idea, but that would need to be handled by a batch command that I can call upon a button click on the UI.
I dont think even C# allow a force reboot.

@mirage335 do you think you could create a batch that instantly quits PiTool and forces system reboot? Thanks!

2 Likes

you can do it like this:

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);
    }
}
3 Likes

Wow I didnt know it was possible to invoke that. Thanks Kev!

2 Likes

I think you can also do it this way:

var psi = new ProcessStartInfo("shutdown","/s /t 0");
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
Process.Start(psi);
3 Likes

Thanks! I never even googled this, as I took for granted the function was not supported. There are a bunch of things that are quite “prohibited” with C# and needs workaround to get these working. Such as system volume. I have tried maybe 10 solutions but none of them actually triggers the system master volume, but only the mixer volumes (app based). Also, a lot of C# libraries are not supported by Unity, so they cant be used.

I can make the volume go up and down or MUTE, but not set it on a certain level with a slider in steps (0.0f to 1.0f for instance)
Thats why I have temporarily removed the volume slider - I hope soon some skilled coder can help me with that :slight_smile:

I will probably re-do the Quit button and make a few selectable options (Restart App, Quit App, Restart Windows etc)

2 Likes

you can use a cmd with this line:

Reboot

%windir%\system32\shutdown -r -f -c “Restart by Pimax Experience in 60 Seconds” -t 60

Shutdown

%windir%\system32\shutdown -f -c “Shutdown by Pimax Experience in 60 Seconds” -t 60

I prefer wait some seconds ( 60 or more) before shutdown

3 Likes

@SweViver I was going to answer in the affirmative, but looks like others beat me to it! I tentatively recommend PimaxUSA’s second suggestion, rather than the first.

@PimaxUSA I like the second solution you offered, which seems to use a typical os.system sort of call to the shutdown binary, better. I know MS has publicly committed to the future of batch, presumably such binaries as well, and this approach is more portable to other operating systems. Then again, maybe I am just pedantic - I have developed a very conservative approach to such things.

2 Likes