Bonjour,
Je sais pas si l'intitulé est clair mais bon, je me lance.
Je suis actuellement sur un petit développement qui permettra d'installer une imprimante depuis une liste d'imprimantes situé dans un fichier .csv listés dans une combobox.
Et le soucis que je rencontre est que une fois le choix effectué dans la combobox, je n'arrive pas à le transcrire sur l'action "Installer l'imprimante" avec le nom choisi.
Dans le code il y a tout le blabla de générations de formes crées par "Primal Form CE".
Vu que j'ai testé à peu prés tout ($combobox.selected etc...) donc j'ai tout enlevé et gardé que l'essentielle.
Please Help
Voici le code :
Code powershell : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94 #Generated Form Function function GenerateForm { #region Import the Assemblies [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null #endregion #region Generated Form Objects $form1 = New-Object System.Windows.Forms.Form $button1 = New-Object System.Windows.Forms.Button $comboBox1 = New-Object System.Windows.Forms.ComboBox $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState #endregion Generated Form Objects #---------------------------------------------- #Generated Event Script Blocks #---------------------------------------------- #Provide Custom Code for events specified in PrimalForms. $button1_OnClick= { (New-Object -ComObject WScript.Network).AddWindowsPrinterConnection("\\ServerName\$printtoinstall") [System.Windows.Forms.MessageBox]::Show("$printtoinstall",'Résultat','OK','64') } $OnLoadForm_StateCorrection= {#Correct the initial state of the form to prevent the .Net maximized form issue $form1.WindowState = $InitialFormWindowState } #---------------------------------------------- #region Generated Form Code $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 262 $System_Drawing_Size.Width = 284 $form1.ClientSize = $System_Drawing_Size $form1.DataBindings.DefaultDataSourceUpdateMode = 0 $form1.Name = "form1" $form1.Text = "Primal Form" $button1.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 146 $System_Drawing_Point.Y = 189 $button1.Location = $System_Drawing_Point $button1.Name = "button1" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 23 $System_Drawing_Size.Width = 75 $button1.Size = $System_Drawing_Size $button1.TabIndex = 1 $button1.Text = "button1" $button1.UseVisualStyleBackColor = $True $button1.add_Click($button1_OnClick) $form1.Controls.Add($button1) $comboBox1.DataBindings.DefaultDataSourceUpdateMode = 0 $comboBox1.FormattingEnabled = $True $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 46 $System_Drawing_Point.Y = 46 $comboBox1.Location = $System_Drawing_Point $printlist = Import-Csv .\test.csv -Delimiter ";" | Select-Object -ExpandProperty Name foreach ($printer in $printlist) { $comboBox1.Items.Add($printer) } $comboBox1.Name = "comboBox1" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 21 $System_Drawing_Size.Width = 121 $comboBox1.Size = $System_Drawing_Size $comboBox1.TabIndex = 0 $form1.Controls.Add($comboBox1) #endregion Generated Form Code #Save the initial state of the form $InitialFormWindowState = $form1.WindowState #Init the OnLoad event to correct the initial state of the form $form1.add_Load($OnLoadForm_StateCorrection) #Show the Form $form1.ShowDialog()| Out-Null } #End Function #Call the Function GenerateForm
Partager