Skip to content

Instantly share code, notes, and snippets.

@vivek1986
Last active October 24, 2023 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vivek1986/af1f8e68396923bd0ecc781bd6b3b923 to your computer and use it in GitHub Desktop.
Save vivek1986/af1f8e68396923bd0ecc781bd6b3b923 to your computer and use it in GitHub Desktop.
Take Control of some Folders like ProgramFiles
$Loc = Get-Location
"Security.Principal.Windows" | % { IEX "( [ $_`Principal ] [$_`Identity ]::GetCurrent() ).IsInRole( 'Administrator' )" } | ? {
$True | % { $Arguments = @('-NoProfile','-ExecutionPolicy Bypass','-NoExit','-File',"`"$($MyInvocation.MyCommand.Path)`"","\`"$Loc\`"");
Start-Process -FilePath PowerShell.exe -Verb RunAs -ArgumentList $Arguments; } }
(Get-Location).ToString()
### Elevated code begins
$Env:UserName,$Env:UserDomain,$Env:ComputerName
$Path = "$ENV:PROGRAMFILES\Sublime Text"
$ACL = Get-ACL -Path $Path
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("$Env:UserName","FullControl","Allow")
$ACL.SetAccessRule($AccessRule)
$ACL | Set-Acl -Path $Path
(Get-ACL -Path $Path).Access | Format-Table IdentityReference,FileSystemRights,AccessControlType,IsInherited,InheritanceFlags -AutoSize
Read-Host
### Elevated code ends
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment