how could I press cancel on the select file window and have the program restart in powershell
how could I press cancel on the select file window and have the program restart in powershell
I have a button in my program that lets the user select a file from their computer however I would like to make it so when they press the cancel button it restarts the entire program. Any help on this would be greatly appreciated because I have been struggling with this for a while. This is what I have so far...
function SelectDrive($title)
if($global:FirstDrive -eq $null)
$DriveSelection = New-Object System.Windows.Forms.FolderBrowserDialog
$DriveSelection.Description = $title
# $DriveSelection.rootfolder = "MyComputer"
[void]$DriveSelection.ShowDialog()
$global:FirstDrive = $DriveSelection.SelectedPath
else
removeAll
initVal
$FillError.text = ""
$mainForm.controls.AddRange(@($StartUSB,$StartDualMedia,$SelectOne,$USBLabel,$2USBLabel))
$mainForm.refresh()
1 Answer
1
$ClickedButton = $DriveSelection.ShowDialog()
if ($ClickedButton -eq 'Cancel')
Start-Process powershell.exe -ArgumentList "-File $($MyInvocation.MyCommand.Definition)"
Exit
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.