Advertisement
npocmaka

StartHidden

Jan 22nd, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2. rem -- v.02 --
  3. setlocal
  4. if "%1" EQU "" (
  5.         echo starts a hidden process
  6.     echo by Vasil "npocmaka" Arnaudov
  7.     echo %~n0 path_to_executable
  8.     goto :eof
  9. )
  10.  
  11. if "%1" EQU "-help" (
  12.         echo starts a hidden process
  13.     echo by Vasil "npocmaka" Arnaudov
  14.     echo %~n0 path_to_executable
  15.     goto :eof
  16. )
  17.  
  18.  
  19. set executable=%~s1
  20. set inpath=%~dp$PATH:1
  21.  
  22.  
  23. ::the idea behind this ugly if is
  24. :: to get the path in 8.3 format because there are problems between
  25. :: SCHTASKS and spaces
  26.  
  27.  
  28.  
  29. if not exist %executable% (
  30.     if "%inpath%" equ "" (
  31.         echo path to executable item does not exist
  32.         exit /B 1      
  33.     ) else (
  34.         for %%f in ("%~dp$PATH:1%~1") do set executable=%%f
  35.     )
  36. )
  37.  
  38.  
  39.  
  40. ::getting the current time
  41. FOR /F "skip=1 tokens=1-3" %%A IN ('WMIC Path Win32_LocalTime Get Hour^,Minute^,Second /Format:table') DO (
  42.     SET /A hours=%%A > nul 2>&1
  43.     SET /A minutes=%%B > nul 2>&1
  44.     SET /A seconds=%%C > nul 2>&1  
  45. )
  46.  
  47. set /a time_stamp=%hours%%minutes%%seconds%
  48.  
  49. if "%time_stamp%" equ "" (
  50.     echo "some kind of error"
  51.     exit /B 2
  52. )
  53.  
  54.  
  55. SCHTASKS /Create /SC ONEVENT /EC Application /MO *[System/EventID=101] /TN start_at_%time_stamp%  /TR %executable%   /RU SYSTEM /F /RL HIGHEST
  56. eventcreate /ID 101 /T INFORMATION /D start_task
  57. SCHTASKS /Delete /TN start_at_%time_stamp% /f
  58. endlocal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement