If the script finished I want a messagebox popup, but I don't know the if statement.
using (PowerShell PowerShellInstance = PowerShell.Create())
{
PowerShellInstance.AddScript("cmdkey /list | ForEach-Object{if($_ -like \"*Target:*\"){cmdkey /del:($_ -replace \" \",\"\" -replace \"Target:\",\"\")}}");
PowerShellInstance.Invoke();
if ()
{
MessageBox.Show("the process was successfully completed");
}
Invoke, you'll see that it will "Invoke the Command synchronously and return the output PSObject collection". So there's nothing to check (except perhaps catch one or more of the 12 documented exceptions that might be thrown on failure).