Author Topic: useful Batch file script to add run as admin to .ps1 or .vbs files  (Read 3536 times)

0 Members and 1 Guest are viewing this topic.

Offline Julian

  • "Cat and Mum Guy"
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Jun 2015
  • Posts: 1320
  • Location: USA, New Mexico
  • Karma: 38
    • View Profile
Here is a useful Batch file script to add run as admin to .ps1 or .vbs files. Just copy and save as vbs_ps_admin_add.bat  Enjoy  :cheesy: (For windows 7 and newer)
Code: [Select]
@echo off
color 80
 cls
 :start
 echo.
ECHO -------------------------------------------------------------------------------
echo.-------(Useful script to add or remove run as admin to .ps1 or .vbs files)-----
echo.----------(You need to be An Administrator to run these commands.)-------------
echo.------------------(This is used for Windows 7 or later)------------------------
ECHO -------------------------------------------------------------------------------
 echo 1.Power Shell
 echo 2.vbs Note:(runs for both wscript.exe and cscript.exe)
 echo 3 I'm done.
 echo.
 echo.
 set /p x=Pick:
 IF '%x%' == '%x%' GOTO Select_%x%

:Select_1
GOTO Select_4

:Select_2
GOTO Select_5

:Select_3
 exit

:Select_4
cls
ECHO -------------------------------------------------------------------------------
echo.------Would you like to Add or Remove run as Admin to .ps1 right click?--------
ECHO -------------------------------------------------------------------------------
 echo 1. This will add Admin to right click?
 echo 2. This will remove Admin to right click?
 echo 3. Do Nothing.
set /p x=Pick:
 IF '%x%' == '%x%' GOTO Power_%x%

:Power_1
REG ADD "HKCR\Microsoft.PowerShellScript.1\Shell\runas" /v HasLUAShield /t REG_SZ /d "" /f
REG ADD "HKCR\Microsoft.PowerShellScript.1\Shell\runas\command" /ve /t REG_EXPAND_SZ /d "\"%%SYSTEMROOT%%\System32\WindowsPowerShell\v1.0\powershell.exe\" -executionpolicy bypass -nologo -file \"%%1\"" /f
cls
GOTO start

:Power_2
REG DELETE "HKCR\Microsoft.PowerShellScript.1\Shell\runas" /f
cls
GOTO start

:Power_3
cls
GOTO start


:Select_5
cls
ECHO -------------------------------------------------------------------------------
echo.------Would you like to Add or Remove run as Admin to .vbs right click?--------
ECHO -------------------------------------------------------------------------------
 echo 1. This will add Admin to right click.
 echo 2. This will remove Admin to right click.
 echo 3. Do Nothing.
set /p x=Pick:
 IF '%x%' == '%x%' GOTO VBscript_%x%

:VBscript_1
REG ADD "HKCR\VBSFile\Shell\runas" /v HasLUAShield /t REG_SZ /d "" /f
REG ADD "HKCR\VBSFile\Shell\runas\Command" /ve /t REG_EXPAND_SZ /d "\"%%SYSTEMROOT%%\System32\wscript.exe\" \"%%1\" %%*" /f
REG ADD "HKCR\VBSFile\Shell\runas\Command" /ve /t REG_EXPAND_SZ /d "\"%%SYSTEMROOT%%\System32\cscript.exe\" \"%%1\" %%*" /f
cls
GOTO start

:VBscript_2
REG DELETE "HKCR\VBSFile\Shell\runas" /f
cls
GOTO start

:VBscript_3
cls
GOTO start

I also attached the batch file on this post.
Julian

 

anything