Top-Themen

AppleEntwicklungHardwareInternetLinuxMicrosoftMultimediaNetzwerkeOff TopicSicherheitSonstige SystemeVirtualisierungWeiterbildungZusammenarbeit

Aktuelle Themen

Administrator.de FeedbackApache ServerAppleAssemblerAudioAusbildungAuslandBackupBasicBatch & ShellBenchmarksBibliotheken & ToolkitsBlogsCloud-DiensteClusterCMSCPU, RAM, MainboardsCSSC und C++DatenbankenDatenschutzDebianDigitiales FernsehenDNSDrucker und ScannerDSL, VDSLE-BooksE-BusinessE-MailEntwicklungErkennung und -AbwehrExchange ServerFestplatten, SSD, RaidFirewallFlatratesGoogle AndroidGrafikGrafikkarten & MonitoreGroupwareHardwareHosting & HousingHTMLHumor (lol)Hyper-VIconsIDE & EditorenInformationsdiensteInstallationInstant MessagingInternetInternet DomäneniOSISDN & AnaloganschlüsseiTunesJavaJavaScriptKiXtartKVMLAN, WAN, WirelessLinuxLinux DesktopLinux NetzwerkLinux ToolsLinux UserverwaltungLizenzierungMac OS XMicrosoftMicrosoft OfficeMikroTik RouterOSMonitoringMultimediaMultimedia & ZubehörNetzwerkeNetzwerkgrundlagenNetzwerkmanagementNetzwerkprotokolleNotebook & ZubehörNovell NetwareOff TopicOpenOffice, LibreOfficeOutlook & MailPapierkorbPascal und DelphiPeripheriegerätePerlPHPPythonRechtliche FragenRedHat, CentOS, FedoraRouter & RoutingSambaSAN, NAS, DASSchriftartenSchulung & TrainingSEOServerServer-HardwareSicherheitSicherheits-ToolsSicherheitsgrundlagenSolarisSonstige SystemeSoziale NetzwerkeSpeicherkartenStudentenjobs & PraktikumSuche ProjektpartnerSuseSwitche und HubsTipps & TricksTK-Netze & GeräteUbuntuUMTS, EDGE & GPRSUtilitiesVB for ApplicationsVerschlüsselung & ZertifikateVideo & StreamingViren und TrojanerVirtualisierungVisual StudioVmwareVoice over IPWebbrowserWebentwicklungWeiterbildungWindows 7Windows 8Windows 10Windows InstallationWindows MobileWindows NetzwerkWindows ServerWindows SystemdateienWindows ToolsWindows UpdateWindows UserverwaltungWindows VistaWindows XPXenserverXMLZusammenarbeit
GELÖST

GUI in Powershell für diesen Code

Frage Entwicklung Batch & Shell

Mitglied: pixel0815

pixel0815 (Level 1) - Jetzt verbinden

08.04.2014, aktualisiert 12:56 Uhr, 1798 Aufrufe, 3 Kommentare

Hallo liebes Forum,

ist es möglich für diesen Code eine einfache Gui zu entwerfen?
Es sollen Edit Felder ein die man befüllen kann, einzig für drivername sollen die Treiber aus dem System ausgelesen werden.

01.
function CreatePrinter { 
02.
$server = $args[0] 
03.
$print = ([WMICLASS]“\\.\ROOT\cimv2:Win32_Printer”).createInstance() 
04.
$print.drivername = $args[1] 
05.
$print.PortName = $args[2] 
06.
$print.Shared = $true 
07.
$print.Published = $true 
08.
$print.Sharename = $args[3] 
09.
$print.Location = $args[4] 
10.
$print.Comment = $args[5] 
11.
$print.DeviceID = $args[6] 
12.
$print.Put() 
13.
14.
 
15.
function CreatePrinterPort { 
16.
$server = $args[0] 
17.
$port = ([WMICLASS]“\\.\ROOT\cimv2:Win32_TCPIPPrinterPort”).createInstance() 
18.
$port.Name= $args[1] 
19.
$port.SNMPEnabled=$false 
20.
$port.Protocol=1 
21.
$port.HostAddress= $args[2] 
22.
$port.Put() 
23.
24.
 
25.
$printers = Import-Csv “Drucker.csv” 
26.
 
27.
foreach ($printer in $printers) { 
28.
CreatePrinterPort $printer.Printserver $printer.Portname $printer.IPAddress 
29.
CreatePrinter $printer.Printserver $printer.Driver $printer.Portname $printer.Sharename $printer.Location $printer.Comment $printer.Printername 
30.
}
Hat da jemand was parat?

Gruß
Heiko
Mitglied: colinardo
08.04.2014, aktualisiert um 13:59 Uhr
Hallo Heiko,
Zitat von pixel0815:
Hat da jemand was parat?
parat nicht, aber schnell was zusammen gezimmert. Das ganze sähe dann so aus:

2330e637a760aa7d843affb2665f668e - Klicke auf das Bild, um es zu vergrößern

(Deinen Code kannst du ja selber im Button-Click-Event hinterlegen und an die Felder koppeln, im Moment werden nur die Werte der Felder in einer MessagBox angezeigt - ein bißchen Arbeit habe ich dir also noch gelassen )

Zur Info: Einen kostenlosen GUI-Builder bekommst du hier: Primal Forms Community Edition
01.
#Generated Form Function 
02.
function GenerateForm { 
03.
 
04.
#region Import the Assemblies 
05.
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null 
06.
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null 
07.
#endregion 
08.
 
09.
$formMain = New-Object System.Windows.Forms.Form 
10.
$btnCreate = New-Object System.Windows.Forms.Button 
11.
$cbShared = New-Object System.Windows.Forms.CheckBox 
12.
$cbPublished = New-Object System.Windows.Forms.CheckBox 
13.
$label6 = New-Object System.Windows.Forms.Label 
14.
$comboDriver = New-Object System.Windows.Forms.ComboBox 
15.
$txtDeviceID = New-Object System.Windows.Forms.TextBox 
16.
$label5 = New-Object System.Windows.Forms.Label 
17.
$txtComment = New-Object System.Windows.Forms.TextBox 
18.
$label4 = New-Object System.Windows.Forms.Label 
19.
$label3 = New-Object System.Windows.Forms.Label 
20.
$txtLocation = New-Object System.Windows.Forms.TextBox 
21.
$label2 = New-Object System.Windows.Forms.Label 
22.
$lblPortname = New-Object System.Windows.Forms.Label 
23.
$txtShareName = New-Object System.Windows.Forms.TextBox 
24.
$txtPortName = New-Object System.Windows.Forms.TextBox 
25.
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState 
26.
 
27.
 
28.
#---------------------------------------------- 
29.
# Event Script Blocks 
30.
#---------------------------------------------- 
31.
$handler_btnCreate_Click=  
32.
33.
    #TODO: hier dein Code wenn auf den Button geklickt wird 
34.
    $value = "Drivername: $($comboDriver.SelectedItem)`r`nPortname: $($txtPortName.Text)`r`nSharename: $($txtShareName.Text)`r`nLocation: $($txtLocation.Text)`r`nComment: $($txtComment.Text)`r`nDevice ID: $($txtDeviceID.Text)`r`nPublished: $($cbPublished.Checked)`r`nShared: $($cbShared.Checked)" 
35.
    [System.Windows.Forms.MessageBox]::Show($value) 
36.
37.
 
38.
$handler_formMain_Load=  
39.
40.
    $drivers = gwmi Win32_Printerdriver | select Name 
41.
    $comboDriver.Items.AddRange($drivers.Name) 
42.
43.
 
44.
$OnLoadForm_StateCorrection= 
45.
{#Correct the initial state of the form to prevent the .Net maximized form issue 
46.
	$formMain.WindowState = $InitialFormWindowState 
47.
48.
 
49.
#---------------------------------------------- 
50.
$System_Drawing_Size = New-Object System.Drawing.Size 
51.
$System_Drawing_Size.Height = 256 
52.
$System_Drawing_Size.Width = 265 
53.
$formMain.ClientSize = $System_Drawing_Size 
54.
$formMain.DataBindings.DefaultDataSourceUpdateMode = 0 
55.
$System_Drawing_Size = New-Object System.Drawing.Size 
56.
$System_Drawing_Size.Height = 284 
57.
$System_Drawing_Size.Width = 273 
58.
$formMain.MinimumSize = $System_Drawing_Size 
59.
$formMain.Name = "formMain" 
60.
$formMain.Text = "Create Printer" 
61.
$formMain.add_Load($handler_formMain_Load) 
62.
 
63.
$btnCreate.Anchor = 14 
64.
 
65.
$btnCreate.DataBindings.DefaultDataSourceUpdateMode = 0 
66.
 
67.
$System_Drawing_Point = New-Object System.Drawing.Point 
68.
$System_Drawing_Point.X = 22 
69.
$System_Drawing_Point.Y = 209 
70.
$btnCreate.Location = $System_Drawing_Point 
71.
$btnCreate.Name = "btnCreate" 
72.
$System_Drawing_Size = New-Object System.Drawing.Size 
73.
$System_Drawing_Size.Height = 35 
74.
$System_Drawing_Size.Width = 221 
75.
$btnCreate.Size = $System_Drawing_Size 
76.
$btnCreate.TabIndex = 16 
77.
$btnCreate.Text = "Create Printer" 
78.
$btnCreate.UseVisualStyleBackColor = $True 
79.
$btnCreate.add_Click($handler_btnCreate_Click) 
80.
 
81.
$formMain.Controls.Add($btnCreate) 
82.
 
83.
 
84.
$cbShared.DataBindings.DefaultDataSourceUpdateMode = 0 
85.
 
86.
$System_Drawing_Point = New-Object System.Drawing.Point 
87.
$System_Drawing_Point.X = 179 
88.
$System_Drawing_Point.Y = 179 
89.
$cbShared.Location = $System_Drawing_Point 
90.
$cbShared.Name = "cbShared" 
91.
$System_Drawing_Size = New-Object System.Drawing.Size 
92.
$System_Drawing_Size.Height = 24 
93.
$System_Drawing_Size.Width = 64 
94.
$cbShared.Size = $System_Drawing_Size 
95.
$cbShared.TabIndex = 15 
96.
$cbShared.Text = "shared" 
97.
$cbShared.UseVisualStyleBackColor = $True 
98.
 
99.
$formMain.Controls.Add($cbShared) 
100.
 
101.
 
102.
$cbPublished.DataBindings.DefaultDataSourceUpdateMode = 0 
103.
 
104.
$System_Drawing_Point = New-Object System.Drawing.Point 
105.
$System_Drawing_Point.X = 100 
106.
$System_Drawing_Point.Y = 179 
107.
$cbPublished.Location = $System_Drawing_Point 
108.
$cbPublished.Name = "cbPublished" 
109.
$System_Drawing_Size = New-Object System.Drawing.Size 
110.
$System_Drawing_Size.Height = 24 
111.
$System_Drawing_Size.Width = 95 
112.
$cbPublished.Size = $System_Drawing_Size 
113.
$cbPublished.TabIndex = 14 
114.
$cbPublished.Text = "published" 
115.
$cbPublished.UseVisualStyleBackColor = $True 
116.
 
117.
$formMain.Controls.Add($cbPublished) 
118.
 
119.
$label6.DataBindings.DefaultDataSourceUpdateMode = 0 
120.
 
121.
$System_Drawing_Point = New-Object System.Drawing.Point 
122.
$System_Drawing_Point.X = 22 
123.
$System_Drawing_Point.Y = 25 
124.
$label6.Location = $System_Drawing_Point 
125.
$label6.Name = "label6" 
126.
$System_Drawing_Size = New-Object System.Drawing.Size 
127.
$System_Drawing_Size.Height = 16 
128.
$System_Drawing_Size.Width = 72 
129.
$label6.Size = $System_Drawing_Size 
130.
$label6.TabIndex = 11 
131.
$label6.Text = "Drivername:" 
132.
 
133.
$formMain.Controls.Add($label6) 
134.
 
135.
$comboDriver.Anchor = 13 
136.
$comboDriver.DataBindings.DefaultDataSourceUpdateMode = 0 
137.
$comboDriver.DropDownStyle = 2 
138.
$comboDriver.FormattingEnabled = $True 
139.
$System_Drawing_Point = New-Object System.Drawing.Point 
140.
$System_Drawing_Point.X = 100 
141.
$System_Drawing_Point.Y = 22 
142.
$comboDriver.Location = $System_Drawing_Point 
143.
$comboDriver.Name = "comboDriver" 
144.
$System_Drawing_Size = New-Object System.Drawing.Size 
145.
$System_Drawing_Size.Height = 21 
146.
$System_Drawing_Size.Width = 143 
147.
$comboDriver.Size = $System_Drawing_Size 
148.
$comboDriver.TabIndex = 10 
149.
 
150.
$formMain.Controls.Add($comboDriver) 
151.
 
152.
$txtDeviceID.Anchor = 13 
153.
$txtDeviceID.DataBindings.DefaultDataSourceUpdateMode = 0 
154.
$System_Drawing_Point = New-Object System.Drawing.Point 
155.
$System_Drawing_Point.X = 100 
156.
$System_Drawing_Point.Y = 153 
157.
$txtDeviceID.Location = $System_Drawing_Point 
158.
$txtDeviceID.Name = "txtDeviceID" 
159.
$System_Drawing_Size = New-Object System.Drawing.Size 
160.
$System_Drawing_Size.Height = 20 
161.
$System_Drawing_Size.Width = 143 
162.
$txtDeviceID.Size = $System_Drawing_Size 
163.
$txtDeviceID.TabIndex = 9 
164.
 
165.
$formMain.Controls.Add($txtDeviceID) 
166.
 
167.
$label5.DataBindings.DefaultDataSourceUpdateMode = 0 
168.
 
169.
$System_Drawing_Point = New-Object System.Drawing.Point 
170.
$System_Drawing_Point.X = 22 
171.
$System_Drawing_Point.Y = 156 
172.
$label5.Location = $System_Drawing_Point 
173.
$label5.Name = "label5" 
174.
$System_Drawing_Size = New-Object System.Drawing.Size 
175.
$System_Drawing_Size.Height = 23 
176.
$System_Drawing_Size.Width = 68 
177.
$label5.Size = $System_Drawing_Size 
178.
$label5.TabIndex = 8 
179.
$label5.Text = "Device ID:" 
180.
 
181.
$formMain.Controls.Add($label5) 
182.
 
183.
$txtComment.Anchor = 13 
184.
$txtComment.DataBindings.DefaultDataSourceUpdateMode = 0 
185.
$System_Drawing_Point = New-Object System.Drawing.Point 
186.
$System_Drawing_Point.X = 100 
187.
$System_Drawing_Point.Y = 127 
188.
$txtComment.Location = $System_Drawing_Point 
189.
$txtComment.Name = "txtComment" 
190.
$System_Drawing_Size = New-Object System.Drawing.Size 
191.
$System_Drawing_Size.Height = 20 
192.
$System_Drawing_Size.Width = 143 
193.
$txtComment.Size = $System_Drawing_Size 
194.
$txtComment.TabIndex = 7 
195.
 
196.
$formMain.Controls.Add($txtComment) 
197.
 
198.
$label4.DataBindings.DefaultDataSourceUpdateMode = 0 
199.
 
200.
$System_Drawing_Point = New-Object System.Drawing.Point 
201.
$System_Drawing_Point.X = 22 
202.
$System_Drawing_Point.Y = 130 
203.
$label4.Location = $System_Drawing_Point 
204.
$label4.Name = "label4" 
205.
$System_Drawing_Size = New-Object System.Drawing.Size 
206.
$System_Drawing_Size.Height = 17 
207.
$System_Drawing_Size.Width = 62 
208.
$label4.Size = $System_Drawing_Size 
209.
$label4.TabIndex = 6 
210.
$label4.Text = "Comment:" 
211.
 
212.
$formMain.Controls.Add($label4) 
213.
 
214.
$label3.DataBindings.DefaultDataSourceUpdateMode = 0 
215.
 
216.
$System_Drawing_Point = New-Object System.Drawing.Point 
217.
$System_Drawing_Point.X = 22 
218.
$System_Drawing_Point.Y = 104 
219.
$label3.Location = $System_Drawing_Point 
220.
$label3.Name = "label3" 
221.
$System_Drawing_Size = New-Object System.Drawing.Size 
222.
$System_Drawing_Size.Height = 20 
223.
$System_Drawing_Size.Width = 67 
224.
$label3.Size = $System_Drawing_Size 
225.
$label3.TabIndex = 5 
226.
$label3.Text = "Location:" 
227.
 
228.
$formMain.Controls.Add($label3) 
229.
 
230.
$txtLocation.Anchor = 13 
231.
$txtLocation.DataBindings.DefaultDataSourceUpdateMode = 0 
232.
$System_Drawing_Point = New-Object System.Drawing.Point 
233.
$System_Drawing_Point.X = 100 
234.
$System_Drawing_Point.Y = 101 
235.
$txtLocation.Location = $System_Drawing_Point 
236.
$txtLocation.Name = "txtLocation" 
237.
$System_Drawing_Size = New-Object System.Drawing.Size 
238.
$System_Drawing_Size.Height = 20 
239.
$System_Drawing_Size.Width = 143 
240.
$txtLocation.Size = $System_Drawing_Size 
241.
$txtLocation.TabIndex = 4 
242.
 
243.
$formMain.Controls.Add($txtLocation) 
244.
 
245.
$label2.DataBindings.DefaultDataSourceUpdateMode = 0 
246.
 
247.
$System_Drawing_Point = New-Object System.Drawing.Point 
248.
$System_Drawing_Point.X = 22 
249.
$System_Drawing_Point.Y = 78 
250.
$label2.Location = $System_Drawing_Point 
251.
$label2.Name = "label2" 
252.
$System_Drawing_Size = New-Object System.Drawing.Size 
253.
$System_Drawing_Size.Height = 20 
254.
$System_Drawing_Size.Width = 72 
255.
$label2.Size = $System_Drawing_Size 
256.
$label2.TabIndex = 3 
257.
$label2.Text = "Sharename:" 
258.
 
259.
$formMain.Controls.Add($label2) 
260.
 
261.
$lblPortname.DataBindings.DefaultDataSourceUpdateMode = 0 
262.
 
263.
$System_Drawing_Point = New-Object System.Drawing.Point 
264.
$System_Drawing_Point.X = 22 
265.
$System_Drawing_Point.Y = 52 
266.
$lblPortname.Location = $System_Drawing_Point 
267.
$lblPortname.Name = "lblPortname" 
268.
$System_Drawing_Size = New-Object System.Drawing.Size 
269.
$System_Drawing_Size.Height = 17 
270.
$System_Drawing_Size.Width = 72 
271.
$lblPortname.Size = $System_Drawing_Size 
272.
$lblPortname.TabIndex = 2 
273.
$lblPortname.Text = "Portname:" 
274.
 
275.
$formMain.Controls.Add($lblPortname) 
276.
 
277.
$txtShareName.Anchor = 13 
278.
$txtShareName.DataBindings.DefaultDataSourceUpdateMode = 0 
279.
$System_Drawing_Point = New-Object System.Drawing.Point 
280.
$System_Drawing_Point.X = 100 
281.
$System_Drawing_Point.Y = 75 
282.
$txtShareName.Location = $System_Drawing_Point 
283.
$txtShareName.Name = "txtShareName" 
284.
$System_Drawing_Size = New-Object System.Drawing.Size 
285.
$System_Drawing_Size.Height = 20 
286.
$System_Drawing_Size.Width = 143 
287.
$txtShareName.Size = $System_Drawing_Size 
288.
$txtShareName.TabIndex = 1 
289.
 
290.
$formMain.Controls.Add($txtShareName) 
291.
 
292.
$txtPortName.Anchor = 13 
293.
$txtPortName.DataBindings.DefaultDataSourceUpdateMode = 0 
294.
$System_Drawing_Point = New-Object System.Drawing.Point 
295.
$System_Drawing_Point.X = 100 
296.
$System_Drawing_Point.Y = 49 
297.
$txtPortName.Location = $System_Drawing_Point 
298.
$txtPortName.Name = "txtPortName" 
299.
$System_Drawing_Size = New-Object System.Drawing.Size 
300.
$System_Drawing_Size.Height = 20 
301.
$System_Drawing_Size.Width = 143 
302.
$txtPortName.Size = $System_Drawing_Size 
303.
$txtPortName.TabIndex = 0 
304.
 
305.
$formMain.Controls.Add($txtPortName) 
306.
 
307.
#Save the initial state of the form 
308.
$InitialFormWindowState = $formMain.WindowState 
309.
#Init the OnLoad event to correct the initial state of the form 
310.
$formMain.add_Load($OnLoadForm_StateCorrection) 
311.
#Show the Form 
312.
$formMain.ShowDialog()| Out-Null 
313.
 
314.
} #End Function 
315.
 
316.
GenerateForm
Grüße Uwe
Bitte warten ..
Mitglied: mayho33
14.04.2014 um 16:31 Uhr
Hi!

Von SAPIEN gibt's die ComunityEdition (CE) des PrimalForms. Damit zeichnest du deine Form ala VisualStudio und legst die Ereignisse fest, danach exportierst du dies in eine PS1 und hast eine fertige lauffähige GUI.

Anschließend baust du deine Funktionalitäten ein, fertig!

Link: http://www.sapien.com/software/communitytools

Du musst dich registrieren, damit du das laden kannst, ist aber sehr empfehlenswert.

lg

mayho
Bitte warten ..
Mitglied: colinardo
17.04.2014, aktualisiert um 12:57 Uhr
Wenns das dann war, den Beitrag bitte noch auf gelöst setzen, Merci.

Grüße Uwe
Bitte warten ..
Ähnliche Inhalte
Entwicklung
gelöst Powershell code implementieren (3)

Frage von Mr.KitKat zum Thema Entwicklung ...

Windows Server
gelöst Core Server 2012R2 - GUI mit Powershell nachinstallieren - korrekte Pfadangabe (2)

Frage von takvorian zum Thema Windows Server ...

Batch & Shell
gelöst Cmd Befehle in Powershell GUI aufrufen (5)

Frage von Markus2016 zum Thema Batch & Shell ...

Neue Wissensbeiträge
Batch & Shell

Batch als Dienst bei Systemstart ohne Anmeldung ausführen

(4)

Tipp von tralveller zum Thema Batch & Shell ...

Sicherheits-Tools

Sicherheitstest von Passwörtern für ganze DB-Tabellen

(1)

Tipp von gdconsult zum Thema Sicherheits-Tools ...

Peripheriegeräte

Was beachten bei der Wahl einer USV Anlage im Serverschrank

(9)

Tipp von zetboxit zum Thema Peripheriegeräte ...

Heiß diskutierte Inhalte
Exchange Server
Exchange 2016 Standard Server 2012 R2 Hetzner Mail (41)

Frage von Datsspeed zum Thema Exchange Server ...

Windows 7
gelöst Lokales Adminprofil defekt (25)

Frage von Yannosch zum Thema Windows 7 ...

LAN, WAN, Wireless
gelöst Statische Routen mit ISC-DHCP Server für Android Devices (18)

Frage von terminator zum Thema LAN, WAN, Wireless ...

Exchange Server
gelöst Migration Exchange 2007 zu 2013 - Public Folder teilweise weg (16)

Frage von Andy1987 zum Thema Exchange Server ...