I know you can use:
Write-Host "Hello World"
command to echo information to the user, however the information shows in
the PowerShell window(CMD window).
How can PowerShell alert user in a Window form?
My second question is: how to run a .ps1 file without show up the powershell
window?
Cheers,
Jim
--
Jim Wang
MVP - Dynamics CRM
and usage:
msgbox "This is my titile" "some text in message box" "Information"
2) if you have PowerShell 1.0 version then you should place this code at a
top of script code after Param() section:
$cp = new-object Microsoft.CSharp.CSharpCodeProvider
$cpar = New-Object System.CodeDom.Compiler.CompilerParameters
$HideWindow = 0x0080
$ShowWindow = 0x0040
$Code = @"
using System;
using System.Runtime.InteropServices;
namespace Win32API
{
public class Window
{
[DllImport("user32.dll")]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr
hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);
}
}
"@
$cp.CompileAssemblyFromSource($cpar, $code)
$PSHandle = (Get-Process –id $pid).MainWindowHandle
[Win32API.Window]::SetWindowPos($PSHandle, 0, 0, 0, 0, 0, $HideWindow)
this will hide PS console.
if you have PowerShell V2 then you can use '-WindowStyle Hidden' option when
you call your script:
powershell.exe -WindowStyle Hidden script.ps1
--
WBR, Vadims Podans
MVP: PowerShell
PowerShell blog - www.sysadmins.lv
"Jim Wang" <Jim...@discussions.microsoft.com> rakstīja ziņojumā
"news:101238AB-5A4E-4D4B...@microsoft.com"...
I would really recommend checking out PrimalForms. You can find the
free version here: You can use a visual editor to design your form
and it will generate the code. Even if you don't end up using it
forever, it generates some great boilerplate code that really helps
you understand the options for generating forms in PowerShell.
Boots { Textblock "HELLO WORLD" -fontsize 48 }
And you could even do it -Async so that your script can continue and
just leave that message there for the user to discover and read later.
As for hiding the window, Vadim's script works ... you should check out
the tricks script on PoshCode: http://poshcode.org/search/HideWindow
It's basically a slightly more feature-full version of what Vadims
posted already, but it keeps track of the windows it hides, so you can
easily unhide them again later (and a few other things too). Of course,
it's a lot easier to just use PowerShell 2, if you can...
--
Joel
With PowerShell v2:
DOS>powershell -windowstyle hidden
Of course, you want the above to run a .ps1 as well...
Marco
>
> How can PowerShell alert user in a Window form?
>
Here using Windows PowerShell 2 programming
to demo some PowerShell BareFootin' WPF actions!
# Add some needed assemblies.
Add-Type –assemblyName PresentationFramework
Add-Type –assemblyName PresentationCore
Add-Type –assemblyName WindowsBase
" "
"Mmm perhaps one made a mistake?"
# Use a Here string - instead of defining
# all these WPF objects in Powershell.
$xamlString = @"
<Window
xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
Title="PowerShell BareFootin' WPF" SizeToContent="WidthAndHeight"
WindowStyle="ToolWindow" ResizeMode="NoResize"
>
<Label Name="alert" Padding="30" Foreground="Green" FontSize="35"
Content="Alert! Alert! Alert!" >
<Label.Background>
<LinearGradientBrush>
<GradientStop Color="Red" Offset="0" />
<GradientStop Color="White" Offset="0.5" />
<GradientStop Color="Red" Offset="1" />
</LinearGradientBrush>
</Label.Background>
<Label.Triggers>
<EventTrigger RoutedEvent="Label.Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard TargetProperty="Background.GradientStops[1].Color">
<ColorAnimation From="White" To="Black" Duration="0:0:4"
AutoReverse="True" />
</Storyboard>
</BeginStoryboard>
<BeginStoryboard>
<Storyboard TargetProperty="FontSize">
<DoubleAnimation To="52" Duration="0:0:4" AutoReverse="True"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Label.Triggers>
</Label>
</Window>
"@
[xml]$xaml = $xamlString
$control = [Windows.Markup.XamlReader]::Load( (New-Object
System.Xml.XmlNodeReader $xaml) )
$null = $control.ShowDialog()
" "
"Done!"
" "
Exit
Remember any PowerShell 2 user
can help one
for PowerShell 2 = WPF usage!
As always enjoy the automation of tools
within the Windows-based, .NET aware,
WPF accessible, multi-processes on the
same IP / Port usage, admin's automation tool,
powershell.exe!
Note that you need to run the code below in a single-threaded apartment. In
PowerShellPlus you can hold the Shift key during startup and check the STA
button, normal PowerShell.exe (at least V2) has the -STA commandline switch.
Is there a way to specify this STA requirement while PowerShell has already
been started?
thanx,
~Hans
"Flowering Weeds" <n...@addrs.ss> wrote in message
news:On5%23X6ICK...@TK2MSFTNGP02.phx.gbl...
In order to script WPF, you have to do one of three things:
· Run the Script in Graphical PowerShell, where WPF scripts will run
without any changes because Graphical PowerShell runspaces are STA.
· Run the script in PowerShell.exe and add the –STA script
· Create a background runspace that is STA, and run the script in
the background runspace
Got this via:
http://blogs.msdn.com/powershell/archive/2008/05/22/wpf-powershell-part-1-hello-world-welcome-to-the-week-of-wpf.aspx
"Hans Dingemans" <hansdi...@hotmail.com> wrote in message
news:euS6jZdC...@TK2MSFTNGP05.phx.gbl...