Question
Utilisation Windows form sans console ?
- schwartz
- Auteur du sujet
- Hors Ligne
- Nouveau membre
-
Réduire
Plus d'informations
- Messages : 1
- Remerciements reçus 0
il y a 11 ans 1 semaine #19249
par schwartz
Utilisation Windows form sans console ? a été créé par schwartz
Tout d'abord bonjour tout le monde,
je ne sais pas si il faut se présenter si oui je le ferais si section il y a, sinon voici mon souci, j'ai voulu en gros faire un programme qui ping une liste de serveur, mesurer qu'elle serveur à le moins de ping pour lancer 2 logiciels a la chaine pour un accès vpn avec les noms de config dans un CSV avec les serveurs, tout un truc quoi
, du coup j'ai voulu faire une gui pour soit se connecter, soit se déconnecter, cela marche ( enfin que sur pshell 3+ je sais pas pourquoi :/) mais par contre j'ai la console qui est la quand je lance mon script et sa m’embête si quelqu'un pourrait me conseiller.
soyez indulgent sur la qualité de mon script j'ai commencer il n'y à pas longtemps ^^'
merci a vous !
je ne sais pas si il faut se présenter si oui je le ferais si section il y a, sinon voici mon souci, j'ai voulu en gros faire un programme qui ping une liste de serveur, mesurer qu'elle serveur à le moins de ping pour lancer 2 logiciels a la chaine pour un accès vpn avec les noms de config dans un CSV avec les serveurs, tout un truc quoi
soyez indulgent sur la qualité de mon script j'ai commencer il n'y à pas longtemps ^^'
merci a vous !
La pièce jointe launcher.txt est absente ou indisponible
Pièces jointes :
Connexion ou Créer un compte pour participer à la conversation.
- Laurent Dardenne
- Hors Ligne
- Modérateur
-
Réduire
Plus d'informations
- Messages : 6311
- Remerciements reçus 68
il y a 11 ans 1 semaine #19250
par Laurent Dardenne
Tutoriels PowerShell
Réponse de Laurent Dardenne sur le sujet Re:Utilisation Windows form sans console ?
Salut,
il faut utiliser des API Windows :
[code:1]
################################################################################
#
# Name : C:\temp\Form1.ps1
# Version : 0.1
# Author :
# Date : 12/03/2015
#
# Generated with ConvertForm module version 1.1
# PowerShell version 4.0
#
# Invocation Line : Convert-Form -Path G:\PS\ConvertForm\TestsWinform\Base\Form1.Designer.cs -Destination c:\temp -HideConsole
# Source : G:\PS\ConvertForm\TestsWinform\Base\Form1.Designer.cs
################################################################################
function Get-ScriptDirectory
{ #Return the directory name of this script
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
$ScriptPath = Get-ScriptDirectory
# Possible value for the nCmdShow parameter
# SW_HIDE = 0;
# SW_SHOWNORMAL = 1;
# SW_NORMAL = 1;
# SW_SHOWMINIMIZED = 2;
# SW_SHOWMAXIMIZED = 3;
# SW_MAXIMIZE = 3;
# SW_SHOWNOACTIVATE = 4;
# SW_SHOW = 5;
# SW_MINIMIZE = 6;
# SW_SHOWMINNOACTIVE = 7;
# SW_SHOWNA = 8;
# SW_RESTORE = 9;
# SW_SHOWDEFAULT = 10;
# SW_MAX = 10
$signature = @'
[DllImport(\"user32.dll\"«»)]
public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
'@
Add-Type -MemberDefinition $signature -Name 'Win32ShowWindowAsync' -Namespace Win32Functions
function Show-Window {
param ([IntPtr] $WindowHandle)
#Displays in the foreground, the window with the handle $WindowHandle
#Write-warning ($WindowHandle -eq $null)
$SW_SHOWNORMAL = 5
$null=[Win32Functions.Win32ShowWindowAsync]::«»ShowWindowAsync($WindowHandle,$SW_SHOWNORMAL)
}
function Hide-Window([IntPtr] $WindowHandle) {
#Hide the window with the handle WindowHandle
#The application is no longer available in the taskbar and in the task manager.
$SW_HIDE = 0
$null=[Win32Functions.Win32ShowWindowAsync]::«»ShowWindowAsync($WindowHandle,$SW_HIDE)
}
# Chargement des assemblies externes
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$WindowHandle=(Get-Process -Id $pid).MainWindowHandle
$FrmBase = New-Object System.Windows.Forms.Form
#
# FrmBase
#
$FrmBase.ClientSize = New-Object System.Drawing.Size(284, 262)
$FrmBase.Name = \"FrmBase\"
$FrmBase.Text = \"Form1\"
function OnFormClosing_FrmBase{
# $this parameter is equal to the sender (object)
# $_ is equal to the parameter e (eventarg)
# The CloseReason property indicates a reason for the closure :
# if (($_).CloseReason -eq [System.Windows.Forms.CloseReason]::UserClosing)
#Sets the value indicating that the event should be canceled.
($_).Cancel= $False
}
$FrmBase.Add_FormClosing( { OnFormClosing_FrmBase} )
$FrmBase.Add_Shown({Hide-Window $WindowHandle;$FrmBase.Activate()})
$ModalResult=$FrmBase.ShowDialog()
Show-Window $WindowHandle
# Libération de la Form
$FrmBase.Dispose()
[/code:1]<br><br>Message édité par: Laurent Dardenne, à: 12/03/15 18:03
il faut utiliser des API Windows :
[code:1]
################################################################################
#
# Name : C:\temp\Form1.ps1
# Version : 0.1
# Author :
# Date : 12/03/2015
#
# Generated with ConvertForm module version 1.1
# PowerShell version 4.0
#
# Invocation Line : Convert-Form -Path G:\PS\ConvertForm\TestsWinform\Base\Form1.Designer.cs -Destination c:\temp -HideConsole
# Source : G:\PS\ConvertForm\TestsWinform\Base\Form1.Designer.cs
################################################################################
function Get-ScriptDirectory
{ #Return the directory name of this script
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
$ScriptPath = Get-ScriptDirectory
# Possible value for the nCmdShow parameter
# SW_HIDE = 0;
# SW_SHOWNORMAL = 1;
# SW_NORMAL = 1;
# SW_SHOWMINIMIZED = 2;
# SW_SHOWMAXIMIZED = 3;
# SW_MAXIMIZE = 3;
# SW_SHOWNOACTIVATE = 4;
# SW_SHOW = 5;
# SW_MINIMIZE = 6;
# SW_SHOWMINNOACTIVE = 7;
# SW_SHOWNA = 8;
# SW_RESTORE = 9;
# SW_SHOWDEFAULT = 10;
# SW_MAX = 10
$signature = @'
[DllImport(\"user32.dll\"«»)]
public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
'@
Add-Type -MemberDefinition $signature -Name 'Win32ShowWindowAsync' -Namespace Win32Functions
function Show-Window {
param ([IntPtr] $WindowHandle)
#Displays in the foreground, the window with the handle $WindowHandle
#Write-warning ($WindowHandle -eq $null)
$SW_SHOWNORMAL = 5
$null=[Win32Functions.Win32ShowWindowAsync]::«»ShowWindowAsync($WindowHandle,$SW_SHOWNORMAL)
}
function Hide-Window([IntPtr] $WindowHandle) {
#Hide the window with the handle WindowHandle
#The application is no longer available in the taskbar and in the task manager.
$SW_HIDE = 0
$null=[Win32Functions.Win32ShowWindowAsync]::«»ShowWindowAsync($WindowHandle,$SW_HIDE)
}
# Chargement des assemblies externes
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$WindowHandle=(Get-Process -Id $pid).MainWindowHandle
$FrmBase = New-Object System.Windows.Forms.Form
#
# FrmBase
#
$FrmBase.ClientSize = New-Object System.Drawing.Size(284, 262)
$FrmBase.Name = \"FrmBase\"
$FrmBase.Text = \"Form1\"
function OnFormClosing_FrmBase{
# $this parameter is equal to the sender (object)
# $_ is equal to the parameter e (eventarg)
# The CloseReason property indicates a reason for the closure :
# if (($_).CloseReason -eq [System.Windows.Forms.CloseReason]::UserClosing)
#Sets the value indicating that the event should be canceled.
($_).Cancel= $False
}
$FrmBase.Add_FormClosing( { OnFormClosing_FrmBase} )
$FrmBase.Add_Shown({Hide-Window $WindowHandle;$FrmBase.Activate()})
$ModalResult=$FrmBase.ShowDialog()
Show-Window $WindowHandle
# Libération de la Form
$FrmBase.Dispose()
[/code:1]<br><br>Message édité par: Laurent Dardenne, à: 12/03/15 18:03
Tutoriels PowerShell
Connexion ou Créer un compte pour participer à la conversation.
- Laurent Dardenne
- Hors Ligne
- Modérateur
-
Réduire
Plus d'informations
- Messages : 6311
- Remerciements reçus 68
il y a 11 ans 1 semaine #19251
par Laurent Dardenne
Tutoriels PowerShell
Réponse de Laurent Dardenne sur le sujet Re:Utilisation Windows form sans console ?
J'ai corrigé le bug dans le code de l'exemple et l'ai mis à jour.
Tutoriels PowerShell
Connexion ou Créer un compte pour participer à la conversation.
Temps de génération de la page : 0.042 secondes
- Vous êtes ici :
-
Accueil
-
forum
-
PowerShell
-
Entraide pour les débutants
- Utilisation Windows form sans console ?