header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Using P/Invoke
Last Post 16 Jan 2008 08:08 PM by EBGreen. 2 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
EBGreenUser is Online
New Member
New Member
Posts:64
Avatar

--
16 Jan 2008 07:36 PM  

I am trying to understand the use of P/Invoke so that I can use the Window's APIs when I must. As an example, I am trying to get the free space on C: using GetDiskFreeSpaceEx from Kernel32.dll. Here is what I do:

 

$free = [IntPtr]::Zero

$total = [IntPtr]::Zero

$totalfree = [IntPtr]::Zero

Invoke-Win32 "kernel32.dll" ([System.Boolean]) "GetDiskFreeSpaceEx" ([string], [Ref], [Ref], [Ref], [Ref]) ("C:\", (
[ref]$free), ([ref]$total), ([ref]$totalfree))

 

Then I look at the value of $free

 

$free
72224768

 

Which has no bearing on the 24GB that I have free on C:. I understand that $free is a pointer, but I can not for the life of me find a way to dereference it and get to the data stored in memory. Can anyone help me figure this out. The Invoke-Win32 function that I use is a fairly common function that is floating around on the web but I can post the code for it if that would help.

marco.shawUser is Offline
Co-Community Director
Basic Member
Basic Member
Posts:195
Avatar

--
16 Jan 2008 07:59 PM  
And invoke-win32 comes from Lee Holmes?
http://www.leeholmes.com/blog/GetTheOwnerOfAProcessInPowerShellPInvokeAndRefOutParameters.aspx
Marco

*Microsoft MVP - Windows PowerShell: http://www.microsoft.com/mvp
*PowerGadgets MVP: http://www.powergadgets.com/mvp
*Blog: http://marcoshaw.blogspot.com
EBGreenUser is Online
New Member
New Member
Posts:64
Avatar

--
16 Jan 2008 08:08 PM  
That would be correct.
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer