Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. # Find currently logged on user
  2. $Loggedon = Get-WmiObject -ComputerName $env:COMPUTERNAME -Class Win32_Computersystem | Select-Object UserName
  3. # Split domain and username.
  4. $Domain,$User = $Loggedon.Username.split('',2)
  5.  
  6.  
  7.  
  8. # NOTE: When you use a SPECIFIC catch block, exceptions thrown by -ErrorAction Stop MAY LACK
  9. # some InvocationInfo details such as ScriptLineNumber.
  10. # REMEDY: If that affects you, remove the SPECIFIC exception type [System.Management.Automation.RuntimeException] in the code below
  11. # and use ONE generic catch block instead. Such a catch block then handles ALL error types, so you would need to
  12. # add the logic to handle different error types differently by yourself.
  13.  
  14.  
  15. # catch [System.Management.Automation.RuntimeException]
  16. # NOTE: When you use a SPECIFIC catch block, exceptions thrown by -ErrorAction Stop MAY LACK
  17. # some InvocationInfo details such as ScriptLineNumber.
  18. # REMEDY: If that affects you, remove the SPECIFIC exception type [System.Management.Automation.CommandNotFoundException] in the code below
  19. # and use ONE generic catch block instead. Such a catch block then handles ALL error types, so you would need to
  20. # add the logic to handle different error types differently by yourself.
  21. {
  22. # get error record
  23. [Management.Automation.ErrorRecord]$e = $_
  24.  
  25. # retrieve information about runtime error
  26. $info = [PSCustomObject]@{
  27. Exception = $e.Exception.Message
  28. Reason = $e.CategoryInfo.Reason
  29. Target = $e.CategoryInfo.TargetName
  30. Script = $e.InvocationInfo.ScriptName
  31. Line = $e.InvocationInfo.ScriptLineNumber
  32. Column = $e.InvocationInfo.OffsetInLine
  33. }
  34.  
  35. # output information. Post-process collected info, and log info (optional)
  36. $info
  37. }
  38.  
  39. {
  40. # get error record
  41. [Management.Automation.ErrorRecord]$e = $_
  42.  
  43. # retrieve information about runtime error
  44. $info = [PSCustomObject]@{
  45. Exception = $e.Exception.Message
  46. Reason = $e.CategoryInfo.Reason
  47. Target = $e.CategoryInfo.TargetName
  48. Script = $e.InvocationInfo.ScriptName
  49. Line = $e.InvocationInfo.ScriptLineNumber
  50. Column = $e.InvocationInfo.OffsetInLine
  51. }
  52.  
  53. # output information. Post-process collected info, and log info (optional)
  54. $info#>
  55. }
  56.  
  57.  
  58. # Oppretter WindowsForm / GUI for applikasjonen.
  59. Add-Type -AssemblyName System.Windows.Forms
  60. Add-Type -AssemblyName System.Drawing
  61.  
  62. # Heading
  63. $form = New-Object -TypeName System.Windows.Forms.Form
  64. $form.Text = 'Test-Heading'
  65. $form.Size = New-Object -TypeName System.Drawing.Size -ArgumentList (400, 600)
  66. $form.StartPosition = 'CenterScreen'
  67.  
  68. #OK-knapp
  69. $OKButton = New-Object -TypeName System.Windows.Forms.Button
  70. $OKButton.Location = New-Object -TypeName System.Drawing.Point -ArgumentList (170, 485)
  71. $OKButton.Size = New-Object -TypeName System.Drawing.Size -ArgumentList (100, 50)
  72. $OKButton.Text = 'OK'
  73. $OKButton.DialogResult = [Windows.Forms.DialogResult]::OK
  74. $form.AcceptButton = $OKButton
  75. $form.Controls.Add($OKButton)
  76.  
  77. #Avbryt-knapp
  78. $CancelButton = New-Object -TypeName System.Windows.Forms.Button
  79. $CancelButton.Location = New-Object -TypeName System.Drawing.Point -ArgumentList (270, 485)
  80. $CancelButton.Size = New-Object -TypeName System.Drawing.Size -ArgumentList (100, 50)
  81. $CancelButton.Text = 'Avbryt'
  82. $CancelButton.DialogResult = [Windows.Forms.DialogResult]::Cancel
  83. $form.CancelButton = $CancelButton
  84. $form.Controls.Add($CancelButton)
  85.  
  86. # Tekst-label
  87. $label = New-Object -TypeName System.Windows.Forms.Label
  88. $label.Location = New-Object -TypeName System.Drawing.Point -ArgumentList (10, 20)
  89. $label.Size = New-Object -TypeName System.Drawing.Size -ArgumentList (280, 20)
  90. $label.Text = 'Test-Label'
  91. $form.Controls.Add($label)
  92.  
  93. # Liste-boks
  94. $listBox = New-Object -TypeName System.Windows.Forms.ListBox
  95. $listBox.Location = New-Object -TypeName System.Drawing.Point -ArgumentList (10, 40)
  96. $listBox.Size = New-Object -TypeName System.Drawing.Size -ArgumentList (360, 20)
  97. $listBox.Height = 400
  98.  
  99.  
  100. # Hashtable made to be able to show one text in the listbox, but return a different value.
  101. $TESTalias = @{
  102. 'TEST1' = '1'
  103. 'TEST2' = '2'
  104. 'TEST3' = '3'
  105.  
  106. }
  107.  
  108. # Listbox-objects, one listbox-item pr. line.
  109. $null = $listBox.Items.Add('TEST1')
  110. $null = $listBox.Items.Add('TEST2')
  111. $null = $listBox.Items.Add('TEST3')
  112.  
  113. $form.Controls.Add($listBox)
  114.  
  115. $form.Topmost = $true
  116.  
  117. $result = $form.ShowDialog()
  118.  
  119. if ($result -eq [Windows.Forms.DialogResult]::OK)
  120. {
  121.  
  122. $TESTalias = $TESThash[$listBox.SelectedItem]
  123.  
  124. # File to change
  125. $file = "C:Users$Userist.ini"
  126.  
  127. # Get file content and store it into $content variable
  128. $content = Get-Content -Path $file
  129.  
  130. # Endrer tekst pƄ linje 33 og linje 53
  131. $content[32] = 'PICTUREPATH=K:OpplaeringBilete'+"$TESTalias"
  132. $content[52] = 'PICTUREPATH=K:OpplaeringBilete'+"$TESTalias"
  133.  
  134.  
  135. # Set the new content
  136. $content | Set-Content -Path $file
  137. if(!(Test-Path -Path "HKLM:SOFTWAREMicrosoftWindowsCurrentversionUninstallExtensBildeFix")){
  138. New-Item -Path "HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstallExtensBildeFix" -Value "1"}
  139.  
  140. $form.Controls|%{$_.Text}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement