在powershell和.net中,使用windows7 api
本篇是翻譯整理 powershell指令碼小子部落格中的內容。原文地址:
http://blogs.technet.com/b/heyscriptingguy/archive/2012/11/11/weekend-scripter-working-with-windows-libraries.aspx
windows api 是win作業系統提供的介面。
以win7庫檔案夾為例,我們使用win api中提供的對象方法等,就可以操作win7的庫。
它比。net更底層,速度更快,使用的是c語言文法。
而【Windows 7 API Code Pack for Microsoft? .NET Framework】可以看作是。net的擴充。或者說是橋樑。
讓我們在。net中,用。net對象,方法屬性的方式,使用win api。(而不是c文法)
目前的版本是1.1,大小為24MB,官網是:
http://archive.msdn.microsoft.com/WindowsAPICodePack
我們知道,powershell是很方便調用。net功能的,而有了這個橋樑,powershell調用win api 也簡單直觀起來了。
下面我們來看看,它帶來了什麼功能:
Windows 7 Taskbar
Jump Lists, Icon Overlay, Progress Bar, Tabbed Thumbnails, and Thumbnail Toolbars
Windows Shell
Windows 7 Libraries
Windows Shell Search API support
Explorer Browser Control
A hierarchy of Shell Namespace entities
Windows Shell property system
Drag and Drop for Shell Objects
Windows Vista and Windows 7 Common File Dialogs, including custom controls
Known Folders and non-file system containers
Shell Object Watcher
Shell Extensions API support
DirectX
Direct3D 11.0, Direct3D 10.1/10.0, DXGI 1.0/1.1, Direct2D 1.0, DirectWrite, Windows Imaging Component (WIC) APIs
Windows Vista and Windows 7 Task Dialogs
Sensor Platform APIs
Extended Linguistic Services APIs
Power Management APIs
Application Restart and Recovery APIs
Network List Manager APIs
Command Link control and System defined Shell icons
--------------------------------------------------------
例子:
# Create a PowerShell Library and include corresponding folders
Add-type -path Microsoft.WindowsAPICodePack.Shell.dll
$ps = New-Object Microsoft.WindowsAPICodePack.Shell.ShellLibrary –Argument "PowerShell",$true
$ps.Add("$($env:userprofile)\Skydrive\PowerShell")
$ps.Add("$($env:userprofile)\SkydrivePro\PowerShell")
$ps.Close()
這個例子其實並不是很好,修改庫檔案夾,更換壁紙等功能,推薦通過
修改註冊表的方法來實現。
不過,很多顯示時的動態效果,只能用api實現。這種是沒法用註冊表的。
-------------------------------------------------------