Jump to content

Post install Restart Yes/No box


Recommended Posts


Vbs message box, with a forced reboot using WMI if user selects yes.

Const LogOff = 0,  Shutdown = 1, Reboot = 2,PowerOff = 8
strComputer = "."
Dim Act, Reply
Set Act = CreateObject("Wscript.Shell")
Reply = Msgbox("Did you want to restart now? ", 4 + 32, "Restart Or Continue")
If Reply = 6 Then '''' FORCED REBOOT USING WMI
Set WMISrv = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}\\" & strComputer & "\root\cimv2")
Set ObjOS = WMISrv.ExecQuery("Select * from Win32_OperatingSystem")
For Each StrOS in ObjOS
StrOS.Win32Shutdown(Reboot + 4)
Next
End If
If Reply = 7 Then
msgbox "User selected to restart later",0 + 32,"User Cancel Restart"
End If

Edited by gunsmokingman
Link to comment
Share on other sites

NirCmd v1.82 - Freeware command-line tool

http://www.nirsoft.net/utils/nircmd.html

Example:

Ask if you want to reboot, and if you answer 'Yes', reboot the computer.

nircmd.exe qboxcom "Do you want to reboot ?" "question" exitwin reboot

Link to comment
Share on other sites

  • 4 months later...
Actually for VBS you need VBS support in Windows, some people remove VBS support with nLite.

The original poster did not indicate if he removed anything at all with nLite, and not all members use nLite.

If you removed VBS support then you would not be able to run some thing like this.

RebootHta.PNG

Save As YesNoReboot.Hta

<HTML><HEAD><Title>Reboot The Computer</Title>
<HTA:APPLICATION
ID="Reboot Computer" APPLICATIONNAME="Reboot The Computer"
INNERBORDER ="No" Border="Thin"
BORDERSTYLE ="complex" SysMenu="Yes"
SCROLLFLAT="No" SCROLL="No"
SingleInstance="Yes" WindowState="Normal"
ShowInTaskbar="Yes" Caption="Yes"
MaximizeButton="No" MinimizeButton="No"
Icon="%SystemRoot%\Explorer.exe">
<!-- ================== -->
<STYLE type="text/css">
BODY
{
font:9.75pt; font-family: Verdana, Palatino Linotype;
color:#000080; font-weight: Bold-Italic;
filter:progid:DXImageTransform.Microsoft.Gradient
(GradientType=0,StartColorStr='#E2E2E2',EndColorStr='#6e6e6e);
padding-top: 1; padding-bottom: 1; Text-Align: Center;
}
TD.Style1
{
font:8.75pt; font-family: Verdana, Palatino Linotype;
color:#000080; font-weight: Bold-Italic;
}
.Button
{
font: 8.75pt; font-family: Verdana, Palatino Linotype; color: #3E3E3E;
filter:progid:DXImageTransform.Microsoft.Gradient
(GradientType=0,StartColorStr='#E2E2E2',EndColorStr='#8e8e8e');
padding-top: 1; padding-bottom: 2; Text-Align: Center; Width: 47; Height: 21;
border-left: 1px Transparent; border-right: 2px Transparent;
border-top: 1px Transparent; border-Bottom: 2px Transparent;
}
</STYLE>
<!-- ================== -->
<script Language="JavaScript">
window.resizeTo (325,150),window.moveTo (300,325);
var LogOff = 0, Shutdown = 1, Reboot = 2, PowerOff = 8, strComputer = ".", WMISrv = "", ObjOS = "";
var Act = new ActiveXObject("Wscript.Shell");
var Fso = new ActiveXObject("Scripting.FileSystemObject");
var Hta = Act.ExpandEnvironmentStrings("%SystemDrive%\\YesNoReboot.Hta");
var Uname = Act.ExpandEnvironmentStrings("%UserName%");
//-> Delete File If Ran From A SFX or If Exists On %SystemDrive%\\YesNoReboot.Hta
function ExitHta() { if (Fso.FileExists(Hta)) { Fso.DeleteFile(Hta),window.close();} else {window.close();}}
</SCRIPT>
<!-- ================== -->
<script language="VBScript">
Function window_OnLoad() : Txt1.innerHTML = Uname : End Function
Function RebootComputer()
Set WMISrv = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}\\" & strComputer & "\root\cimv2")
Set ObjOS = WMISrv.ExecQuery("Select * from Win32_OperatingSystem")
For Each StrOS in ObjOS : StrOS.Win32Shutdown(Reboot + 4) : Next
End function
</SCRIPT></HEAD>
<!-- ================== --><Body Scroll='No'> <!-- USER NAME SPAN --><Span ID='Txt1'></Span>
<!-- TABLE AND TD FOR THE TEXT MESSAGE -->
<Table><TD Class='Style1' VAlign='Top'>Would you like to Reboot the Computer now?</TD></Table>
<!-- ===== EMPTY SPACE ===== -->
<Table><TD Height='16'> </TD></Table>
<!-- ===== TABLE FOR THE BUTTONS START ===== --><Table>
<!-- ===== BUTTON YES ===== -->
<TD Width='61' Align='Center'><Input Type='Button' Class='Button'onmouseout="this.style.color='#3E3E3E';"
onmouseover="this.style.color='#000080';" Style='cursor:Hand;' Value='Yes' OnClick='RebootComputer()'></TD>
<!-- ===== BUTTON NO ===== -->
<TD Width='61' Align='Center'><Input Type='Button' Class='Button' onmouseout="this.style.color='#3E3E3E';"
onmouseover="this.style.color='#000080';" Style='cursor:Hand;' Value='No' OnClick='ExitHta()'></TD>
<!-- ====== TABLE FOR THE BUTTONS END ====== --></Table></Body></HTML>

Edited by gunsmokingman
Link to comment
Share on other sites

VBS script is better because you do not have to add nothing, it built in to the OS itself.

A script made in vbscript is not automatically better than some app just because the language used is built into the OS. I'd say it's more of a question of how well it does what it's meant to do.

And between adding a vbscript to your disc or adding a little 3rd party utility, there's not much difference either. Your script didn't come with windows anymore than that utility - they're both "3rd party" if I can say. What language was used to create it (c++ or vbscript or whatever) or which way it's executed (compiled win32 binary or an interpreted script) doesn't matter all that much.

There's many ways to shutdown a PC too... There's API calls for that e.g. ExitWindowsEx and InitiateSystemShutdownEx (use via Interop / P/Invoke if req'd), utilities built right into windows (shutdown.exe) and similar 3rd party utilities, and other ways - like the WMI method you've used (which also can have issues - like not having SeShutdownPrivilege in local security policy).

You just can't say it's better because windows supports vbscript (which again can be removed or not supported right, have it's extension's association messed up in registry or whatever). It depends mainly on what method is best suited to reboot your PC i.e. For Win9x, forget about WMI... There's "no one-size-fits-all" solution. There are different scenarios, and people have preferences (compiled apps - open or closed source, basic scripts, methods of rebooting, etc).

WMI is very handy for remote management of PCs, but in this case it's only acting as a wrapper that calls InitiateSystemShutdownEx for you (just as shutdown.exe and picking reboot in start menu does). Calling it directly from native win32 code works just as well if not better (no need to interpret a script and bypass "wrappers") -- my 0.02$ HTAs only have even more overhead (IE takes quite a fair amount of RAM just for a messagebox) and requirements (IE 5.5+, and some features could be disabled as well)

I'm not saying vbscript isn't a good solution or anything. I'm just saying it isn't the only nor automatically the best one either. Others can pick whatever they prefer/think is best/works best for them... Your favorite/ultimate best solution ever != everyone else's preferred solution.

Edited by crahak
Link to comment
Share on other sites

Wouldn't it make sence to check if there are any PendingFileRenameOperations and only prompt the user if they exist.

That would be up to the individual person using this. If there is no name to get all it will produce is a blank

spot above the Would you like to Reboot the Computer now?

This was just a demo to show that if you removed the VBS suppport the script inside the HTA would fail.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...