Skip to content

Instantly share code, notes, and snippets.

@ivanrad
Created October 23, 2012 10:34
Show Gist options
  • Save ivanrad/83589625b2981016cd5d to your computer and use it in GitHub Desktop.
Save ivanrad/83589625b2981016cd5d to your computer and use it in GitHub Desktop.
Windows scripts
// set apm level on resume from hibernate/suspend
//
var apmcmd = "c:\\bin\\hdparm.exe -B 254 /dev/sda";
var shell = WScript.CreateObject("WScript.Shell");
shell.Run(apmcmd, 0);
var events = GetObject("winmgmts:").ExecNotificationQuery("Select * from Win32_PowerManagementEvent");
while (true) {
var e = events.NextEvent();
switch (e.EventType) {
case 7:
shell.Run(apmcmd, 0);
break;
default:
break;
}
}
@echo off
rem RunApplyMigration -- run all ApplyMigration.bat scripts found in the modification scripts subfolders that are under source control
rem ApplyMigration.bat script will not be run if it contains ApplyMigration.exclude file next to itself (the file is a text file that may contain a reason why that particular migration step is to be skipped)
if "%1"=="" goto usemsg
setlocal
set migration_script=ApplyMigration.bat
set migration_exclude=ApplyMigration.exclude
echo Running migration scripts located under root folder: %1
echo;
for /f "delims=$" %%i in ('tf dir %1 /folders^|sort^|findstr /r "^$[0-9]"') do (
if exist %%i\%migration_script% (
if not exist %%i\%migration_exclude% (
echo Begin: Executing %%i\%migration_script% [%DATE% %TIME%]
pushd %%i
call %migration_script%
popd
echo End: Executing %%i\%migration_script% [%DATE% %TIME%]
) else (
echo Excluding folder %%i -- %migration_exclude% file found.
type %%i\%migration_exclude%|findstr /v /i "^\s*rem"
echo;
)
)
)
endlocal
goto die
:usemsg
echo NOTE: this is a helper script, and is intended to be called by other scripts, you probably DO NOT need to run it by yourself!
echo;
echo usage: RunApplyMigration.bat [migration script folder]
echo;
:die
@echo off
SETLOCAL
if "%1" == "stop" set action=stop
if "%1" == "start" set action=start
if "%action%" == "" goto :usemsg
if "%2" == "trunk" goto :handletrunk
if "%2" == "rel" goto :handlerelease
goto :usemsg
:usemsg
echo usage: sql [stop^|start] [trunk^|rel]
goto :end
:handletrunk
if "%action%" == "stop" (
net stop mssqlserver /y
net stop MSSQLFDLauncher /y
rem net stop msftesql /y
rem sc stop sqlserveragent
rem sc stop msftesql
rem sc stop mssqlserver
) else if "%action%" == "start" (
net start mssqlserver
net start MSSQLFDLauncher
rem net start msftesql
rem sc start mssqlserver
rem sc start sqlserveragent
rem sc start msftesql
)
goto :end
:handlerelease
if "%action%" == "stop" (
net stop MSSQL$RELEASE /y
net stop MSSQLFDLauncher$RELEASE /y
rem net stop msftesql$RELEASE /y
rem sc stop sqlagent$RELEASE
rem sc stop msftesql$RELEASE
rem sc stop mssql$RELEASE
) else if "%action%" == "start" (
net start MSSQL$RELEASE
net start MSSQLFDLauncher$RELEASE
rem net start msftesql$RELEASE
rem sc start mssql$RELEASE
rem sc start sqlagent$RELEASE
rem sc start msftesql$RELEASE
)
goto :end
:end
ENDLOCAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment