PowerShell z API Windows

28 March 2015
http://blogs.technet.com/b/heyscriptingguy/archive/2013/06/25/use-powershell-to-interact-with-the-windows-api-part-1.aspx

$MethodDefinition = @'

 

[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]

 

public static extern bool CopyFile(string lpExistingFileName, string lpNewFileName, bool bFailIfExists);

 

'@

 

$Kernel32 = Add-Type -MemberDefinition $MethodDefinition -Name 'Kernel32' -Namespace 'Win32' -PassThru

 

# You may now call the CopyFile function

 

# Copy calc.exe to the user's desktop

 

$Kernel32::CopyFile("$($Env:SystemRoot)\System32\calc.exe", "$($Env:USERPROFILE)\Desktop\calc.exe", $False)


Kategorie: Power Shell