msg box cancel help in vbs

Discussion in 'Software' started by nfv111, Aug 20, 2008.

  1. nfv111

    nfv111 Private E-2

    the following vbscript will copy the Netscape folder. It has a OK and cancel button but I cant get the cancel to work. What I need it to do is if the user clicks on it, it just returns to Windows. Right now it just continues to execute. Any thoughts? Thanks

    msgbox("Please select OK to continue shutting down or X out and return to Windows"),vbOKCancel
    Dim shell
    Set shell = CreateObject("WScript.Shell")
    Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")
    Dim fld
    Set fld = fso.GetFolder("C:\Documents and Settings\user\Application Data\Netscape")
    Dim fl
    for each fl In fld.Files
    fl.Copy("Q:\Netscape\" & fl.Name)
    Next
    dim nFld
    for each nFld In fld.SubFolders
    nfld.Copy("Q:\Netscape\" & nFld.Name)
    Next
    Set fld = Nothing
    Set fso =Nothing
     
  2. PC-XT

    PC-XT Master Sergeant

    You need to catch the return value, check if Cancel was pressed, and quit if it was:
    Code:
    if msgbox("Please select OK to continue shutting down or X out and return to Windows",vbOKCancel)=2 then wscript.quit
    If you are shutting down Windows, you may need extra code to cancel the shutdown.

    BTW, you could use fso.FolderCopy instead of copying each file.
     
    Last edited: Aug 20, 2008

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds