Remoting Slideshow

  1. ########################## 
  2. #Coded by Felipe Binotto## 
  3. ########################## 
  4.  
  5.  
  6.  
  7. function Return-DropDown([Object] $DropDown){ 
  8.     $Choice = $DropDown.SelectedItem.ToString() 
  9.         $user = $user.Text 
  10.             foreach($Item in $xml.Items.Item){ 
  11.             if($Item.app -eq $Choice){ 
  12.             if($Item.path.split(".")[-1] -eq "msc"){ 
  13.             .\psexec -e -d -u $user -p $password.Text mmc "$($Item.path)"
  14.             elseif($Item.arguments){ 
  15.             .\psexec -e -d -u $user -p $password.Text $Item.path $Item.arguments
  16.             else{.\psexec -e -d -u $user -p $password.Text $Item.path}} 
  17.              
  18.          
  19. }             
  20. function Add-App(){ 
  21.  
  22. Get-Name 
  23. if($script:check){ 
  24. $objForm = New-Object System.Windows.Forms.OpenFileDialog 
  25. $objForm.InitialDirectory = "C:\" 
  26. $objForm.Filter = "All Files (*.*)|*.*" 
  27. $objForm.Title = "Source" 
  28. $objForm.ShowHelp = $true 
  29. $show = $objForm.ShowDialog() 
  30. if($show.value__ -eq 1){ 
  31.  
  32. Get-Arguments 
  33. $path = $objForm.FileName 
  34. $item = $xml.CreateElement("item"
  35. $Item.SetAttribute("App", $script:app
  36. $Item.SetAttribute("Path", $path
  37. $Item.SetAttribute("Arguments", $script:arg
  38. $item.set_InnerText($app
  39. $xml.get_DocumentElement().AppendChild($item
  40. $xml | Export-Clixml apps.xml 
  41. $DropDown.Items.Add($Item.app) | Out-Null 
  42. }}} 
  43.  
  44. function Remove-App(){ 
  45.  
  46. for($i=0; $i -lt $xml.Items.Item.Count; $i++){ 
  47. if($xml.Items.Item[$i].App -eq $DropDown.SelectedItem.ToString()){ 
  48. $DropDown.Items.Remove($xml.Items.Item[$i].app
  49. $xml.Items.RemoveChild($xml.Items.item[$i]) 
  50. $xml | Export-Clixml apps.xml
  51.  
  52. }} 
  53.  
  54.  
  55. Function Get-Name(){ 
  56.  
  57. $Form = New-Object System.Windows.Forms.Form 
  58. $Form.width = 200 
  59. $Form.height = 90 
  60. $Form.startposition = "centerscreen" 
  61. $Form.Text = "App's Name" 
  62. $arg = new-object System.Windows.Forms.TextBox 
  63. $arg.Location = new-object System.Drawing.Size(10,5) 
  64. $arg.Size = new-object System.Drawing.Size(170,20) 
  65. $OKButton = new-object System.Windows.Forms.Button 
  66. $OKButton.Text = "OK" 
  67. $OKButton.Add_Click({$script:app = $arg.Text; $script:check = $true; $Form.Close()}) 
  68. $OKButton.Location = new-object System.Drawing.Size(50,35) 
  69. $OKButton.Size = new-object System.Drawing.Size(40,20) 
  70. $CButton = new-object System.Windows.Forms.Button 
  71. $CButton.Text = "CANCEL" 
  72. $CButton.Location = new-object System.Drawing.Size(95,35) 
  73. $CButton.Size = new-object System.Drawing.Size(70,20) 
  74. $CButton.Add_Click({$script:check = $false; $Form.Close()}) 
  75. $Form.Controls.Add($CButton
  76. $Form.Controls.Add($arg
  77. $Form.Controls.Add($arglabel
  78. $Form.Controls.Add($OKButton
  79. $Form.Add_Shown({$Form.Activate()}) 
  80. $Form.ShowDialog()} 
  81.  
  82. Function Get-Arguments(){ 
  83.  
  84. $Form = New-Object System.Windows.Forms.Form 
  85. $Form.width = 200 
  86. $Form.height = 90 
  87. $Form.startposition = "centerscreen" 
  88. $Form.Text = "Arguments" 
  89. $arg = new-object System.Windows.Forms.TextBox 
  90. $arg.Location = new-object System.Drawing.Size(10,5) 
  91. $arg.Size = new-object System.Drawing.Size(170,20) 
  92. $OKButton = new-object System.Windows.Forms.Button 
  93. $OKButton.Text = "OK" 
  94. $OKButton.Add_Click({$script:arg = $arg.Text; $Form.Close()}) 
  95. $OKButton.Location = new-object System.Drawing.Size(50,35) 
  96. $OKButton.Size = new-object System.Drawing.Size(40,20) 
  97. $NOButton = new-object System.Windows.Forms.Button 
  98. $NOButton.Text = "NO" 
  99. $NOButton.Location = new-object System.Drawing.Size(95,35) 
  100. $NOButton.Size = new-object System.Drawing.Size(40,20) 
  101. $NOButton.Add_Click({$Form.Close()}) 
  102. $Form.Controls.Add($NOButton
  103. $Form.Controls.Add($arg
  104. $Form.Controls.Add($OKButton
  105. $Form.Add_Shown({$Form.Activate()}) 
  106. $Form.ShowDialog()} 
  107.  
  108.  
  109. Function Main(){ 
  110.  
  111.  
  112. [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null 
  113. [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null 
  114.  
  115. if(Test-Path apps.xml){$xml = Import-Clixml apps.xml
  116. else
  117. $xml = @'  
  118. <items><item App="CMD" Path="C:\Windows\System32\cmd.exe" Arguments="">CMD</item></items> 
  119. '@ | Out-File apps.xml 
  120. $xml = [xml](Get-Content apps.xml)} 
  121.  
  122.  
  123. $Form = New-Object System.Windows.Forms.Form 
  124. $Form.width = 300 
  125. $Form.height = 255 
  126. $Form.Text = "Run As" 
  127. $Form.backcolor = "black" 
  128. $Form.maximumsize = New-Object System.Drawing.Size(300,250) 
  129. $Form.startposition = "centerscreen" 
  130.  
  131. $Form.KeyPreview = $True 
  132. $Form.Add_KeyDown({if ($_.KeyCode -eq "Enter")  
  133.     {Try{Return-DropDown($DropDown)}Catch{[Windows.Forms.MessageBox]::Show("Select one of the options from the DropBox.")}}}) 
  134. $Form.Add_KeyDown({if ($_.KeyCode -eq "Escape")  
  135.     {$Form.Close()}}) 
  136.      
  137. $DropDown = new-object System.Windows.Forms.ComboBox 
  138. $DropDown.Location = new-object System.Drawing.Size(60,100) 
  139. $DropDown.Size = new-object System.Drawing.Size(180,30) 
  140.  
  141. $DropDownArrayList = New-Object System.Collections.ArrayList 
  142. foreach($Item in $xml.Items.Item){ 
  143. $DropDownArrayList.add($Item.App) | Out-Null
  144. $DropDownArrayList.sort() 
  145.  
  146. ForEach ($Item in $DropDownArrayList) { 
  147.     $DropDown.Items.Add($Item) | Out-Null 
  148.  
  149. $RunButton = new-object System.Windows.Forms.Button 
  150. $RunButton.Location = new-object System.Drawing.Size(100,140) 
  151. $RunButton.Size = new-object System.Drawing.Size(100,20) 
  152. $RunButton.BackColor = "Transparent" 
  153. $RunButton.Text = "OK" 
  154. $RunButton.ForeColor = "White" 
  155. $RunButton.Add_Click({Try{Return-DropDown($DropDown)}Catch{[Windows.Forms.MessageBox]::Show("Select one of the options from the DropBox.")}}) 
  156.  
  157. $AddButton = new-object System.Windows.Forms.Button 
  158. $AddButton.Location = new-object System.Drawing.Size(5,190) 
  159. $AddButton.Size = new-object System.Drawing.Size(20,20) 
  160. $AddButton.BackColor = "Transparent" 
  161. $AddButton.Text = "+" 
  162. $AddButton.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",20,5,0,0) 
  163. $AddButton.ForeColor = "White" 
  164. $AddButton.Add_Click({Add-App}) 
  165.  
  166. $RemoveButton = new-object System.Windows.Forms.Button 
  167. $RemoveButton.Location = new-object System.Drawing.Size(26,190) 
  168. $RemoveButton.Size = new-object System.Drawing.Size(20,20) 
  169. $RemoveButton.BackColor = "Transparent" 
  170. $RemoveButton.Text = "-" 
  171. $RemoveButton.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",20,5,0,0) 
  172. $RemoveButton.ForeColor = "White" 
  173. $RemoveButton.Add_Click({Remove-App}) 
  174.  
  175. $LockButton = new-object System.Windows.Forms.Button 
  176. $LockButton.Location = new-object System.Drawing.Size(47,190) 
  177. $LockButton.Size = new-object System.Drawing.Size(70,20) 
  178. $LockButton.BackColor = "Transparent" 
  179. $LockButton.Text = "LOCK" 
  180. $LockButton.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",14,5,0,0) 
  181. $LockButton.ForeColor = "White" 
  182. $LockButton.Add_Click({rundll32.exe user32.dll, LockWorkStation}) 
  183.  
  184. $user = new-object System.Windows.Forms.TextBox 
  185. $user.Location = new-object System.Drawing.Size(100,10) 
  186. $user.Size = new-object System.Drawing.Size(150,20) 
  187.  
  188. $userLabel = new-object System.Windows.Forms.Label 
  189. $userLabel.Location = new-object System.Drawing.Size(10,10) 
  190. $userLabel.size = new-object System.Drawing.Size(200,30) 
  191. $userLabel.backcolor = "Transparent" 
  192. $userLabel.forecolor = "white" 
  193. $userLabel.Font = new-object System.Drawing.Font("Microsoft Sans Serif",12,[System.Drawing.FontStyle]::Bold
  194. $userLabel.Text = "Username" 
  195.  
  196. $password = new-object System.Windows.Forms.TextBox 
  197. $password.Location = new-object System.Drawing.Size(100,50) 
  198. $password.UseSystemPasswordChar = $true 
  199. $password.Size = new-object System.Drawing.Size(150,50) 
  200.  
  201. $passwordLabel = new-object System.Windows.Forms.Label 
  202. $passwordLabel.Location = new-object System.Drawing.Size(10,50) 
  203. $passwordLabel.size = new-object System.Drawing.Size(150,30) 
  204. $passwordLabel.backcolor = "Transparent" 
  205. $passwordLabel.forecolor = "white" 
  206. $passwordLabel.Font = new-object System.Drawing.Font("Microsoft Sans Serif",12,[System.Drawing.FontStyle]::Bold
  207. $passwordLabel.Text = "Password" 
  208.  
  209. $Form.Controls.Add($user
  210. $Form.Controls.Add($userLabel
  211. $Form.Controls.Add($password
  212. $Form.Controls.Add($passwordLabel
  213. $Form.Controls.Add($DropDown
  214. $Form.Controls.Add($RunButton
  215. $Form.Controls.Add($RemoveButton
  216. $Form.Controls.Add($AddButton
  217. $Form.Controls.Add($LockButton
  218. $Form.Add_Shown({$Form.Activate()}) 
  219. $Form.ShowDialog()} 
  220. Main 
 
Loading...
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.