Powershell tool : How to quickly build a GUI with Powershell and XAML
https://www.systanddeploy.com/2015/10/powershell-tool-how-to-quickly-build.html
In this post I will show you a quick way to create your own Powershell GUI.
I have rebuild a tool that I have already shared on my blog : Microsoft EXE extractor that I have done using "PrimalForms Community Edition".
In order to build the GUI i used Visual Studio 2012.
Some explanations about XAML and WPF
- https://msdn.microsoft.com/en-us/library/vstudio/ms752059(v=vs.100).aspx
- http://www.wpf-tutorial.com/xaml/basic-xaml/
- http://www.wpftutorial.net/StackPanel.html
- http://www.wpf-tutorial.com/panels/stackpanel/
Why WPF and not Windows Forms
- WPF is easy to create
- WPF design is better
- Possibility to reuse your old code
- WPF is newer
More informations about WPF between Windows Forms
- http://www.wpf-tutorial.com/about-wpf/wpf-vs-winforms/
- http://www.infragistics.com/community/blogs/devtoolsguy/archive/2015/04/17/windows-presentation-foundation-vs-winforms.aspx
- http://www.wiseowl.co.uk/blog/s308/wpf-winforms.htm
Build the GUI with Visual Studio
- Select "New project"
- Select "WPF applications"
Choose WPF applications |
- Select all controls you want in the side bar
Controls list |
- In the below part you can see the appropriate XAML code
XAML overview |
How to link the XAML and the PS1 script ?
- The first step is to load the XAML from your PS1, as below :
- Remove the "x:Class" part from you XAML at the first line.
<Window x:Class="application_name.MainWindow"
In order to manipulate your controls with the ps1 you have to name them in the xaml file.
You just have to add x:Name="button_test" to your control, as below :
- <RadioButton x:Name="test" Content="test"/>
- $button_test= $Form.findname("button_test")
Tested environments
- Powershell v2
- Powershell v3
- Powershell v4
- Windows 7 x86
- Windows 7 x64
You can find in the below rar file the new Microsoft EXE exctrator tool.
You can extract the content in order to get the XAML and PS1 files.
Download the Tool |
5 commentaires
better than AdminScriptEditor ?
http://www.itninja.com/community/admin-script-editor
(need to be registered to download the tool)
I don't know it, but unless I'm wrong it seems to be a script editor like primalform, visualstudio ...
So I guess you can also use XAML and Powershell with it.
Dam is back avec un top billet !!!
Merci Nico ☺☺
Nice post and good information. Thanks for sharing.
basic computer skills test
google adwords test
Enregistrer un commentaire