Question [RESOLU]PowerShell Boutons radio

Plus d'informations
il y a 10 ans 10 mois #20365 par David
Bonjour,

Vous pourriez me dire ou je me suis planté svp ?
Je devrais avoir une fenêtre qui s'ouvre avec 3 boutons radio et ok et annuler en bas

Mais chez moi rien ne se lance du tout :

[code:1]# Introduction to Radio buttons and Grouping #
##############################################

# A function to create the form
function Ghost32{
[void] [System.Reflection.Assembly]::LoadWithPartialName(\"System.Windows.Forms\"«»)
[void] [System.Reflection.Assembly]::LoadWithPartialName(\"System.Drawing\"«»)

# Set the size of your form
$Form = New-Object System.Windows.Forms.Form
$Form.width = 500
$Form.height = 300
$Form.Text = ”Choix du ghost à descendre\"

# Set the font of the text to be used within the form
$Font = New-Object System.Drawing.Font(\"Times New Roman\",12)
$Form.Font = $Font

# Create a group that will contain your radio buttons
$MyGroupBox = New-Object System.Windows.Forms.GroupBox
$MyGroupBox.Location = \"40,30\"
$MyGroupBox.size = \"400,150\"
$MyGroupBox.text = \"Quelle image souhaitez vous descendre?\"

# Create the collection of radio buttons
$RadioButton1 = New-Object System.Windows.Forms.RadioButton
$RadioButton1.Location = '20,40'
$RadioButton1.size = \"350,20\"
$RadioButton1.Text = \"HP6005\"

$RadioButton2 = New-Object System.Windows.Forms.RadioButton
$RadioButton2.Location = \"20,70\"
$RadioButton2.size = \"350,20\"
$RadioButton2.Text = \"HP6305\"

$RadioButton3 = New-Object System.Windows.Forms.RadioButton
$RadioButton3.Location = \"20,100\"
$RadioButton3.size = \"350,20\"
$RadioButton3.Text = \"Quitter\"

# Add an OK button
$OKButton = new-object System.Windows.Forms.Button
$OKButton.Location = \"130,200\"
$OKButton.Size = \"100,40\"
$OKButton.Text = \"OK\"
$OKButton.DialogResult=[System.Windows.Forms.DialogResult]::OK

#Add a cancel button
$CancelButton = new-object System.Windows.Forms.Button
$CancelButton.Location = \"255,200\"
$CancelButton.Size = \"100,40\"
$CancelButton.Text = \"Cancel\"
$CancelButton.DialogResult=[System.Windows.Forms.DialogResult]::Cancel

# Add all the Form controls on one line
$form.Controls.AddRange(@($MyGroupBox,$OKButton,$CancelButton))

# Add all the GroupBox controls on one line
$MyGroupBox.Controls.AddRange(@($Radiobutton1,$RadioButton2,$RadioButton3))

# Activate the form
$form.Add_Shown({$form.Activate()})

# Get the results from the button click
$dialogResult = $form.ShowDialog()

# If the OK button is selected
if ($dialogResult -eq \"OK\"«»){

# Check the current state of each radio button and respond accordingly
if ($RadioButton1){
$Script:command = \"X:\Windows\System32\Cmd.exe /c start X:\Ghost32\ghost32.exe -clone, mode=restore, src=E:\Image\HP6005.gho, dst=1 /k\"}
elseif ($RadioButton2){
$Script:command = \"X:\Windows\System32\Cmd.exe /c start X:\Ghost32\ghost32.exe -clone, mode=restore, src=E:\Image\HP6305.gho, dst=1 /k\"}
elseif ($RadioButton3){$objGhost32.Close()}
}
}[/code:1]

Merci pour votre aide precieuse !!

Message édité par: goro, à: 4/07/15 00:39

Message édité par: goro, à: 4/07/15 00:41

Message édité par: goro, à: 4/07/15 00:43<br><br>Message édité par: goro, à: 4/07/15 22:59

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

Plus d'informations
il y a 10 ans 10 mois #20366 par David
Réponse de David sur le sujet Re:PowerShell Boutons radio
Alors je viens de trouver pourquoi ma form ne se lance pas :

J'ai oublie la fonction d'appel en fin de script :

[code:1]# Call the function
Ghost32[/code:1]

Ce qui nous donne après quelques modifications :

[code:1]# Introduction to Radio buttons and Grouping #
##############################################

# A function to create the form
function Ghost32{
[void] [System.Reflection.Assembly]::LoadWithPartialName(\&quot;System.Windows.Forms\&quot;«»)
[void] [System.Reflection.Assembly]::LoadWithPartialName(\&quot;System.Drawing\&quot;«»)

# Set the size of your form
$Form = New-Object System.Windows.Forms.Form
$Form.width = 500
$Form.height = 300
$Form.Text = ”Choix du ghost à descendre\&quot;

# Set the font of the text to be used within the form
$Font = New-Object System.Drawing.Font(\&quot;Times New Roman\&quot;,12)
$Form.Font = $Font

# Create a group that will contain your radio buttons
$MyGroupBox = New-Object System.Windows.Forms.GroupBox
$MyGroupBox.Location = \&quot;40,30\&quot;
$MyGroupBox.size = \&quot;400,150\&quot;
$MyGroupBox.text = \&quot;Quelle image souhaitez vous descendre?\&quot;

# Create the collection of radio buttons
$RadioButton1 = New-Object System.Windows.Forms.RadioButton
$RadioButton1.Location = '20,40'
$RadioButton1.size = \&quot;350,20\&quot;
$radiobutton1.Checked = $true
$RadioButton1.Text = \&quot;HP 6005\&quot;

$RadioButton2 = New-Object System.Windows.Forms.RadioButton
$RadioButton2.Location = \&quot;20,70\&quot;
$RadioButton2.size = \&quot;350,20\&quot;
$radiobutton1.Checked = $false
$RadioButton2.Text = \&quot;HP 6305\&quot;

# Add an OK button
$OKButton = new-object System.Windows.Forms.Button
$OKButton.Location = \&quot;130,200\&quot;
$OKButton.Size = \&quot;100,40\&quot;
$OKButton.Text = \&quot;OK\&quot;
$OKButton.DialogResult=[System.Windows.Forms.DialogResult]::OK

#Add a cancel button
$CancelButton = new-object System.Windows.Forms.Button
$CancelButton.Location = \&quot;255,200\&quot;
$CancelButton.Size = \&quot;100,40\&quot;
$CancelButton.Text = \&quot;Cancel\&quot;
$CancelButton.DialogResult=[System.Windows.Forms.DialogResult]::Cancel

# Add all the Form controls on one line
$form.Controls.AddRange(@($MyGroupBox,$OKButton,$CancelButton))

# Add all the GroupBox controls on one line
$MyGroupBox.Controls.AddRange(@($Radiobutton1,$RadioButton2))

# Activate the form
$form.Add_Shown({$form.Activate()})

# Get the results from the button click
$dialogResult = $form.ShowDialog()

# If the OK button is selected
if ($dialogResult -eq \&quot;OK\&quot;«»){

# Check the current state of each radio button and respond accordingly
if ($RadioButton1){
$Script:command = \&quot;C:\Windows\System32\cmd.exe /C start E:\WinPE-Plugin\Apps\x86\Ghost32\ghost32.exe /clone /mode=restore /src=E:\WinPE-Plugin\Images\HP6005sevensp1.gho /dst=1\&quot;}
elseif ($RadioButton2){
$Script:command = \&quot;E:\WinPE-Plugin\Apps\x86\Ghost32\ghost32.exe -clone, -mode=restore, -src=E:\WinPE-Plugin\Images\HP6005seven sp1.gho, -dst=1\&quot;}
}
}
# Call the function
Ghost32[/code:1]

Maintenant je bute sur les actions des radiobuttons, il ne lancent pas ma cmd :s

Vous avez une idée ? Je continue à chercher de mon côté !

Merci d'avance

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

Plus d'informations
il y a 10 ans 10 mois #20367 par xyz
Réponse de xyz sur le sujet Re:PowerShell Boutons radio
Salut,
essaie avec l'opérateur &amp;
[code:1]&amp;\&quot;cmd /param...\&quot;[/code:1]

Tutoriels PowerShell

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

Plus d'informations
il y a 10 ans 10 mois #20368 par David
Réponse de David sur le sujet [RESOLU] PowerShell Boutons radio
C'est bien ce que j'ai fini par trouver après quelques heures de recherches et de tests :)

Merci en tout cas :)

Voici le code qui fonctionne si ca peut servir :

[code:1]# La fonction pour créer la form
function Ghost32{
[void] [System.Reflection.Assembly]::LoadWithPartialName(\&quot;System.Windows.Forms\&quot;«»)
[void] [System.Reflection.Assembly]::LoadWithPartialName(\&quot;System.Drawing\&quot;«»)

# Régler la taille de la form
$Form = New-Object System.Windows.Forms.Form
$Form.width = 500
$Form.height = 300
$Form.Text = ”Choix du ghost à descendre\&quot;

# Set the font of the text to be used within the form
$Font = New-Object System.Drawing.Font(\&quot;Times New Roman\&quot;,12)
$Form.Font = $Font

# Create a group that will contain your radio buttons
$MyGroupBox = New-Object System.Windows.Forms.GroupBox
$MyGroupBox.Location = \&quot;40,30\&quot;
$MyGroupBox.size = \&quot;400,150\&quot;
$MyGroupBox.text = \&quot;Quelle image souhaitez vous descendre?\&quot;

# Création de la collection de boutons radio
$RadioButton1 = New-Object System.Windows.Forms.RadioButton
$RadioButton1.Location = '20,40'
$RadioButton1.size = \&quot;350,20\&quot;
$radiobutton1.Checked = $true
$RadioButton1.Text = \&quot;HP 6005\&quot;

$RadioButton2 = New-Object System.Windows.Forms.RadioButton
$RadioButton2.Location = \&quot;20,70\&quot;
$RadioButton2.size = \&quot;350,20\&quot;
$radiobutton1.Checked = $false
$RadioButton2.Text = \&quot;HP 6305\&quot;

# Ajouter le bouton OK
$OKButton = new-object System.Windows.Forms.Button
$OKButton.Location = \&quot;130,200\&quot;
$OKButton.Size = \&quot;100,40\&quot;
$OKButton.Text = \&quot;OK\&quot;
$OKButton.DialogResult=[System.Windows.Forms.DialogResult]::OK

#Ajouter le bouton annuler
$CancelButton = new-object System.Windows.Forms.Button
$CancelButton.Location = \&quot;255,200\&quot;
$CancelButton.Size = \&quot;100,40\&quot;
$CancelButton.Text = \&quot;Annuler\&quot;
$CancelButton.DialogResult=[System.Windows.Forms.DialogResult]::Cancel

# Add all the Form controls on one line
$form.Controls.AddRange(@($MyGroupBox,$OKButton,$CancelButton))

# Add all the GroupBox controls on one line
$MyGroupBox.Controls.AddRange(@($Radiobutton1,$RadioButton2))

# Activation de la form
$form.Add_Shown({$form.Activate()})

# Get the results from the bouton click
$dialogResult = $form.ShowDialog()

# Si le bouton OK est choisi
if ($dialogResult -eq \&quot;OK\&quot;«»){

# Verifier l'état de chaque bouton radio et agir en fonction
if ($RadioButton1){
$command = cmd.exe /C \&quot;E:\WinPE-Plugin\Apps\x86\Ghost32\ghost32.exe /clone,src=E:\WinPE-Plugin\Images\HP6005sevensp1.gho,mode=restore,dst=1\&quot;}
elseif ($RadioButton2){
$command = cmd.exe /C \&quot;E:\WinPE-Plugin\Apps\x86\Ghost32\ghost32.exe /clone,src=E:\WinPE-Plugin\Images\HP6305sevensp1.gho,mode=restore,dst=1\&quot;}
}
}

# Appel de la fonction
Ghost32[/code:1]

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

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