PowerShell中调用Win32API
2008-06-03 22:02
239 查看
调用Win32 API, 取得网络文件夹的剩余空间. 用户无需挂载磁盘即可取得结果
$a = Add-Type -memberDefinition @"
[DllImport("Kernel32.dll")]
public static extern bool GetDiskFreeSpaceEx(
string lpDirectoryName,
out long lpFreeBytesAvailable,
out long lpTotalNumberOfBytes,
out long lpTotalNumberOfFreeBytes
);
"@ -passthru -name MyGetDiskFreeSpaceEx
$fba = [int64] 0;
$tnb = [int64] 0;
$nfb = [int64] 0;
$a::GetDiskFreeSpaceEx("//.host/Shared Folders/files", [ref] $fba, [ref] $tnb, [ref] $nfb)
"FreeBytesAvailable: $($x)"
"TotalNumberOfBytes: $($y)"
"TotalNumberOfFreeBytes: $($z)"
------------OLD------------
$a = Add-Type -memberDefinition @"
[DllImport("Kernel32.dll")]
public static extern bool GetDiskFreeSpaceEx(
string lpDirectoryName,
IntPtr lpFreeBytesAvailable,
IntPtr lpTotalNumberOfBytes,
IntPtr lpTotalNumberOfFreeBytes
);
"@ -passthru -name MyGetDiskFreeSpaceEx
$fba = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(20);
$tnb = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(20);
$nfb = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(20);
$a::GetDiskFreeSpaceEx("//.host/Shared Folders/files", $fba, $tnb, $nfb)
$x = [System.Runtime.InteropServices.Marshal]::ReadInt64($fba)
$y = [System.Runtime.InteropServices.Marshal]::ReadInt64($tnb)
$z = [System.Runtime.InteropServices.Marshal]::ReadInt64($nfb)
"FreeBytesAvailable: $($x)"
"TotalNumberOfBytes: $($y)"
"TotalNumberOfFreeBytes: $($z)"
[System.Runtime.InteropServices.Marshal]::FreeHGlobal($fba);
[System.Runtime.InteropServices.Marshal]::FreeHGlobal($tnb);
[System.Runtime.InteropServices.Marshal]::FreeHGlobal($nfb);
$a = Add-Type -memberDefinition @"
[DllImport("Kernel32.dll")]
public static extern bool GetDiskFreeSpaceEx(
string lpDirectoryName,
out long lpFreeBytesAvailable,
out long lpTotalNumberOfBytes,
out long lpTotalNumberOfFreeBytes
);
"@ -passthru -name MyGetDiskFreeSpaceEx
$fba = [int64] 0;
$tnb = [int64] 0;
$nfb = [int64] 0;
$a::GetDiskFreeSpaceEx("//.host/Shared Folders/files", [ref] $fba, [ref] $tnb, [ref] $nfb)
"FreeBytesAvailable: $($x)"
"TotalNumberOfBytes: $($y)"
"TotalNumberOfFreeBytes: $($z)"
------------OLD------------
$a = Add-Type -memberDefinition @"
[DllImport("Kernel32.dll")]
public static extern bool GetDiskFreeSpaceEx(
string lpDirectoryName,
IntPtr lpFreeBytesAvailable,
IntPtr lpTotalNumberOfBytes,
IntPtr lpTotalNumberOfFreeBytes
);
"@ -passthru -name MyGetDiskFreeSpaceEx
$fba = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(20);
$tnb = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(20);
$nfb = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(20);
$a::GetDiskFreeSpaceEx("//.host/Shared Folders/files", $fba, $tnb, $nfb)
$x = [System.Runtime.InteropServices.Marshal]::ReadInt64($fba)
$y = [System.Runtime.InteropServices.Marshal]::ReadInt64($tnb)
$z = [System.Runtime.InteropServices.Marshal]::ReadInt64($nfb)
"FreeBytesAvailable: $($x)"
"TotalNumberOfBytes: $($y)"
"TotalNumberOfFreeBytes: $($z)"
[System.Runtime.InteropServices.Marshal]::FreeHGlobal($fba);
[System.Runtime.InteropServices.Marshal]::FreeHGlobal($tnb);
[System.Runtime.InteropServices.Marshal]::FreeHGlobal($nfb);
相关文章推荐
- 快速找出System.Management.Automation.dll,c#调用powershell
- 在Powershell中调用VBScript
- PowerShell调用SharePoint web service遍历/修改List(列表)数据
- C#通过代码调用PowerShell
- Win32API调用错误号与信息(1-999)
- Win32API调用错误号与信息(8000-8999)
- C# 调用PowerShell方法
- 常用Win32Api调用............
- win32api调用打开/保存文件对话框
- win32控制台中调用win32api和控件资源
- C#调用WIN32API系列一列举可用COM端口
- 天灵灵,地灵灵,但愿这个一定灵!!!python调用win32api,启动应用程序窗口
- C#可以直接调用的Win32API
- java 调用 powershell 遇到的 reader.readLine() 卡住问题
- Win32API调用错误号与信息(2000-2999)
- Silverlight5 RC调用Win32API
- C# 调用PowerShell方法
- 用C# 调用PowerShell 3.0
- PowerShell笔记(三):调用MS SQL数据库
- qt下调用win32api 修改分辨率