共用方式為


ICommandRuntime.ShouldContinue Method

Definition

Overloads

ShouldContinue(String, String)

Called by a cmdlet to confirm an operation or grouping of operations with the user. This differs from ShouldProcess in that it is not affected by preference settings or command-line parameters, it always does the query. This variant only offers Yes/No, not YesToAll/NoToAll.

ShouldContinue(String, String, Boolean, Boolean)

Called to confirm an operation or grouping of operations with the user. This differs from ShouldProcess in that it is not affected by preference settings or command-line parameters, it always does the query. This variant offers Yes, No, YesToAll and NoToAll.

ShouldContinue(String, String)

Called by a cmdlet to confirm an operation or grouping of operations with the user. This differs from ShouldProcess in that it is not affected by preference settings or command-line parameters, it always does the query. This variant only offers Yes/No, not YesToAll/NoToAll.

public:
 bool ShouldContinue(System::String ^ query, System::String ^ caption);
public:
 bool ShouldContinue(Platform::String ^ query, Platform::String ^ caption);
bool ShouldContinue(std::wstring const & query, std::wstring const & caption);
public bool ShouldContinue (string query, string caption);
public bool ShouldContinue (string? query, string? caption);
abstract member ShouldContinue : string * string -> bool
Public Function ShouldContinue (query As String, caption As String) As Boolean

Parameters

query
String

Textual query of whether the action should be performed, usually in the form of a question.

caption
String

Caption of the window which may be displayed when the user is prompted whether or not to perform the action. It may be displayed by some hosts, but not all.

Returns

If ShouldContinue returns true, the operation should be performed. If ShouldContinue returns false, the operation should not be performed, and the Cmdlet should move on to the next target resource.

Remarks

Cmdlets using ShouldContinue should also offer a "bool Force" parameter which bypasses the calls to ShouldContinue and ShouldProcess. If this is not done, it will be difficult to use the Cmdlet from scripts and non-interactive hosts.

Cmdlets using ShouldContinue must still verify operations which will make changes using ShouldProcess. This will assure that settings such as -WhatIf work properly. You may call ShouldContinue either before or after ShouldProcess.

ShouldContinue may only be called during a call to this Cmdlet's implementation of ProcessRecord, BeginProcessing or EndProcessing, and only from that thread.

Cmdlets may have different "classes" of confirmations. For example, "del" confirms whether files in a particular directory should be deleted, whether read-only files should be deleted, etc. Cmdlets can use ShouldContinue to store YesToAll/NoToAll members for each such "class" to keep track of whether the user has confirmed "delete all read-only files" etc. ShouldProcess offers YesToAll/NoToAll automatically, but answering YesToAll or NoToAll applies to all subsequent calls to ShouldProcess for the Cmdlet instance.

An implementation should prompt the user in an appropriate manner and return true or false. An alternative trivial implementation would be to just return true all the time.

See also

Applies to

ShouldContinue(String, String, Boolean, Boolean)

Called to confirm an operation or grouping of operations with the user. This differs from ShouldProcess in that it is not affected by preference settings or command-line parameters, it always does the query. This variant offers Yes, No, YesToAll and NoToAll.

public:
 bool ShouldContinue(System::String ^ query, System::String ^ caption, bool % yesToAll, bool % noToAll);
bool ShouldContinue(std::wstring const & query, std::wstring const & caption, bool & yesToAll, bool & noToAll);
public bool ShouldContinue (string query, string caption, ref bool yesToAll, ref bool noToAll);
public bool ShouldContinue (string? query, string? caption, ref bool yesToAll, ref bool noToAll);
abstract member ShouldContinue : string * string * bool * bool -> bool
Public Function ShouldContinue (query As String, caption As String, ByRef yesToAll As Boolean, ByRef noToAll As Boolean) As Boolean

Parameters

query
String

Textual query of whether the action should be performed, usually in the form of a question.

caption
String

Caption of the window which may be displayed when the user is prompted whether or not to perform the action. It may be displayed by some hosts, but not all.

yesToAll
Boolean

true iff user selects YesToAll. If this is already true, ShouldContinue will bypass the prompt and return true.

noToAll
Boolean

true iff user selects NoToAll. If this is already true, ShouldContinue will bypass the prompt and return false.

Returns

If ShouldContinue returns true, the operation should be performed. If ShouldContinue returns false, the operation should not be performed, and the Cmdlet should move on to the next target resource.

Remarks

Cmdlets using ShouldContinue should also offer a "bool Force" parameter which bypasses the calls to ShouldContinue and ShouldProcess. If this is not done, it will be difficult to use the Cmdlet from scripts and non-interactive hosts.

Cmdlets using ShouldContinue must still verify operations which will make changes using ShouldProcess. This will assure that settings such as -WhatIf work properly. You may call ShouldContinue either before or after ShouldProcess.

ShouldContinue may only be called during a call to this Cmdlet's implementation of ProcessRecord, BeginProcessing or EndProcessing, and only from that thread.

Cmdlets may have different "classes" of confirmations. For example, "del" confirms whether files in a particular directory should be deleted, whether read-only files should be deleted, etc. Cmdlets can use ShouldContinue to store YesToAll/NoToAll members for each such "class" to keep track of whether the user has confirmed "delete all read-only files" etc. ShouldProcess offers YesToAll/NoToAll automatically, but answering YesToAll or NoToAll applies to all subsequent calls to ShouldProcess for the Cmdlet instance.

An implementation should prompt the user in an appropriate manner and return true or false. An alternative trivial implementation would be to just return true all the time.

See also

Applies to