Advertisement
Werezwolf

CMD Elevated Script Run

Jul 31st, 2014
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.77 KB | None | 0 0
  1. @Echo Off
  2. ::This Script is to run read based DOS commands with Network Paths, Permissions Elevation and Logging back to server
  3.  
  4. Set xdate=%date:~-4,4%%date:~-7,2%%date:~-10,2%
  5. Set return="^& echo."
  6. ::Mapped Network drive to read from
  7. Set drive=Z:
  8. set location=%drive%\~Server
  9. ::Logging
  10. @mkdir %location%\Logs\RunAs\%xdate%
  11. set log=%location%\Logs\RunAs\%xdate%\history.txt
  12. ::Got to put these scripts on to the local computer
  13. set xlocation=DomainTemp_%PROCESSOR_ARCHITECTURE%_%computername%
  14.  
  15. ::Will be a non persistent drive labeled X:
  16. ::This is for the scripts that need to write back to the server
  17. setx xdrive \\192.168.0.2\Path\To\Destination
  18.  
  19. ::So we don't lose who is actually running the script
  20. SETX xusername %username%
  21.  
  22. cd /D %location%\Scripts
  23. ::List Programs
  24. dir /b /o:n programs
  25. ::Ask which one
  26. Set /P xprog=Type the name of the program.
  27. ::Do not pass Go. Do not collect $200
  28. If NOT EXIST %location%\Scripts\programs\%xprog% Goto label_error_1
  29.  
  30. ::make Temp
  31. mkdir %appdata%\%xlocation%
  32.  
  33. ::Copy program to temp
  34. ROBOCOPY %location%\Scripts\programs\ %appdata%\%xlocation% %xprog%
  35.  
  36. ::Change to temp
  37. cd /d %appdata%\%xlocation%
  38.  
  39. ::Log Details
  40. echo [%xdate% - %time%]: %xusername% >> %log%
  41. echo [%xdate% - %time%]: %xprog% >> %log%
  42.  
  43. ::Run Program as Administrator (or elevated account)
  44. ::Will also ask for Password
  45. Runas /env /noprofile /user:administrator@%userdomain% %xprog%
  46. echo [%xdate% - %time%]: Runas Errorlevel:%errorlevel% (0=Success 1=Fail) >> %log%
  47. echo run %appdata%\%xlocation%\%xprog% >> %log%
  48. echo ---------- >> %log%
  49. exit
  50.  
  51. :label_error_1
  52. ::Dose not Exist dear user
  53. msg %xusername% "File dose Not Exist on Server"
  54. echo [%xdate% - %time%]: %xusername% >> %log%
  55. echo %xprog% Dose Not Exist >> %log%
  56. echo ---------- >> %log%
  57. pause
  58. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement