Advertisement
Guest User

Untitled

a guest
Sep 18th, 2022
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.15 KB | None | 0 0
  1. Вот код всего скрипта целиком. Он мне интересен как практика работы с реестром, и вообще powershell:
  2. <code>
  3. ### Elevate Credentials ###
  4. param([switch]$Elevated)
  5. function Check-Admin {
  6. $currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
  7. $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator) }
  8. if ((Check-Admin) -eq $false) {
  9. if ($elevated){ # Could not elevate, quit
  10. } else {
  11. Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ( $myinvocation.MyCommand.Definition ))
  12. } exit
  13. }
  14. ### Elevate Credentials ###
  15. ###Test Registry Value##
  16. function Test-RegistryValue {
  17. param (
  18. [parameter(Mandatory=$true)]
  19. [ValidateNotNullOrEmpty()]$Path,
  20. [parameter(Mandatory=$true)]
  21. [ValidateNotNullOrEmpty()]$Value
  22. )
  23. try {
  24. Get-ItemProperty -Path $Path | Select-Object -ExpandProperty $Value -ErrorAction Stop | Out-Null
  25. return $true
  26. }
  27. catch {
  28. return $false
  29. }
  30. }
  31.  
  32. ###Test Registry Value##
  33.  
  34. ### Switch Encoding to UTF-8 ###
  35. [Console]::outputEncoding = [System.Text.Encoding]::GetEncoding('UTF-8')
  36. ### Switch Encoding to UTF-8 ###
  37.  
  38. #########################Select Registry Tweaks######################
  39. Write-Host "---------------------------------"-ForegroundColor Yellow
  40. Write-Host "Registry Tweaks" -ForegroundColor Yellow
  41. Write-Host "---------------------------------"-ForegroundColor Yellow
  42. Write-Host "1.Add Owner to context menu" -ForegroundColor Green
  43. Write-Host "2.Add Run as Invoker to context menu" -ForegroundColor Green
  44. Write-Host "3.Add Run Powershell as Admin to context menu" -ForegroundColor Green
  45. Write-Host "4.Exit" -ForegroundColor Green
  46. Write-Host "---------------------------------" -ForegroundColor Yellow
  47.  
  48. $Tweaks = Read-Host "Select Applying Tweak "
  49. Switch($Tweaks){
  50. 1{Write-Host '---------------------------------' -ForegroundColor Yellow
  51. Write-Host "Owner Registry Tweak" -ForegroundColor Yellow
  52. Write-Host '---------------------------------'-ForegroundColor Yellow
  53. Write-Host '1. Add to context menu' -ForegroundColor Green
  54. Write-Host '2. Remove from context menu' -ForegroundColor Green
  55. Write-Host "---------------------------------" -ForegroundColor Yellow
  56. $Owner = Read-Host 'Action';
  57. Switch($Owner){
  58. 1{New-PSDrive -PSProvider registry -Root HKEY_CLASSES_ROOT -Name HKCR | Out-Null; `
  59. Set-Location -LiteralPath "HKCR:\*\shell\"; `
  60. If (!(Test-Path -LiteralPath HKCR:\*\shell\takeownership)){New-Item -Path HKCR:\`*\shell\takeownership -Force | Out-Null}; `
  61. New-ItemProperty -LiteralPath HKCR:\*\shell\takeownership -Name HasLUAShield -Value "" -PropertyType String -Force | Out-Null; `
  62. New-ItemProperty -LiteralPath HKCR:\*\shell\takeownership -Name NoWorkingDirectory -Value "" -PropertyType String -Force | Out-Null; `
  63. Set-ItemProperty -LiteralPath HKCR:\*\shell\takeownership -Name '(default)' -Value "Стать Владельцем" -Force | Out-Null; `
  64. If (!(Test-Path -LiteralPath HKCR:\*\shell\takeownership\command)){New-Item -Path HKCR:\`*\shell\takeownership\command -Force | Out-Null}; `
  65. Set-ItemProperty -LiteralPath HKCR:\*\shell\takeownership\command -Name '(default)' -Value 'cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F' -Force | Out-Null; `
  66. New-ItemProperty -LiteralPath HKCR:\*\shell\takeownership\command -Name IsolatedCommand -Value 'cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F' -PropertyType String -Force | Out-Null; `
  67. If (!(Test-Path -LiteralPath HKCR:\exefile\shell\takeownership)){New-Item -Path HKCR:\exefile\shell\takeownership -Force | Out-Null}; `
  68. New-ItemProperty -LiteralPath HKCR:\exefile\shell\takeownership -Name HasLUAShield -Value "" -PropertyType String -Force | Out-Null; `
  69. New-ItemProperty -LiteralPath HKCR:\exefile\shell\takeownership -Name NoWorkingDirectory -Value "" -PropertyType String -Force | Out-Null; `
  70. Set-ItemProperty -LiteralPath HKCR:\exefile\shell\takeownership -Name '(default)' -Value "Стать Владельцем" -Force | Out-Null; `
  71. If (!(Test-Path -LiteralPath HKCR:\exefile\shell\takeownership\command)){New-Item -Path HKCR:\exefile\shell\takeownership\command -Force | Out-Null}; `
  72. Set-ItemProperty -LiteralPath HKCR:\exefile\shell\takeownership\command -Name '(default)' -Value 'cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F' -Force | Out-Null; `
  73. New-ItemProperty -LiteralPath HKCR:\exefile\shell\takeownership\command -Name IsolatedCommand -Value 'cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F' -PropertyType String -Force | Out-Null; `
  74. If (!(Test-Path -LiteralPath HKCR:\dllfile\shell\takeownership)){New-Item -Path HKCR:\dllfile\shell\takeownership -Force | Out-Null}; `
  75. New-ItemProperty -LiteralPath HKCR:\dllfile\shell\takeownership -Name HasLUAShield -Value "" -PropertyType String -Force | Out-Null; `
  76. New-ItemProperty -LiteralPath HKCR:\dllfile\shell\takeownership -Name NoWorkingDirectory -Value "" -PropertyType String -Force | Out-Null; `
  77. Set-ItemProperty -LiteralPath HKCR:\dllfile\shell\takeownership -Name '(default)' -Value "Стать Владельцем" -Force | Out-Null; `
  78. If (!(Test-Path -LiteralPath HKCR:\dllfile\shell\takeownership\command)){New-Item -Path HKCR:\dllfile\shell\takeownership\command -Force | Out-Null}; `
  79. Set-ItemProperty -LiteralPath HKCR:\dllfile\shell\takeownership\command -Name '(default)' -Value 'cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F' -Force | Out-Null; `
  80. New-ItemProperty -LiteralPath HKCR:\dllfile\shell\takeownership\command -Name IsolatedCommand -Value 'cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F' -PropertyType String -Force | Out-Null; `
  81. If (!(Test-Path -LiteralPath HKCR:\Directory\shell\takeownership)){New-Item -Path HKCR:\Directory\shell\takeownership -Force | Out-Null}; `
  82. New-ItemProperty -LiteralPath HKCR:\Directory\shell\takeownership -Name HasLUAShield -Value "" -PropertyType String -Force | Out-Null; `
  83. New-ItemProperty -LiteralPath HKCR:\Directory\shell\takeownership -Name NoWorkingDirectory -Value "" -PropertyType String -Force | Out-Null; `
  84. Set-ItemProperty -LiteralPath HKCR:\Directory\shell\takeownership -Name '(default)' -Value "Стать Владельцем" -Force | Out-Null; `
  85. If (!(Test-Path -LiteralPath HKCR:\Directory\shell\takeownership\command)){New-Item -Path HKCR:\Directory\shell\takeownership\command -Force | Out-Null}; `
  86. Set-ItemProperty -LiteralPath HKCR:\Directory\shell\takeownership\command -Name '(default)' -Value 'cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F' -Force | Out-Null; `
  87. New-ItemProperty -LiteralPath HKCR:\Directory\shell\takeownership\command -Name IsolatedCommand -Value 'cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F' -PropertyType String -Force | Out-Null; `
  88. Write-Host "Set Owner button was added successfully"}
  89. 2{New-PSDrive -PSProvider registry -Root HKEY_CLASSES_ROOT -Name HKCR | Out-Null; `
  90. Remove-Item -LiteralPath HKCR:\`*\shell\takeownership -recurse -Force | Out-Null; `
  91. Remove-Item -LiteralPath HKCR:\exefile\shell\takeownership -recurse -Force | Out-Null; `
  92. Remove-Item -LiteralPath HKCR:\dllfile\shell\takeownership -recurse -Force | Out-Null; `
  93. Remove-Item -LiteralPath HKCR:\Directory\shell\takeownership -recurse -Force | Out-Null; `
  94. Write-Host "Set Owner button was removed successfully"}
  95. }
  96. }
  97. 2{Write-Host '-------------- ------------------' -ForegroundColor Yellow;
  98. Write-Host "Invoker Registry Tweak" -ForegroundColor Yellow;
  99. Write-Host '---------------------------------'-ForegroundColor Yellow;
  100. Write-Host '1. Add to context menu' -ForegroundColor Green;
  101. Write-Host '2. Remove from context menu' -ForegroundColor Green;
  102. Write-Host "---------------------------------" -ForegroundColor Yellow;
  103. $Invoker = Read-Host 'Action';
  104. Switch($Invoker){
  105. 1{If (!(Test-RegistryValue -Path 'HKCU:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers' -Value 'C:\Program Files\ConEmu\ConEmu64.exe')){New-ItemProperty -LiteralPath 'HKCU:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers' `
  106. -Name 'C:\Program Files\ConEmu\ConEmu64.exe' -Value "RUNASINVOKER" -PropertyType String -Force | Out-Null}; `
  107. Write-Host "Inoker mode enabled for ConEmu64"
  108. }
  109. 2{Remove-ItemProperty -Path 'HKCU:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers' `
  110. -Name 'C:\Program Files\ConEmu\ConEmu64.exe' -Force | Out-Null; `
  111. Write-Host "Inoker mode disabled for ConEmu64"}
  112. }
  113. }
  114. 3{Write-Host '---------------------------------' -ForegroundColor Yellow;
  115. Write-Host "Powershell Admin Session Registry Tweak" -ForegroundColor Yellow;
  116. Write-Host '---------------------------------'-ForegroundColor Yellow;
  117. Write-Host '1. Add to context menu' -ForegroundColor Green;
  118. Write-Host '2. Remove from context menu' -ForegroundColor Green;
  119. Write-Host "---------------------------------" -ForegroundColor Yellow;
  120. $PSAdmin = Read-Host 'Action';
  121. Switch($PSAdmin){
  122. 1{New-PSDrive -PSProvider registry -Root HKEY_CLASSES_ROOT -Name HKCR | Out-Null; `
  123. If (!(Test-Path -LiteralPath HKCR:\Microsoft.PowerShellScript.1\Shell\runas\command)){New-Item -Path HKCR:\Microsoft.PowerShellScript.1\Shell\runas\command -Force | Out-Null}; `
  124. New-ItemProperty -LiteralPath HKCR:\Microsoft.PowerShellScript.1\Shell\runas\ -Name HasLUAShield -Value '' -PropertyType String -Force | Out-Null; `
  125. New-ItemProperty -LiteralPath HKCR:\Microsoft.PowerShellScript.1\Shell\runas\command -Name 'Default' -Value 'powershell.exe –NoExit "-Command" "if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & '%1'\"' -PropertyType String -Force | Out-Null; `
  126. }
  127. 2{}
  128. }
  129.  
  130. }
  131. }
  132. #4{Write-Host 'Exit'; exit}
  133. # default {Write-Host 'Wrong choice, try again' -ForegroundColor Red}
  134. </code>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement