Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

Using System.Windows.Window from PowerShell

$
0
0

Hi

I am playing with the recently blogged Lock-Screen function (Temporarily Locking the Screen). It is working fine in the ISE but I can't use it from the PowerShell console shell.

I'm getting an error about not being able to find Windows.Window. I've added the following line:

[reflection.assembly]::loadwithpartialname("System.Windows") | Out-Null

and I've altered the "New-Object" function call to:

$window = New-Object System.Windows.Window

but I'm still getting the error:

New-Object : Cannot find type [System.Windows.Window]: make sure the assembly containing this type is loaded.

I've also tried inputting the commands directly into the PowerShell console shell but I get the same:

> [reflection.assembly]::loadwithpartialname("System.Windows"); $x = New-Object System.Windows.Window

GAC    Version        Location
True   v4.0.30319     C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows\v4.0_4.0.0.0__b03f5f7f11d50a3a\Syste...

New-Object : Cannot find type [System.Windows.Window]: make sure the assembly containing this type is loaded.

At line:1 char:68
+ [reflection.assembly]::loadwithpartialname("System.Windows"); $x = New-Object Sy ...
    + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand


Viewing all articles
Browse latest Browse all 8583

Trending Articles