Question Cacher exécution fenêtre scripts

Plus d'informations
il y a 1 an 2 mois #32918 par rhiwotar
Bonjour !!

Petite question pas exactement  powershell mais vous connaissaient peut-être la réponse.

J'ai des scripts qui s'éxecute à l'ouverture de sessions (par GPO) ou via des taches planifiées et je voudrais masquer les fenêtres qui apparaissent.
Pour l'ouverture de session, j'ai rien trouvé et pour les taches planifiées, j'ai beau mettre "-windowstyle hidden" en argument, ça veut rien savoir.

Merci d'avance!

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 1 an 2 mois #32919 par ericlm128
Hi,

Pour le planificateur de tâche tu peux tenter l'option "Masquer".

De façon plus général tu dois passer par un autre programme ou script qui n'est pas un programme en mode console et qui te permettra de masquer une exécution.

Tantôt j'utilisais un exe compilé en Autotit. Assez simple à faire avec la commande RunWait
Ou un script vbs : winaero.com/run-a-program-hidden-in-windows-10/
Ou un programme tiers comme cmdow (souvent détecté comme un malware ) : ritchielawrence.github.io/cmdow/
Voir aussi NirCmd sur le fameux site de NirSoft www.nirsoft.net/utils/nircmd.html

Je te conseil tout de même le vbs plus simple et lisible (script)


Sinon il m'arrive aussi de ne pas souhaiter le masquer complètement, je fait donc une auto-réduction (minimiser) dans le script PowerShell. Peut être que cela pourrait suffire même si il y a un pop d'une fenêtre.
#region MINIMIZE me
function Set-WindowState {
param(
    [Parameter()]
    [ValidateSet('FORCEMINIMIZE', 'HIDE', 'MAXIMIZE', 'MINIMIZE', 'RESTORE',
                 'SHOW', 'SHOWDEFAULT', 'SHOWMAXIMIZED', 'SHOWMINIMIZED',
                 'SHOWMINNOACTIVE', 'SHOWNA', 'SHOWNOACTIVATE', 'SHOWNORMAL')]
    [Alias('Style')]
    [String] $State = 'SHOW',
    
    [Parameter(ValueFromPipelineByPropertyname='True')]
    [System.IntPtr] $MainWindowHandle = (Get-Process –id $pid).MainWindowHandle,

    [Parameter()]
    [switch] $PassThru

)
BEGIN
{

$WindowStates = @{
    'FORCEMINIMIZE'   = 11
    'HIDE'            = 0
    'MAXIMIZE'        = 3
    'MINIMIZE'        = 6
    'RESTORE'         = 9
    'SHOW'            = 5
    'SHOWDEFAULT'     = 10
    'SHOWMAXIMIZED'   = 3
    'SHOWMINIMIZED'   = 2
    'SHOWMINNOACTIVE' = 7
    'SHOWNA'          = 8
    'SHOWNOACTIVATE'  = 4
    'SHOWNORMAL'      = 1
}
    
$Win32ShowWindowAsync = Add-Type –memberDefinition @"
[DllImport("user32.dll")]
public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
"@ -Name "Win32ShowWindowAsync" -Namespace Win32Functions -PassThru

}
PROCESS
{
    $Win32ShowWindowAsync::ShowWindowAsync($MainWindowHandle, $WindowStates[$State]) | Out-Null
    Write-Verbose ("Set Window State on '{0}' to '{1}' " -f $MainWindowHandle, $State)

    if ($PassThru)
    {
        Write-Output $MainWindowHandle
    }
}
END
{
}
}

try
{
    Get-Process -ID $PID | Set-WindowState -State MINIMIZE
} catch {}
#endregion
 

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 1 an 2 mois - il y a 1 an 2 mois #32923 par rhiwotar
Réponse de rhiwotar sur le sujet Cacher exécution fenêtre scripts
Salut,

D'accord merci, je pensais à un truc plus intégré

Je vais tenter un script d'appel avec juste un
start-process monscript.ps1 -windowsstyle -hidden

voir si c'est déjà plus discret
Dernière édition: il y a 1 an 2 mois par rhiwotar.

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.072 secondes
Propulsé par Kunena