[seems solved] Return value of a function

Hello everybody,

At starting of a Windows session, I have a few windows that are opened when launching programs, and the user has to close them before doing anything else.

It would be nice to close them automatically.

Let us take the example of PowerShell.

closeWin "Windows PowerShell" "exit~"

function closeWin()
{
    param
    (
        [string]$arg1,
        [string]$keys
    )
    $wshell = New-Object -ComObject wscript.shell;
    $wshell.AppActivate([string]$arg1);
    Start-Sleep 1;
    $wshell.SendKeys([string]$keys);
}


Well, it closes the window, and then displays False.

Instead of displaying True, I should like the script to display “Window not found”, I think it would be more explicit.

Well, is it AppActivate, that returns a value?

Oh, it seems so.

    $t = $wshell.AppActivate([string]$arg1);
    if($t)
    {
        "$arg1 : window not found";
    }
    else
    {
        "$arg1 : window closed";
    }

and strangely, it worked only after I launched it three times.
So, the return value is the answer to the question “does this raise an error ?”
If I search AppActivate on Internet, I have the forums questions before the documentation.

Oh, in PowerShell I typed update-help, maybe next time I get something more useful.

Maybe.

Au caractère Ligne:1 : 1
+ update-help
+ ~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [Update-Help], Exceptio 
   n
    + FullyQualifiedErrorId : UnableToRetrieveHelpInfoXml,Microsoft.PowerShell 
   .Commands.UpdateHelpCommand