SHARE
TWEET

Run_As_Admin_PS.bat

hackoo May 11th, 2020 (edited) 2,224 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2. Mode 90,5
  3. Title Run as admin using Powershell to manage windows Processes in command line by Hackoo 2020
  4. If [%1] NEQ [Admin] Goto RunAsAdmin
  5. Call :CreateShortcut
  6. :Main
  7. Set /a W=400
  8. Mode %W%,%W% & cls & color 0A
  9. Set "MyPID="
  10. REM =================================================================================================
  11.   Powershell ^
  12.   Get-WmiObject Win32_Process ^
  13. | where commandline -NE $null ^
  14. | Select-Object ProcessID,Name,CommandLine ^
  15. | Out-String -Width %W% ^
  16. | Findstr /I /V "Admin" ^
  17. | Findstr /I /V "Get-WmiObject"
  18. REM The second powershell command is for saving the output result into a text file with same name ;
  19. REM as the script but with ".txt" in extension.
  20.   Powershell ^
  21.   Get-WmiObject Win32_Process ^
  22. | where commandline -NE $null ^
  23. | Select-Object ProcessID,Name,CommandLine ^
  24. | Out-String -Width %W% ^
  25. | Findstr /I /V "Admin" ^
  26. | Findstr /I /V "Get-WmiObject" ^
  27. | Out-File "%~dpn0.txt" -Encoding  ASCII
  28. echo(================================================================================================
  29. SET /P "MyPID=Please enter the Process ID number in order to kill its Application correspondante : "
  30. IF [%MyPID%] EQU [] GOTO Error
  31. cls & echo(
  32. Taskkill /PID %MyPID% /T /F
  33. If ErrorLevel 1 Color 0C
  34. Timeout /T 2 /NoBreak>nul & Goto Main
  35. ::---------------------------------------------------------------------------------------------------
  36. :RunAsAdmin
  37. cls & color 0B & Mode 90,5
  38. echo(
  39. echo(            ===========================================================
  40. echo(                  Please wait a while ... Running as Admin ....
  41. echo(            ===========================================================
  42. Powershell start -verb runas '%0' Admin & Exit
  43. ::---------------------------------------------------------------------------------------------------
  44. :Error
  45. cls & echo( & Color 0C
  46. ECHO You did not enter a PID ????
  47. Timeout /T 2 /NoBreak>nul & Goto Main
  48. ::---------------------------------------------------------------------------------------------------
  49. :CreateShortcut
  50. Powershell ^
  51. "$s=(New-Object -COM WScript.Shell).CreateShortcut('%userprofile%\Desktop\%~n0.lnk'); ^
  52. $s.TargetPath='%~f0'; ^
  53. $s.WorkingDirectory='%~dp0'; ^
  54. $s.IconLocation='PowerShell.exe,0'; ^
  55. $s.Description='Run as admin using Powershell to manage windows Processes in command line'; ^
  56. $s.HotKey='CTRL+ALT+R'; ^
  57. $s.Save()"
  58. Exit /B
  59. ::---------------------------------------------------------------------------------------------------
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top