0

I'm trying to run a script that prompts a user for a location and once that location has been selected, the script will copy IE favorites to that location .(It's part of a bigger project to copy multiple directories to a location of your choice)

It starts off with a VBS script to create the prompt, then I create a variable based on what's selected. Then the script copies IE favorites to that selected location. The problem is, if I select "cancel" the script runs anyway!

Any help is much appreciated!

Code: (Batch Script)

@echo off

For /F "Tokens=1 Delims=" %%I In ('cscript //nologo BrowseFolder.vbs') Do Set _FolderName=%%I

set dest=%_FolderName%

md "%dest%\UserBackup" &md "%dest%\UserBackup\Favorites" &ROBOCOPY /E /XJ "%userprofile%\Favorites" "%dest%\UserBackup\Favorites"  

Code: (VBS Script) - Save as "BrowseFolder.vbs"If you want to run it as an example.

Const MY_COMPUTER = &H11&
Const WINDOW_HANDLE = 0
Const OPTIONS = 0

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(MY_COMPUTER)
Set objFolderItem = objFolder.Self
strPath = objFolderItem.Path

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder _
(WINDOW_HANDLE, "Please select the destination for your data:", OPTIONS, strPath)

If objFolder Is Nothing Then
Wscript.Quit
End If

Set objFolderItem = objFolder.Self
objPath = objFolderItem.Path

Wscript.Echo objPath

Thank you in advance!

PHANDI
  • 3
  • 1

1 Answers1

1

The windows batch still runs because you don't check if the variable passed back is empty or not. The cancel button on the VBs Script will only cancel the VBS Script.

Try this in your windows batch file:

For /F "Tokens=1 Delims=" %%I In ('cscript //nologo BrowseFolder.vbs') Do Set _FolderName=%%I

IF [%_FolderName%] == [] GOTO EndBatch

set dest=%_FolderName%

md "%dest%\UserBackup" &md "%dest%\UserBackup\Favorites" &ROBOCOPY /E /XJ "%userprofile%\Favorites" "%dest%\UserBackup\Favorites"

:EndBatch
Community
  • 1
  • 1
Eric S
  • 1,336
  • 15
  • 20