TekNetics Posted June 14, 2007 Share Posted June 14, 2007 folks; I'm really new at vbscripting for windows but have managed to work out some of my issues. I'm stuck on closing the script early if a user clicks the cancel button in a msgbox. I can get the result code but even using wscript.quit the script continues to run when I click cancel in the msgbox box. Here's a snippet of the script I am working on On error resume next MsgBox "This utility will close ALL instances of Microsoft Access.", 1+32 If result = 2 then wscript.quit For each Process in GetObject("winmgmts:").InstancesOf ("win32_process") If ucase(Process.name) = ucase("msaccess.exe") Then Process.Terminate End IF Next Msgbox "Time to continue with other steps" The idea is to close the script if the Cancel button is pressed or continue if OK is pressed. Appologies for the rookie question but I can't find any guidance on this . Thanks Link to comment https://www.neowin.net/forum/topic/567264-exitting-a-vbscript-based-on-msgbox-result/ Share on other sites More sharing options...
0 pacifica Posted June 14, 2007 Share Posted June 14, 2007 (edited) like this... result = MsgBox("This utility will close ALL instances of Microsoft Access.", vbOkCancel) if(result=vbCancel)Then ' or result=2 wscript.echo "you chose 'cancel'. exiting script." wscript.quit else WScript.Echo "you chose 'ok'." end If you either add your constant values together for the display icon or you use the intrinsic name (vbOkCancel, etc.) for instance, your "1+32" displays the ok\cancel options with the question mark image in the dialog box. not sure if that's what you were aiming for... here's a list of the contants... msgbox constants Link to comment https://www.neowin.net/forum/topic/567264-exitting-a-vbscript-based-on-msgbox-result/#findComment-588626232 Share on other sites More sharing options...
0 TekNetics Posted June 14, 2007 Author Share Posted June 14, 2007 Thanks pacifica. That helps a ton. More assistance if possible. Once I have determined if the user wants to continue, there are a few additional steps that will follow. Each step has the potential to error, present an error message, user clicks OK and the script quits. What's the best way to structure this. Here is some more of the script. 'Check to see if USERFOLDER exists 'if not then create the folder 'yes then delete all files in the folder If NOT objFSO.FolderExists(strUSERFOLDER) then objFSO.CreateFolder(strUSERFOLDER) else objFSO.DeleteFile(strUSERFOLDER & strALLFILES) numerr = Err.number abouterr = Err.description If numerr <> 0 Then MsgBox "Please contact HELPDESK and provide the following information" &vbCRLF&vbCRLF& "Error number: " &numerr&vbCRLF& "Description: " &abouterr&vbCRLF& "data: " &strUSERFOLDER, 0+16, "ERROR with User folder" Err.Clear 'COPY CHIP.MDE to local system objFSO.CopyFile strSRCFOLDER&strCHIPMDE, strUSERFOLDER numerr = Err.number abouterr = Err.description If numerr <> 0 Then MsgBox "Please contact HELPDESK and provide the following information" &vbCRLF&vbCRLF& "Error number: " &numerr&vbCRLF& "Description: " &abouterr&vbCRLF& "Data: " &vbCRLF& " " &strSRCFOLDER&strCHIPMDE &vbCRLF& " " &strUSERFOLDER&strCHIPMDE, 0+16, "ERROR copying CHIP.MDE" Err.clear If the first section fails, I want the script to exit when the user presses OK, ditto with the second section. there are 3 more sections after this. thanks again Link to comment https://www.neowin.net/forum/topic/567264-exitting-a-vbscript-based-on-msgbox-result/#findComment-588626322 Share on other sites More sharing options...
0 +primortal Subscriber² Posted June 14, 2007 Subscriber² Share Posted June 14, 2007 (edited) you could do this instead for your if statements (sorta the samething pacifica posted) If numerr <> 0 then MsgBox "Please contact HELPDESK and provide the following information" &vbCRLF&vbCRLF& "Error number: " &numerr&vbCRLF& "Description: " &abouterr&vbCRLF& "data: " &strUSERFOLDER, 0+16, "ERROR with User folder" wscript.quit End if Edited June 14, 2007 by primortal Link to comment https://www.neowin.net/forum/topic/567264-exitting-a-vbscript-based-on-msgbox-result/#findComment-588626331 Share on other sites More sharing options...
0 TekNetics Posted June 14, 2007 Author Share Posted June 14, 2007 Thanks. Everything works the way i had originally envisioned it. Any recommendations for learning vbScripting for Windows...good books or programs...editors (I'm using Context - it is pretty basic) One other question, Is it possible to compile .vbs files into exe's or is it worth it? Link to comment https://www.neowin.net/forum/topic/567264-exitting-a-vbscript-based-on-msgbox-result/#findComment-588626538 Share on other sites More sharing options...
0 +primortal Subscriber² Posted June 14, 2007 Subscriber² Share Posted June 14, 2007 Here is a quick program reference guide on vbscript from ms http://www.microsoft.com/downloads/details...;DisplayLang=en Link to comment https://www.neowin.net/forum/topic/567264-exitting-a-vbscript-based-on-msgbox-result/#findComment-588626598 Share on other sites More sharing options...
Question
TekNetics
folks;
I'm really new at vbscripting for windows but have managed to work out some of my issues.
I'm stuck on closing the script early if a user clicks the cancel button in a msgbox.
I can get the result code but even using wscript.quit the script continues to run when I click cancel in the msgbox box.
Here's a snippet of the script I am working on
On error resume next
MsgBox "This utility will close ALL instances of Microsoft Access.", 1+32
If result = 2 then wscript.quit
For each Process in GetObject("winmgmts:").InstancesOf ("win32_process")
If ucase(Process.name) = ucase("msaccess.exe") Then
Process.Terminate
End IF
Next
Msgbox "Time to continue with other steps"
The idea is to close the script if the Cancel button is pressed or continue if OK is pressed.
Appologies for the rookie question but I can't find any guidance on this .
Thanks
Link to comment
https://www.neowin.net/forum/topic/567264-exitting-a-vbscript-based-on-msgbox-result/Share on other sites
5 answers to this question
Recommended Posts