Thursday, 29 October 2009

All About Batch Files

I can't explain how much I love batch files. You can write your commands in a .bat file, then you can run them. It's great for automation which saves a lot of time.

Ok, what can you do with it?

Start Applications

SET fromFolder=C:\Projects\Beacon\v1.0\code

START %fromFolder%\BrokerService\bin\Debug\BeaconServer.BrokerService.exe

START http://localhost/BeaconClientService.WebUI/Default.aspx

Copy Files

SET fromFolder=C:\Projects\Beacon\v1.0\code

SET toFolder=D:\Projects\Beacon\v1.0\code

xcopy /E /Y %fromFolder% %toFolder%

Build Solutions

SET msBuildFolder= C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

CD %msBuildFolder%

SET rootFolder=C:\SharedFolder\Beacon\v1.0\code\

MSBUILD %rootFolder%BeaconClient\src\BeaconClient.sln

MSBUILD %rootFolder%BeaconServer\src\BeaconServer.sln


Start IE with a Specific Url

SET iexplore=C:\"Program Files"\"Internet Explorer"\IEXPLORE.EXE

SET url=

START %iexplore% %url%

Kill All IE Instances

taskkill /f /im iexplore.exe

Open Chrome in a New Window

start "Chrome" chrome --new-window

Start Chrome with 2 Specific Urls

SET appPath=C:\Users\[Username]\AppData\Local\Google\Chrome\Application\chrome.exe

START %appPath%

Empty a File
To empty any file, such as .log, .txt, .cs, you can use the following command:

set filePath1=FolderName\filename.log
type NUL > %filePath1%

Reset IIS

Kill Current Web Server Processes

Taskkill /IM WebDev.WebServer40.EXE /F

Kill Chrome

Taskkill /IM WebDev.WebServer40.EXE /F

Build and Publish a Solution

msbuild C:\\AppFolder\AppProject.csproj /p:DeployOnBuild=true /p:PublishProfile=C:\\AppFolder\Properties\PublishProfiles\localhost.pubxml /p:VisualStudioVersion=12.0

Delete a File

DEL c:\folder\filename.sql

SVN Get Latest

CD C:\Program Files\TortoiseSVN\bin\

START TortoiseProc.exe /command:update /path:"C:\Svn\mediacenter\" /closeonend:1


No comments: