Я работаю над сценарием, который предлагает вам скопировать целые структуры папок, включая ACL (разрешения). Мой вопрос теперь в том, как я могу сделать так, чтобы когда я нажимал кнопку отмены во всплывающем окне, он действительно отменялся?
Я работаю с PowerShell
**#———————-Source Drive and Folder———————# [System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.VisualBasic’) | Out-Null $sourceDrive = [Microsoft.VisualBasic.Interaction]::InputBox(«Please enter the source drive for copying `n(e.g: C)», «source drive», «») $sourceFolder = [Microsoft.VisualBasic.Interaction]::InputBox(«Please enter the source folder for copying `n(e.g: FolderSomething)», «source folder», «») #———————-Source Drive and Folder———————# #——————-Destination Drive and Folder——————-# [System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.VisualBasic’) | Out-Null $destinationDrive = [Microsoft.VisualBasic.Interaction]::InputBox(«Please enter the destination drive for copying `n(e.g: D)», «destination drive», «») $destinationFolder = [Microsoft.VisualBasic.Interaction]::InputBox(«Please enter the destination folder for copying `n(e.g: Folder1Something2)», «destination folder», «») #——————-Destination Drive and Folder——————-# #———————Create new Folder for Copy———————# $createNewFolder = [Microsoft.VisualBasic.Interaction]::InputBox(«Do you want to create a new folder in this directory? `n(e.g: y/n)», «Create new folder», «») if($createNewFolder -eq «n»){ xcopy «$sourceDrive`:$sourceFolder» «$destinationDrive`:$destinationFolder» /O /X /E /H /K }elseif($createNewFolder -eq «y») { [System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.VisualBasic’) | Out-Null $newFolder = [Microsoft.VisualBasic.Interaction]::InputBox(«Please enter the name of the folder `n(e.g: somefolder)», «New folder», «») xcopy «$sourceDrive`:$sourceFolder» «$destinationDrive`:$newfolder$destinationFolder» /O /X /E /H /K }else { } #———————Create new Folder for Copy———————# #xcopy «$sourceDrive`:$sourceFolder» «$destinationDrive`:$destinationFolder» /O /X /E /H /K**
Это также было размещено на powershell.org: https://powershell.org/forums/topic/how-can-i-make-my-script-stop-when-clicked-on-the-cancel-button-2/
заранее спасибо
Мартин
Помог ли какой-либо из наших ответов? — person Martin Schmidt schedule 06.11.2020
Источник: