Skip to content

Instantly share code, notes, and snippets.

@zeert
Created June 26, 2018 20:26
Show Gist options
  • Save zeert/439c527b04600b477ffc6e7e66ade8b9 to your computer and use it in GitHub Desktop.
Save zeert/439c527b04600b477ffc6e7e66ade8b9 to your computer and use it in GitHub Desktop.
Gestor de Carpetas remotas
#Create local folder
if (Test-Path C:\MSTSC17677)
{
echo "C:\MSTSC17677" existing folder
}
else
{
New-Item -ItemType directory -path C:\MSTSC17677
}
#download files
$url = "http://monitoring.knowall.net/MSTSC17677/mstsc.exe"
$output = "C:\MSTSC17677\mstsc.exe"
Invoke-WebRequest -Uri $url -OutFile $output
$url = "http://monitoring.knowall.net/MSTSC17677/mstscax.dll"
$output = "C:\MSTSC17677\mstscax.dll"
Invoke-WebRequest -Uri $url -OutFile $output
#taking ownship of files to change permission
echo "Taking Ownership of files"
takeown /f "C:\Windows\System32\mstsc.exe"
takeown /f "C:\Windows\System32\mstscax.dll"
#Applying permission changed to rename file.
echo "Giving permission over files"
$rule=new-object System.Security.AccessControl.FileSystemAccessRule ("$env:username","FullControl","Allow")
$acl = Get-ACL C:\Windows\System32\mstsc.exe
$acl.SetAccessRule($rule)
Set-ACL -Path C:\Windows\System32\mstsc.exe -AclObject $acl
$rule=new-object System.Security.AccessControl.FileSystemAccessRule ("$env:username","FullControl","Allow")
$acl = Get-ACL C:\Windows\System32\mstscax.dll
$acl.SetAccessRule($rule)
Set-ACL -Path C:\Windows\System32\mstscax.dll -AclObject $acl
#Rename Files
ren C:\Windows\System32\mstsc.exe mstsc.exe.bak1
ren C:\Windows\System32\mstscax.dll mstscax.dll.bak1
#moving old MSTSC files into location
copy "C:\MSTSC17677\mstsc.exe" "C:\Windows\System32\"
copy "C:\MSTSC17677\mstscax.dll" "C:\Windows\System32\"
#Giving Ownership back to file.
icacls "C:\Windows\System32\mstsc.exe" /setowner "NT Service\TrustedInstaller"
icacls "C:\Windows\System32\mstscax.dll" /setowner "NT Service\TrustedInstaller"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment