kof94 Posted April 1, 2006 Share Posted April 1, 2006 Anyone got any idea how to generate a Restart Yes/No box for post WPI/RunonceEx/batch etc.I wish to replace my present obligatory shutdown.exe restart.Thanks Link to comment Share on other sites More sharing options...
gunsmokingman Posted April 1, 2006 Share Posted April 1, 2006 (edited) 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 April 1, 2006 by gunsmokingman Link to comment Share on other sites More sharing options...
kof94 Posted April 1, 2006 Author Share Posted April 1, 2006 Thanks, exactly what I needed. Link to comment Share on other sites More sharing options...
gunsmokingman Posted April 1, 2006 Share Posted April 1, 2006 Your welcome Link to comment Share on other sites More sharing options...
ironside Posted April 1, 2006 Share Posted April 1, 2006 NirCmd v1.82 - Freeware command-line toolhttp://www.nirsoft.net/utils/nircmd.htmlExample: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 More sharing options...
gunsmokingman Posted April 1, 2006 Share Posted April 1, 2006 VBS script is better because you do not have to add nothing, it built in to the OS itself. Link to comment Share on other sites More sharing options...
danielvh Posted August 27, 2006 Share Posted August 27, 2006 Can I just stick that at the end of my batch file which is run from guirunonce? Link to comment Share on other sites More sharing options...
ZileXa Posted August 27, 2006 Share Posted August 27, 2006 Actually for VBS you need VBS support in Windows, some people remove VBS support with nLite. Link to comment Share on other sites More sharing options...
gunsmokingman Posted August 27, 2006 Share Posted August 27, 2006 (edited) 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.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 October 17, 2006 by gunsmokingman Link to comment Share on other sites More sharing options...
Bezalel Posted August 28, 2006 Share Posted August 28, 2006 Wouldn't it make sence to check if there are any PendingFileRenameOperations and only prompt the user if they exist. Link to comment Share on other sites More sharing options...
CoffeeFiend Posted August 28, 2006 Share Posted August 28, 2006 (edited) 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 August 28, 2006 by crahak Link to comment Share on other sites More sharing options...
gunsmokingman Posted August 28, 2006 Share Posted August 28, 2006 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 blankspot 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now