1iJaCk

cmdrc.bat

Aug 18th, 2016
220
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 9.47 KB | None | 0 0
  1. :: Params Check :::::::::::::::::::::::
  2. %*
  3. ::   If called with params,          ::
  4. ::   run those first                 ::
  5. ::                                   ::
  6. :::::::::::::::::::::::::::::::::::::::
  7.  
  8. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  9. ::   USE AT YOUR OWN RISK - Provided AS IS - no warrenty, no support, no guarntee    ::
  10. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  11. ::                                                                                   ::
  12. ::                 Alex V. | [email protected] | 08/31/2016 | Version: 1.0                 ::
  13. ::                   https://pastebin.com/raw/fxj75AQ0                               ::
  14. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  15.  
  16.  
  17. :: Default Prompt :::::::::::::::::::::
  18. ::   Sets Default Prompt value       ::
  19. ::                                      
  20. @set "_cmdrc=$_[$D] [$T$H$H$H] [%username%@%computername%] [$p$+]$_$g$g"
  21. :::::::::::::::::::::::::::::::::::::::
  22.  
  23.  
  24.  
  25. :: Run Check ::::::::::::::::::::::::::
  26. ::   If cmdrc has already been run   ::
  27. ::   it will not run it again        ::
  28. ::     Default 1.  If you want it to pull every time regardless, set to 0.
  29. ::
  30. @set /a "_cmdrc_init_counter+=1"
  31. @if "%_cmdrc_init_counter%" gtr "1" goto skip_config_pull
  32. :::::::::::::::::::::::::::::::::::::::
  33.  
  34.  
  35. :: Env Swap :::::::::::::::::::::::::::
  36. ::   Making sure that your session   ::
  37. ::   is least impacted by _cmdrc     ::
  38. ::
  39. @setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
  40. @echo off
  41.  
  42.  
  43.  
  44. :: User behavior changes ::::::::::::::
  45. set "_pause_flag="                      rem Default NOTSET. Pauses before giving completing this script
  46. set "_delay_flag="                      rem Default NOTSET. Pauses before giving completing this script
  47. set "_delay_value="                     rem Default 30.  If it is not set, it will default to 10
  48. set "_cmdrc_title=%username%@%computername%" rem Default Command Prompt - %username%@%computername%.  This is the base title string, other info will be appended
  49. :::::::::::::::::::::::::::::::::::::::
  50.  
  51.  
  52.  
  53. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  54. ::                                                                           ::
  55. :: Start of Script Functions                                                 ::
  56. ::   Run Function with the call command                                      ::
  57. ::                                                                           ::
  58. ::   Example:                                                                ::
  59. ::     call :function_name with params "and params with quotes"              ::
  60. ::                                                                           ::
  61. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  62. goto end_of_script_functions
  63.  
  64. :install_check
  65. goto :eof
  66.  
  67. :install_me
  68. :: Install Option :::::::::::::::::::::
  69. :: Add Context Menu, if needed:
  70. REM cmd_context_menu.reg:
  71.     REM Windows Registry Editor Version 5.00
  72.     REM
  73.     REM [HKEY_CLASSES_ROOT\Directory\shell\Open Normal Console here]
  74.     REM @="Open Normal Console here"
  75.     REM
  76.     REM [HKEY_CLASSES_ROOT\Directory\shell\Open Normal Console here\command]
  77.     REM @="title %1 && color 1a && cd /D %1"
  78.     REM
  79.     REM
  80.     REM [HKEY_CLASSES_ROOT\Directory\shell\Open Elevated Console here]
  81.     REM @="Open Elevated Console here"
  82.     REM
  83.     REM [HKEY_CLASSES_ROOT\Directory\shell\Open Elevated Console here\command]
  84.     REM @="C:\\Windows\\System32\\elevate.exe /K \"title %1 && color 1a && cd /D %1\""
  85.    
  86.    
  87.    
  88. :: reg add "HKEY_CLASSES_ROOT\Directory\shell\Open Elevated Console here" /v "@" /t
  89. :::::::::::::::::::::::::::::::::::::::
  90. goto :eof
  91.  
  92.  
  93. goto :eof
  94. :end_of_script_functions
  95. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  96. ::                                                                           ::
  97. :: End of Script Functions                                                   ::
  98. ::                                                                           ::
  99. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  100.  
  101.  
  102.  
  103. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  104. ::                                                                           ::
  105. :: Start of config pull                                                      ::
  106. ::   This should only happen once                                            ::
  107. ::                                                                           ::
  108. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  109.  
  110. :: Checking if this script has already been run in this console session
  111. ::
  112. if not defined _cmdrc_init_counter (
  113.     set /a "_cmdrc_init_counter+=1"
  114.     )
  115. :::::::::::::::::::::::::::::::::::::::
  116.  
  117.  
  118.    
  119. :: Print Bar ::::::::::::::::::::::::::
  120. echo/
  121. echo [=======] [CMDrc] [====================]
  122.  
  123.  
  124.  
  125. :: Get Processor info :::::::::::::::::
  126. ::
  127. if defined PROCESSOR_ARCHITEW6432 (
  128.     set "Proc_Mode=%PROCESSOR_ARCHITECTURE%[%PROCESSOR_ARCHITEW6432%]"
  129. ) else (
  130.     set "Proc_Mode=%PROCESSOR_ARCHITECTURE%"
  131. )
  132. :::::::::::::::::::::::::::::::::::::::
  133.  
  134.  
  135.  
  136. :: Network cable check ::::::::::::::::
  137. ::   Only works in Admin Console     ::
  138. ::  
  139. set "_cmdrc_no_network_connection="
  140. if defined _cmdrc_admin (
  141.     netsh interface show interface 2>nul | findstr "Connected" 2>&1>nul || set "_cmdrc_no_network_connection=true"
  142. )
  143. :::::::::::::::::::::::::::::::::::::::
  144.  
  145.  
  146.  
  147. :: Get external IP info :::::::::::::::
  148. ::   only if cable is connected      ::
  149. ::
  150. set "ip_ex_addr_all="
  151. if not defined _cmdrc_no_network_connection (
  152.     for /f "skip=1 tokens=2 delims=: " %%a in ('call nslookup myip.opendns.com. resolver1.opendns.com ^|findstr /i /C:"Address:"') do (
  153.         set "ip_ex_addr_all=%%a"
  154.     ) 2>&1>nul
  155. )
  156.  
  157. if defined ip_ex_addr_all (
  158.     echo External IP Addresses:
  159.     rem for /f "delims=," %%i in ('echo %ip_ex_addr_all%') do echo      %%i
  160.     for %%i in (%ip_ex_addr_all%) do echo         %%i
  161.     echo/
  162. )
  163.  
  164. if defined ip_ex_addr_all (
  165.     set "_cmdrc_title=%_cmdrc_title% Ext IPS:[%ip_ex_addr_all: =][%]"
  166. )
  167. :::::::::::::::::::::::::::::::::::::::
  168.  
  169.  
  170.  
  171. :: Get local IP info ::::::::::::::::::
  172. ::   Defining first three IPs        ::
  173. ::   Defining all local IPs          ::
  174. ::
  175. set /a count=0
  176. set "ip_addr="
  177. set "ip_lo_addr_all="
  178.  
  179. for /f "tokens=2 delims=:" %%a in ('ipconfig ^| findstr "IPv4"') do (
  180.     set "/a count+=1"
  181.     set "temp_ip_lo_addr=%%a"
  182.     if "!temp_ip_lo_addr:~0,1!" == " " (
  183.         set "temp_ip_lo_addr=!temp_ip_lo_addr:~1%!"
  184.     )
  185.  
  186.     if "!count!" leq "3" (
  187.         if not defined ip_addr (
  188.             set "ip_addr=!temp_ip_lo_addr!"
  189.             set "ip_lo_addr_all=!temp_ip_lo_addr!"
  190.         ) else (
  191.             set "ip_addr=!ip_addr! !temp_ip_lo_addr!"
  192.             set "ip_lo_addr_all=!ip_lo_addr_all! !temp_ip_lo_addr!"
  193.         )
  194.     ) else (
  195.         set "ip_lo_addr_all=!ip_lo_addr_all! !temp_ip_lo_addr!"
  196.     )
  197. )
  198.  
  199. :: Printing to console
  200. ::   Adding to Title String
  201. if defined ip_addr (
  202.     echo System IP Addresses:
  203.     for %%i in (%ip_lo_addr_all%) do echo         %%i
  204.     set "_cmdrc_title=%_cmdrc_title% Local IPS:[%ip_addr: =][%]"
  205. )
  206. :::::::::::::::::::::::::::::::::::::::
  207.  
  208.  
  209.  
  210. :CREATE_CONTEXT_MENUS
  211. if not defined _cmdrc_admin goto skip_CREATE_CONTEXT_MENUS
  212. :: TODO :: check registry
  213. :: TODO :: add if missing
  214.  
  215. :skip_CREATE_CONTEXT_MENUS
  216.  
  217.  
  218.  
  219. :: Pulling Console Encoding  ::::::::::
  220. ::   Prints the current              ::
  221. ::   console encoding type           ::
  222. ::
  223. set "chcp_current="
  224. for /f "tokens=2 delims=:" %%c in ('chcp') do set "chcp_current=%%c"
  225.  
  226. :: Scrubbing output
  227. if defined chcp_current (
  228.     if "%chcp_current:~0,1%" == " " (
  229.         set "chcp_current=%chcp_current:~1%"
  230.     )
  231. )
  232.  
  233. :: Printing to screen
  234. ::   If you need to change to UTF8, use this command - chcp 65001
  235. ::
  236.  
  237. ::   Human readable
  238. if "%chcp_current%" equ "437" (
  239.     set "_cmdrc_chcp_type=OEM - United States"
  240. )
  241. if "%chcp_current%" equ "65001" (
  242.     set "_cmdrc_chcp_type=UTF-8"
  243. )
  244.  
  245. if defined _cmdrc_chcp_type (
  246.     echo/
  247.     echo Console Encoding:
  248.     echo         %chcp_current% %_cmdrc_chcp_type%
  249. ) else (
  250.     echo/
  251.     echo Console Encoding:
  252.     echo         %chcp_current%
  253. )
  254. :::::::::::::::::::::::::::::::::::::::
  255.  
  256.  
  257.  
  258. :: Final Title set ::::::::::::::::::::
  259. ::   Does persist after endlocal     ::
  260. ::
  261. title %_cmdrc_title%
  262. :::::::::::::::::::::::::::::::::::::::
  263.  
  264. :: Print Bar ::::::::::::::::::::::::::
  265. echo [======================================]
  266.  
  267. :: If you wanted to pause or have the prompt delay before
  268. @if defined _pause_flag @echo/ && @echo CMDrc: INFO: Paused: Press any key to continue && @pause 2>&1>nul
  269. @if defined _delay_flag ( if defined _delay_value ( echo CMDrc: INFO: Delay [%_delay_value%] secs && timeout /t %_delay_value% ) else ( echo CMDrc: INFO: Delay [10] secs && timeout /t 10 ) )
  270.  
  271. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  272. ::                                                                           ::
  273. :: End of config pull                                                        ::
  274. ::   This should only happen once                                            ::
  275. ::                                                                           ::
  276. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  277.  
  278. @endlocal
  279.  
  280. :: Double-Triple checking to make sure that the PROMPT value was set properly
  281. @if not defined PROMPT set "PROMPT=%_cmdrc%"
  282.  
  283.  
  284. @echo on
  285. :skip_config_pull
  286.  
  287. :: Making sure that the prompt value is set
  288. @if not "%PROMPT:[]=%" == "%_cmdrc:[]=%" set "PROMPT=%_cmdrc%"
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment