How to restart and shutdown pc in winPE with vb net

Here I am going to disuses How to restart and shutdown pc in winPE with vb net .net framework 4. If you don’t know how to Add framework winPE Windows Preinstallation Environment  you can visit the link.  After integration success an application with dot net framework 4.0 in winPE, I got attension the application should have functionality to restart and shutdown. I normally tried shutdown with its parameters /r, /s, -r, -s but surprisingly it did not work for me in vb.net. After it I started to search on Internet how to restart computer in winPE with vb.net. At last I found “wpeutil“ command to reboot or shutdown pc in winPE. But the issue with command is it can only run DOS environment, there cmd window pop up and looks to bad to me. So I have to search some extra features to accomplish the task. The “Process” and ProcessStartInfo()commands made easy for me to compile a good application.

How to restart and shutdown pc in winPE with vb net

Note: – the following code does not work in Windows Environment it works only in winPE.

If you want to shutdown your PC in winPE, simply copy the following code and paste under button and run only in winPE.

Dim p As New Process
Dim psi As New ProcessStartInfo()
        psi.Verb = "runas" ' runas = Run As Administrator
        psi.FileName = "cmd.exe" ' File or exe to run (this cannot take arguments, use ProcessStartInfo.Arguments instead
        psi.Arguments = "/c wpeutil shutdown"
        psi.WindowStyle = ProcessWindowStyle.Hidden
        p.StartInfo = psi
        p.Start()
        p.WaitForExit()

If you want to restart your PC in winPE, simply copy the following code and paste under button and run only in winPE.

Dim p As New Process
Dim psi As New ProcessStartInfo()
        psi.Verb = "runas" ' runas = Run As Administrator
        psi.FileName = "cmd.exe" ' File or exe to run (this cannot take arguments, use ProcessStartInfo.Arguments instead
        psi.Arguments = "/c wpeutil reboot"
        psi.WindowStyle = ProcessWindowStyle.Hidden
        p.StartInfo = psi
        p.Start()
        p.WaitForExit()

Leave a Reply

Your email address will not be published. Required fields are marked *


*