kernel32/GetNamedPipeClientComputerName.ps1
function GetNamedPipeClientComputerName { <# .SYNOPSIS Retrieves the client computer name for the specified named pipe. .PARAMETER PipeHandle A handle to an instance of a named pipe. This handle must be created by the CreateNamedPipe function. .NOTES Author: Jared Atkinson (@jaredcatkinson) License: BSD 3-Clause Required Dependencies: PSReflect Optional Dependencies: None (func kernel32 GetNamedPipeClientComputerName ([Bool]) @( [IntPtr], #_In_ HANDLE Pipe, [byte[]], #_Out_ LPTSTR ClientComputerName, [UInt32] #_In_ ULONG ClientComputerNameLength ) -EntryPoint GetNamedPipeClientComputerName -SetLastError) .EXAMPLES #> param ( [Parameter(Mandatory = $true)] [IntPtr] $PipeHandle ) $buf = New-Object byte[](1024) $SUCCESS = $kernel32::GetNamedPipeClientComputerName($PipeHandle, $buf, $buf.Length); $LastError = [Runtime.InteropServices.Marshal]::GetLastWin32Error() if(-not $SUCCESS) { throw "[GetNamedPipeClientComputerName] Error: $(([ComponentModel.Win32Exception] $LastError).Message)" } Write-Output ([System.Text.Encoding]::Unicode.GetString($buf)) } |