The result should be a list with all process names, PIDs and amount of used
GDI objects.
I played with the following:
PS H:\> (Get-WmiObject -Class Win32_OperatingSystem -ComputerName
.).InvokeMethod("GetGuiResources",0)
Method invocation failed because
[System.Management.ManagementObject#root\cimv2\Win32_OperatingSystem] doesn't
contain a method named 'InvokeMethod'.
At line:1 char:74
+ (Get-WmiObject -Class Win32_OperatingSystem -ComputerName .).InvokeMethod(
<<<< "GetGuiResources",0)
But with no success as you can see.
If this is not possible with Powershell, every way to get this information
using a Windows native way is fine. It needs to be automated without any user
interaction and I would like to avoid to write and compile some code for
this, that's all.
thanks
Yes - there is no such method (GetGuiResources) on that class!
GetGuiResources is an unmanaged API and I'm not skilled enough (yet) to
know how to call this API natively - you need to use p/invoke.
>If this is not possible with Powershell, every way to get this information
>using a Windows native way is fine. It needs to be automated without any user
>interaction and I would like to avoid to write and compile some code for
>this, that's all.
You can use P/Invoke - but i can;t give you a good sample.
Thomas
--
Thomas Lee
doct...@gmail.com
I think I can live with this, but if anybody knows a more simple way to get
the GDI handles from PowerShell, please post it.
"Thomas Lee" wrote:
> .....
>
> You can use P/Invoke - but i can;t give you a good sample.
>
> Thomas
>
> --
> Thomas Lee
> doct...@gmail.com
> .
>
Strictly speaking that's running C/C++ and unmanaged code.
PowerShell is built on top of .NET and calling into the .NET framework
is trivial in most cases. In effect, your PowerShell script is a bit of
managed code.
What you are asking is how to get into the unmanaged Win32 APIs. From
any bit of managed code (whether it's an actual C# program or a
PowerShell script, you have to use P/Invoke to get to that API. Its ugly
and is to be avoided if/where possible. This may be a case where you are
forced to use it.
>I think I can live with this, but if anybody knows a more simple way to get
>the GDI handles from PowerShell, please post it.
I will ask around, but I am not aware of any managed API you can call to
get this info.
Sorry I don't have a better answer.
$sig = @'
[DllImport("User32.dll")]
public static extern int GetGuiResources(IntPtr hProcess, int uiFlags);
'@
Add-Type -MemberDefinition $sig -name NativeMethods -namespace Win32
$handle = @(Get-Process -id $pid)[0].Handle
$numGuiHandles = [Win32.NativeMethods]::GetGuiResources($handle, 0)
"Number of GUI handles $numGuiHandles"
--
Keith
"Dirk Abhau" <Dirk...@discussions.microsoft.com> wrote in message
news:9EC579F5-288F-41A8...@microsoft.com...