Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for nostartskype.bat

(view source code of nostartskype.bat as plain text)

  1. @ECHO OFF
  2. ECHO.
  3. ECHO NoStartSkype.bat,  Version 1.01 for Windows 7 and later
  4. ECHO Disable Skype to start when Windows starts, reenforce after Skype updates
  5. ECHO.
  6. ECHO Usage:  NOSTARTSKYPE.BAT
  7. ECHO.
  8. ECHO Notes:  This batch file has to be run only once on the computer, with
  9. ECHO         elevated privileges.
  10. ECHO         The batch file uses a temporary XML file to create a Scheduled
  11. ECHO         task, which in turn will delete Skype's autostart entry in the
  12. ECHO         registry at each logon and at each workstation lock event.
  13. ECHO         Return code ^("ErrorLevel"^) 0 if all seems to go well, 1 for
  14. ECHO         invalid command line arguments, 2 if a restart with elevated
  15. ECHO         privileges was required.
  16. ECHO.
  17. ECHO Written by Rob van der Woude
  18. ECHO http://www.robvanderwoude.com
  19. ECHO.
  20. ECHO.
  21.  
  22. IF "%~1"=="" (
  23. 	REM Check if running with elevated privileges
  24. 	WHOAMI /Groups 2>NUL | FIND "12288" >NUL
  25. 	IF ERRORLEVEL 1 (
  26. 		REM Create a temporary script to restart the batch file with elevated privileges
  27. 		>  "%Temp%.\%~n0.vbs" ECHO Set UAC = CreateObject^( "Shell.Application" ^)
  28. 		>> "%Temp%.\%~n0.vbs" ECHO UAC.ShellExecute "%~s0", "", "", "runas", 1
  29. 		REM Restart the batch file with elevated privileges
  30. 		CSCRIPT.EXE //NoLogo "%Temp%.\%~n0.vbs"
  31. 		EXIT /B 2
  32. 	)
  33. 	SLEEP 5 >NUL 2>&1
  34. 	REM Delete temporary script if it exists
  35. 	IF EXIST "%Temp%.\%~n0.vbs" DEL "%Temp%.\%~n0.vbs"
  36. ) ELSE (
  37. 	EXIT /B 1
  38. )
  39.  
  40. SETLOCAL
  41.  
  42. REM Use WMIC to capture task creation time
  43. FOR /F "tokens=*" %%A IN ('WMIC Path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Year /Format:Value ^| FIND "="') DO (
  44. 	FOR /F "tokens=1* delims==" %%B IN ("%%~A") DO (
  45. 		SET %%~B=0%%~C
  46. 	)
  47. )
  48.  
  49. REM Create (Unicode) XML file to import scheduled task from
  50. SET XML="%Temp%.\%~n0.xml"
  51. IF EXIST %XML% DEL %XML%
  52. >  %XML% ECHO ^<?xml version="1.0" encoding="UTF-16"?^>
  53. >> %XML% ECHO ^<Task version="1.3" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"^>
  54. >> %XML% ECHO   ^<RegistrationInfo^>
  55. >> %XML% ECHO     ^<Date^>%Year:~1%-%Month:~-2,2%-%Day:~-2,2%T%Hour:~-2,2%:%Minute:~-2,2%:00.000^</Date^>
  56. >> %XML% ECHO     ^<Author^>%UserDomain%\%UserName%^</Author^>
  57. >> %XML% ECHO   ^</RegistrationInfo^>
  58. >> %XML% ECHO   ^<Triggers^>
  59. >> %XML% ECHO     ^<SessionStateChangeTrigger^>
  60. >> %XML% ECHO       ^<Enabled^>true^</Enabled^>
  61. >> %XML% ECHO       ^<StateChange^>SessionLock^</StateChange^>
  62. >> %XML% ECHO     ^</SessionStateChangeTrigger^>
  63. >> %XML% ECHO     ^<LogonTrigger^>
  64. >> %XML% ECHO       ^<Enabled^>true^</Enabled^>
  65. >> %XML% ECHO     ^</LogonTrigger^>
  66. >> %XML% ECHO   ^</Triggers^>
  67. >> %XML% ECHO   ^<Principals^>
  68. >> %XML% ECHO     ^<Principal id="Author"^>
  69. >> %XML% ECHO       ^<UserId^>%UserDomain%\%UserName%^</UserId^>
  70. >> %XML% ECHO       ^<LogonType^>InteractiveToken^</LogonType^>
  71. >> %XML% ECHO       ^<RunLevel^>HighestAvailable^</RunLevel^>
  72. >> %XML% ECHO     ^</Principal^>
  73. >> %XML% ECHO   ^</Principals^>
  74. >> %XML% ECHO   ^<Settings^>
  75. >> %XML% ECHO     ^<MultipleInstancesPolicy^>IgnoreNew^</MultipleInstancesPolicy^>
  76. >> %XML% ECHO     ^<DisallowStartIfOnBatteries^>false^</DisallowStartIfOnBatteries^>
  77. >> %XML% ECHO     ^<StopIfGoingOnBatteries^>true^</StopIfGoingOnBatteries^>
  78. >> %XML% ECHO     ^<AllowHardTerminate^>true^</AllowHardTerminate^>
  79. >> %XML% ECHO     ^<StartWhenAvailable^>false^</StartWhenAvailable^>
  80. >> %XML% ECHO     ^<RunOnlyIfNetworkAvailable^>false^</RunOnlyIfNetworkAvailable^>
  81. >> %XML% ECHO     ^<IdleSettings^>
  82. >> %XML% ECHO       ^<StopOnIdleEnd^>true^</StopOnIdleEnd^>
  83. >> %XML% ECHO       ^<RestartOnIdle^>false^</RestartOnIdle^>
  84. >> %XML% ECHO     ^</IdleSettings^>
  85. >> %XML% ECHO     ^<AllowStartOnDemand^>true^</AllowStartOnDemand^>
  86. >> %XML% ECHO     ^<Enabled^>true^</Enabled^>
  87. >> %XML% ECHO     ^<Hidden^>true^</Hidden^>
  88. >> %XML% ECHO     ^<RunOnlyIfIdle^>false^</RunOnlyIfIdle^>
  89. >> %XML% ECHO     ^<DisallowStartOnRemoteAppSession^>false^</DisallowStartOnRemoteAppSession^>
  90. >> %XML% ECHO     ^<UseUnifiedSchedulingEngine^>false^</UseUnifiedSchedulingEngine^>
  91. >> %XML% ECHO     ^<WakeToRun^>false^</WakeToRun^>
  92. >> %XML% ECHO     ^<ExecutionTimeLimit^>PT1H^</ExecutionTimeLimit^>
  93. >> %XML% ECHO     ^<Priority^>7^</Priority^>
  94. >> %XML% ECHO     ^<RestartOnFailure^>
  95. >> %XML% ECHO       ^<Interval^>PT5M^</Interval^>
  96. >> %XML% ECHO       ^<Count^>3^</Count^>
  97. >> %XML% ECHO     ^</RestartOnFailure^>
  98. >> %XML% ECHO   ^</Settings^>
  99. >> %XML% ECHO   ^<Actions Context="Author"^>
  100. >> %XML% ECHO     ^<Exec^>
  101. >> %XML% ECHO       ^<Command^>REG.EXE^</Command^>
  102. >> %XML% ECHO       ^<Arguments^>Delete "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run" /V Skype /F^</Arguments^>
  103. >> %XML% ECHO     ^</Exec^>
  104. >> %XML% ECHO   ^</Actions^>
  105. >> %XML% ECHO ^</Task^>
  106.  
  107. REM Delete the task if it already exists
  108. SCHTASKS /Query /TN "%~n0" >NUL 2>&1 && SCHTASKS /Delete /TN "%~n0" /F >NUL 2>&1
  109.  
  110. REM Create the task by importing the XML we just created
  111. SCHTASKS /Create /TN "%~n0" /XML %XML%
  112.  
  113. REM Delete the temporary XML file
  114. IF EXIST %XML% DEL %XML%
  115.  
  116. ENDLOCAL
  117. EXIT /B 0
  118.  

page last modified: 2024-04-16; loaded in 0.0110 seconds