PoshInternals icon indicating copy to clipboard operation
PoshInternals copied to clipboard

Close desktop

Open J-o-h-n- opened this issue 11 years ago • 1 comments

Hello, Running into a problem--but it could also just be my limited understanding of these functions. Anyway, I am trying to close (delete) the desktop after using 'New-Desktop' . I have tried numerous different things, but to no avail... Get-Desktop continues to list the created desktop. I even tried this (completely built off your work):

function Close-Desktop
{
    [CmdletBinding()]
    param(
        [Parameter(Mandatory, ValueFromPipeLine=$true, ParameterSetName="Desktop")]
        [PSObject]$Desktop,
        [Parameter(Mandatory, ValueFromPipeLine=$true, ParameterSetName="Name", Position=0)]
        [string]$Name
    )

    Process
    {
        if ($Desktop -eq $null)
        {
            $Desktop = Get-Desktop -Name $Name
        }

        if ($Desktop -eq $null)
        {
            Write-Error "Failed to find desktop"
            return
        }

        if (-not [PoshInternals.User32]::CloseDesktop($Desktop.Handle))
        {
            throw (New-Object System.ComponentModel.Win32Exception)
        }
    }
}

Any ideas on how to destroy the desktop?

J-o-h-n- avatar Jan 06 '14 20:01 J-o-h-n-

Same here, been trying all sorts of wacky stuff with the [PoshInternals.User32]::CloseDesktop() method with no luck, I'll look again and see if I can figure it out

mavericksevmont avatar Jul 17 '18 02:07 mavericksevmont