Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Echo Off
- ::This Script is to run read based DOS commands with Network Paths, Permissions Elevation and Logging back to server
- Set xdate=%date:~-4,4%%date:~-7,2%%date:~-10,2%
- Set return="^& echo."
- ::Mapped Network drive to read from
- Set drive=Z:
- set location=%drive%\~Server
- ::Logging
- @mkdir %location%\Logs\RunAs\%xdate%
- set log=%location%\Logs\RunAs\%xdate%\history.txt
- ::Got to put these scripts on to the local computer
- set xlocation=DomainTemp_%PROCESSOR_ARCHITECTURE%_%computername%
- ::Will be a non persistent drive labeled X:
- ::This is for the scripts that need to write back to the server
- setx xdrive \\192.168.0.2\Path\To\Destination
- ::So we don't lose who is actually running the script
- SETX xusername %username%
- cd /D %location%\Scripts
- ::List Programs
- dir /b /o:n programs
- ::Ask which one
- Set /P xprog=Type the name of the program.
- ::Do not pass Go. Do not collect $200
- If NOT EXIST %location%\Scripts\programs\%xprog% Goto label_error_1
- ::make Temp
- mkdir %appdata%\%xlocation%
- ::Copy program to temp
- ROBOCOPY %location%\Scripts\programs\ %appdata%\%xlocation% %xprog%
- ::Change to temp
- cd /d %appdata%\%xlocation%
- ::Log Details
- echo [%xdate% - %time%]: %xusername% >> %log%
- echo [%xdate% - %time%]: %xprog% >> %log%
- ::Run Program as Administrator (or elevated account)
- ::Will also ask for Password
- Runas /env /noprofile /user:administrator@%userdomain% %xprog%
- echo [%xdate% - %time%]: Runas Errorlevel:%errorlevel% (0=Success 1=Fail) >> %log%
- echo run %appdata%\%xlocation%\%xprog% >> %log%
- echo ---------- >> %log%
- exit
- :label_error_1
- ::Dose not Exist dear user
- msg %xusername% "File dose Not Exist on Server"
- echo [%xdate% - %time%]: %xusername% >> %log%
- echo %xprog% Dose Not Exist >> %log%
- echo ---------- >> %log%
- pause
- exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement