“Bakalım Powershell’in sınırlarını ne kadar zorlayabiliyorum” yaklaşımının bir sonucu olarak geliştirdiğim bu script’i de sizlerle paylaşmak istiyorum.
Yine bir fonksiyon kullandım ve script’imi Powershell Profil yoluna attım. Böylece her Powershell açılışında fonksiyonumu tanımasını sağladım.
Bana ise bir tek Powershell’i açıp radyo yazmak düştü!
Bir form tasarımı yaptım ve aşağıdaki gibi gözükmesini sağladım.
Bütün radyo listesini çekip bana sergilediğinde tek yapmak zorunda oldugum Radyo 35′i seçip özlediğim Izmir’imi dinlemekti, ben de öyle yaptım!
İşte kaynak kodları da aşağıdaki gibi. Doğrudan kopyalayıp radyo.ps1 ismiyle kaydedip Powershell içerisinden kullanabilirsiniz.
function radyo { [reflection.assembly]::loadwithpartialname(“System.Windows.Forms”) | Out-Null [reflection.assembly]::loadwithpartialname(“System.Drawing”) | Out-Null $form1 = New-Object System.Windows.Forms.Form $button2 = New-Object System.Windows.Forms.Button $button1 = New-Object System.Windows.Forms.Button $comboBox1 = New-Object System.Windows.Forms.ComboBox $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState $button1_OnClick= { if ($radyocal){ $radyocal.quit() } $form1.Text = “Radyo Yukleniyor – BakiOnur Radyo” $radyolar = new-object -com “InternetExplorer.Application” $radyolar.navigate(“http://www.radyolar.org/radyolar.asp”) start-sleep -s 2 $bulunanistasyon=$radyolar.Document.getElementsByTagName(“a”) | where{$_.innertext -eq $combobox1.selecteditem} $radyocal = new-object -com “InternetExplorer.Application” $radyocal.navigate($bulunanistasyon.href) $radyolar.quit() $form1.Text = “BakiOnur Radyo” } $form1_load={ $form1.Text = “Liste Yükleniyor – BakiOnur Radyo” $radyolar = new-object -com “InternetExplorer.Application” $radyolar.navigate(“http://www.radyolar.org/radyolar.asp”) start-sleep -s 2 $link = $radyolar.Document.getElementsByTagName(“a”) $link | foreach{ if(!($_.innertext -eq $null)){ $combobox1.items.add($_.innertext)} } $combobox1.items.remove(“Anasayfa”) $combobox1.items.remove(“YARDIM”) $combobox1.items.remove(“Radyolar”) $combobox1.items.remove(“Radyo Ekle”) $combobox1.items.remove(“ANASAYFA”) $combobox1.items.remove(“Frekanslar”) $combobox1.items.remove(“Sohbet Odas?”) $combobox1.items.remove(“?leti?im”) $combobox1.items.remove(“REKLAM”) $combobox1.items.remove(“SIK SORULAN SORULAR”) $combobox1.items.remove(“NEDEN D?NLEYEM?YORUM”) $combobox1.items.remove(“HATA B?LD?R”) $combobox1.items.remove(“?LET???M”) $combobox1.items.remove(“Radyo ekle”) $radyolar.Quit() $form1.Text = “Radyo Seciniz – BakiOnur Radyo” } $button2_OnClick= { $acikapp = new-object -com shell.application $acikradyo = $acikapp.windows() | where {$_.Type -eq “HTML Document” -and $_.locationURL -like “*http://www.radyolar.org/*”} if($acikradyo){ $acikradyo.quit() } $form1.close() } $OnLoadForm_StateCorrection= { $form1.WindowState = $InitialFormWindowState } $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 101 $System_Drawing_Size.Width = 252 $form1.ClientSize = $System_Drawing_Size $form1.DataBindings.DefaultDataSourceUpdateMode = 0 $form1.Name = “form1″ $form1.Text = “BakiOnur Radyo” $button2.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 153 $System_Drawing_Point.Y = 66 $button2.Location = $System_Drawing_Point $button2.Name = “button2″ $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 23 $System_Drawing_Size.Width = 75 $button2.Size = $System_Drawing_Size $button2.TabIndex = 2 $button2.Text = “Kapat” $button2.UseVisualStyleBackColor = $True $button2.add_Click($button2_OnClick) $form1.Controls.Add($button2) $button1.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 153 $System_Drawing_Point.Y = 31 $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 = “Dinle” $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 = 12 $System_Drawing_Point.Y = 33 $comboBox1.Location = $System_Drawing_Point $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) $InitialFormWindowState = $form1.WindowState $form1.add_Load($OnLoadForm_StateCorrection) $form1.add_Load($form1_load) $form1.ShowDialog()| Out-Null } |
Umarım müzik keyfinize katkıda bulunmusumdur!
Tesekkürler,
BakiOnur