Is it possible to use a Windows 7 TaskDialog in PowerShell?
I’d like to convert the following messagebox to a TaskDialog:
[System.Windows.Forms.MessageBox]::Show(
"There are currently one or more Microsoft Office applications running.`n`nYou must close down all open Office applications before the template update can continue.",
"Updating Templates",
[System.Windows.Forms.MessageBoxButtons]::RetryCancel,
[System.Windows.Forms.MessageBoxIcon]::Warning )
Anyone know how/if this can be done?
Thanks,
Ben
You need to use Microsoft’s Windows API CodePack for this, it’s very simple, but although it will work fine from PowerShell ISE, PoshConsole, PowerGUI etc — I don’t believe it will work in PowerShell.exe because the console loads the wrong version of comctl32.dll (the common controls library).
Hopefully it’s obvious that the
$resultvalue is actually an enumeration value (of type[Microsoft.WindowsAPICodePack.Dialogs.TaskDialogResult]) … but in PowerShell you can basically treat it as a string or an int if you like.Of course, this is barely scratching the surface of what you can do with a TaskDialog — if you use it with just this code, it will look and behave very similarly to your current dialog — but you can explore the other possibilities yourself — I can recommend the TaskDialog builder tool from this MSDN Magazine Article as a way to learn the many options.