1/15/11

ASP.NET MVC 3 - Project Template for Visual Studio 2010

References
Microsoft.CSharp
System
System.Core
System.Web
System.Web.Helpers
System.Web.Mvc
System.Web.Routing
System.Web.Services
System.Web.WebPages

Folders
controllers
js
models
properties
ux
views
views\home
views\shared

Files
controllers\homeController.cs
demo.csproj
demo.csproj.user
global.asax
global.asax.cs
js\alert.js
properties\assemblyInfo.cs
ux\style.css
views\_viewStart.cshtml
views\home\default.cshtml
views\shared\error.cshtml
views\shared\_layout.cshtml
views\web.config
web.config
web.debug.config
web.release.config

controllers\homeController.cs
using System.Web.Mvc;

namespace Demo.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Default()
        {
            ViewBag.Message = "ViewBag.Message, set in HomeController";

            return View();
        }
    }
}

demo.csproj
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion></ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{A8C1B3E9-6897-4456-A450-2662343B9E6F}</ProjectGuid>
    <ProjectTypeGuids>{E53F8FEA-EAE0-44A6-8774-FFD645390401};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>properties</AppDesignerFolder>
    <RootNamespace>Demo</RootNamespace>
    <AssemblyName>demo</AssemblyName>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <MvcBuildViews>false</MvcBuildViews>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <PublishDatabases>false</PublishDatabases>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Web" />
    <Reference Include="System.Web.Helpers" />
    <Reference Include="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
    <Reference Include="System.Web.Routing" />
    <Reference Include="System.Web.Services" />
    <Reference Include="System.Web.WebPages" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="global.asax.cs">
      <DependentUpon>global.asax</DependentUpon>
    </Compile>
    <Compile Include="properties\assemblyInfo.cs" />
    <Compile Include="controllers\homeController.cs" />
  </ItemGroup>
  <ItemGroup>
    <Content Include="global.asax" />
    <Content Include="js\alert.js" />
    <Content Include="ux\style.css" />
    <Content Include="views\_viewStart.cshtml" />
    <Content Include="views\home\default.cshtml" />
    <Content Include="views\shared\_layout.cshtml" />
    <Content Include="views\shared\error.cshtml" />
    <Content Include="views\web.config" />
    <Content Include="web.config" />
    <Content Include="web.Debug.config">
      <DependentUpon>web.config</DependentUpon>
    </Content>
    <Content Include="web.Release.config">
      <DependentUpon>web.config</DependentUpon>
    </Content>
  </ItemGroup>
  <ItemGroup>
    <Folder Include="models\" />
  </ItemGroup>
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target> -->
  <Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
    <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
  </Target>
  <ProjectExtensions>
    <VisualStudio>
      <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
        <WebProjectProperties>
          <UseIIS>False</UseIIS>
          <AutoAssignPort>True</AutoAssignPort>
          <DevelopmentServerPort>1234</DevelopmentServerPort>
          <DevelopmentServerVPath>/</DevelopmentServerVPath>
          <IISUrl></IISUrl>
          <NTLMAuthentication>False</NTLMAuthentication>
          <UseCustomServer>True</UseCustomServer>
          <CustomServerUrl>http://dev.mvcdemo.com/</CustomServerUrl>
          <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
        </WebProjectProperties>
      </FlavorProperties>
    </VisualStudio>
  </ProjectExtensions>
</Project>

demo.csproj.user
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <ProjectView>ShowAllFiles</ProjectView>
  </PropertyGroup>
  <ProjectExtensions>
    <VisualStudio>
      <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
        <WebProjectProperties>
          <StartPageUrl></StartPageUrl>
          <StartAction>NoStartPage</StartAction>
          <AspNetDebugging>True</AspNetDebugging>
          <SilverlightDebugging>False</SilverlightDebugging>
          <NativeDebugging>False</NativeDebugging>
          <SQLDebugging>False</SQLDebugging>
          <ExternalProgram></ExternalProgram>
          <StartExternalURL></StartExternalURL>
          <StartCmdLineArguments></StartCmdLineArguments>
          <StartWorkingDirectory></StartWorkingDirectory>
          <EnableENC>False</EnableENC>
          <AlwaysStartWebServerOnDebug>True</AlwaysStartWebServerOnDebug>
        </WebProjectProperties>
      </FlavorProperties>
    </VisualStudio>
  </ProjectExtensions>
</Project>

global.asax
<%@ Application Codebehind="global.asax.cs" Inherits="Demo.MvcApplication" Language="C#" %>

global.asax.cs
using System.Web.Mvc;
using System.Web.Routing;

namespace Demo
{
    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "default",                     // Route name
                "{controller}/{action}/{id}",  // URL with parameters
                new { controller = "Home",     // Parameter defaults
                      action     = "Default", 
                      id         = UrlParameter.Optional }
            );
        }

        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }
    }
}

js\alert.js
//<script src="/js/alert.js" type="text/javascript"></script>
alert("/js/alert.js");

properties\assemblyInfo.cs
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: AssemblyTitle("MVC Demo")]
[assembly: AssemblyCompany("Expression Software")]
[assembly: ComVisible(false)]
[assembly: Guid("28bf9b70-c4f2-4007-986f-5598dd52dfa8")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

ux\style.css
body{
background:#000;
color:#fff;
font-family:Verdana, Arial, Helvetica, Sans-Serif;
}

views\_viewStart.cshtml
@*file: \views\_viewStart.cshtml
  desc: common view code, executed at the start of View render
*@

@{
    //set default layout
    Layout = "~/views/shared/_layout.cshtml";
}

views\home\default.cshtml
@{
    ViewBag.PageTitle = null;  //breakpoint
    ViewBag.PageTitle += "MVC Demo";
}

@*html body - view source for line breaks & whitespace*@
<h1>@ViewBag.PageTitle</h1>
ViewBag.PageTitle: @ViewBag.PageTitle<br />
ViewBag.Message: @ViewBag.Message

views\shared\error.cshtml
@{
    Layout = null;
}
<!doctype html>
<html>
<head>
  <title>Error</title>
  <meta charset=utf-8>
</head>
<body>
  error...
</body>
</html>

views\shared\_layout.cshtml
<!doctype html>
<html>
<head>
  <title>@ViewBag.PageTitle - Expression Software</title>
  <meta charset=utf-8>
  <link href="/ux/style.css" rel="stylesheet" type="text/css" />
  <!--<script src="/js/alert.js" type="text/javascript"></script>-->
</head>
<body>
  @RenderBody()

  <br />------------------------<br />
  @DateTime.Now.ToString("MM-dd-yy HH:mm:ss:fff")

  <br />------------------------
  @foreach(var x in new [] {0,1,2})
  {
      ;<br />@x;  //use leading semicolon to prevent generating extra, collapsed, whitespace
  }
</body>
</html>

views\web.config
<?xml version="1.0"?>
<configuration>
  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>

  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

  <appSettings>
    <add key="webpages:Enabled" value="false" />
  </appSettings>

  <system.web>
    <httpHandlers>
      <add path="*" verb="*" type="System.Web.HttpNotFoundHandler" />
    </httpHandlers>

    <!-- Enabling request validation in view pages would cause validation to occur after the input has already been processed by the controller.
         By default MVC performs request validation before a controller processes the input. 
         To change this behavior apply the ValidateInputAttribute to a controller or action. -->
    <pages
        validateRequest="false"
        pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <controls>
        <add tagPrefix="mvc" namespace="System.Web.Mvc" assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </controls>
    </pages>
  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />

    <handlers>
      <remove name="BlockViewHandler" />
      <add name="BlockViewHandler" 
           path="*" verb="*"
           preCondition="integratedMode" 
           type="System.Web.HttpNotFoundHandler" />
    </handlers>
  </system.webServer>
</configuration>

web.config
<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="ClientValidationEnabled" value="true"/> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true"/> 
  </appSettings>

  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
    </compilation>

    <authentication mode="None" />

    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages"/>
      </namespaces>
    </pages>
  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

web.debug.config
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
</configuration>

web.release.config
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
  </system.web>
</configuration>



1/12/11

Using External JavaScript Files with Google Analytics

For basic page tracking, put the code in an external file.

Then you can use this
<script src="/js/googleAnalytics.js" type="text/javascript"></script>

instead of
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _gaq.push(['_trackPageview']);
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>

Add to files, right before the closing head tag.


googleAnalytics.js
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);
(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

12/30/10

Happy New Year!

Translations by Google Translate API.

LanguageTranslationPhonetic Pronunciation
AfrikaansVoorspoedige Nuwe Jaar!
AlbanianGëzuar Vitin e Ri!
Arabicسنة جديدة سعيدة
ArmenianՇնորհավոր Նոր ՏարիShnorhavor Nor Tari
BelarusianЗ Новым годам!Z Novym hodam!
BulgarianЧестита Нова Година!Chestita Nova Godina!
CatalanFeliç Any Nou!
Chinese Simplified新年快乐Xīnnián kuàilè!
Chinese Traditional新年快樂Xīnnián kuàilè!
CroatianSretna Nova Godina!
CzechŠťastný Nový Rok!
DanishGodt Nytår!
DutchGelukkig Nieuw Jaar!
EstonianHead uut Aastat!
FilipinoMasaya Bagong Taon!
FinnishHyvää Uutta Vuotta!
FrenchJoyeux Nouvel An!
GalicianFeliz Ano!
GermanGlückliches Neues Jahr!
GreekΕυτυχισμένο το Νέο Έτος!Ef̱tychisméno to Néo Étos
Haitian CreoleKontan Ane Nouvo!
Hebrewשנה טובה
Hindiनया साल मुबारक हो!Nayā sāla mubāraka hō!
HungarianBoldog Új Évet!
IcelandicGleðilegt Nýtt Ár!
IndonesianSelamat Tahun Baru!
IrishAthbhliain faoi mhaise daoibh!
ItalianFelice Anno Nuovo!
Japanese明けましておめでとうございますAkemashite omedetōgozaimasu
Korean새해 복 많이saehae bog manh-i
LatvianLaimīgu Jauno gadu!
LithuanianLaimingų Naujųjų Metų!
MacedonianСреќна Нова Година!Sreḱna Nova Godina!
MalaySelamat Tahun Baru!
MalteseSena l-ġdida Kuntenti!
NorwegianGodt Nytt År!
Persianرسید سال نوی خوشی
PolishSzczęśliwego Nowego Roku!
PortugueseFeliz Ano Novo!
RomanianAn Nou Fericit!
RussianС Новым годом!S Novym godom!
SerbianСрећна Нова година!Srećna Nova godina!
SlovakŠťastný Nový Rok!
SlovenianSrečno novo leto!
SpanishFeliz Año Nuevo!
SwahiliFuraha ya Mwaka Mpya!
SwedishGott Nytt År!
Thaiสวัสดีปีใหม่S̄wạs̄dī pī h̄ım̀
TurkishMutlu yıllar!
UkrainianЗ Новим роком!Z Novym rokom!
VietnameseChúc mừng năm mới
WelshBlwyddyn Newydd Dda!
Yiddishגליקלעך ניו יאָר

12/5/10

SQL Server Command Line Utility - SqlCmd

http://msdn.microsoft.com/en-us/library/ms162773.aspx
path: c:\program files\microsoft sql server\100\tools\binn\sqlcmd.exe

powershell examples
- execute command-line query, connect using SQL Server Authentication
  &sqlcmd -S SERVER -d DB -U LOGIN -P 'PASSWORD' -q 'select getdate()'

- execute command-line query, connect using SQL Server Authentication, password prompt
  &sqlcmd -S SERVER -d DB -U LOGIN -q 'select getdate()'

- execute command-line query, connect using Windows Authentication
  &sqlcmd -S SERVER -d DB -E -q 'select getdate()'
    
- execute sql script file
  &sqlcmd -S SERVER -d DB -E -i x:\sql\script1.sql

- execute all sql script files in a folder
  gci x:\sql\ *.* | %{ &sqlcmd -S SERVER -d DB -E -i $_.fullname }
  
- exit or quit

- command-line options
  [-? show syntax summary]
  [-a packetsize]
  [-A dedicated admin connection]
  [-b On error batch abort]
  [-c cmdend]
  [-C Trust Server Certificate]
  [-d use database name]
  [-e echo input]
  [-E trusted connection]
  [-f <codepage> | i:<codepage>[,o:<codepage>]]
  [-h headers]
  [-H hostname]
  [-i inputfile]
  [-I Enable Quoted Identifiers]
  [-k[1|2] remove[replace] control characters]
  [-l login timeout]
  [-L[c] list servers[clean output]]
  [-m errorlevel]
  [-N Encrypt Connection]
  [-o outputfile]
  [-p[1] print statistics[colon format]]
  [-P password]
  [-q "cmdline query"]
  [-Q "cmdline query" and exit]
  [-r[0|1] msgs to stderr]
  [-R use client regional setting]
  [-s colseparator]
  [-S server]
  [-t query timeout]
  [-u unicode output]
  [-U login id]
  [-v var = "value"...]
  [-V severitylevel]
  [-w screen width]
  [-W remove trailing spaces]
  [-x disable variable substitution]
  [-X[1] disable commands, startup script, enviroment variables [and exit]]
  [-y variable length type display width]
  [-Y fixed length type display width]
  [-z new password]
  [-Z new password and exit]

11/15/10

PInvoke SetWindowText PowerShell Script

P/Invoke examples for the SetWindowText Windows API Function.
These examples set the window text/title for Notepad.exe.
#get notepad window handle
$notepad = get-process notepad
$notepad.mainWindowHandle //100000, intptr structure

$pinvoke::setWindowText($notepad.mainWindowHandle, "a")

#auto-convert int to intptr
$pinvoke::setWindowText(100000, "b")

#create intptr
#out-null to suppress bool result
$pinvoke::setWindowText((new-object intPtr(100000)), "c") | out-null

$pinvoke::setWindowTextCustomWrapper(100000)

Implementation #1 simply exposes the SetWindowText method, the member definition uses C# syntax.
$pinvoke = add-type -name pinvoke -passThru -memberDefinition @'

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool SetWindowText(IntPtr hwnd, String lpString);

'@

Implementation #2, same as #1 but written on one line.
$pinvoke = add-type -name pinvoke -passThru -memberDefinition '[DllImport("user32.dll", CharSet = CharSet.Auto)]public static extern bool SetWindowText(IntPtr hwnd, String lpString);'

Implementation #3, SetWindowText is private, add custom wrapper method.
$pinvoke = add-type -name pinvoke -passThru -memberDefinition @'

[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern bool SetWindowText(IntPtr hwnd, String lpString);

public static void SetWindowTextCustomWrapper(IntPtr handle)
{
string customText = string.Format("handle: {0}", handle);
SetWindowText(handle, customText);
}

'@


11/3/10

Git Custom Difftool Configuration

Original solution by David Tchepak: Setting up Git difftool on Windows

This example shows the configuration for ExamDiff Pro.
Tested on Windows 7 and msysgit version 1.7.3.1

1. Set the path environment variable to include "c:\program files\git\cmd\;"
2. Create a shell script wrapper file, note the forward slashes in the executable path
#c:\program files\git\cmd\diff.sh
#!/bin/sh
"c:/program files/examdiff pro/examdiff.exe" "$1" "$2" | cat

3. Edit the .gitconfig file
#c:\users\john\.gitconfig
[diff]
tool = examdiff

[difftool "examdiff"]
cmd = diff.sh "$LOCAL" "$REMOTE"
...

4. Verify it works, run the difftool command: git difftool --no-prompt


Setting Windows Path Environment Variable with PowerShell

#get all environment vars
gi env:
(gi env:) | sort name

#get path value
gi env:path
(gi env:path).value
(gi env:path).value.split(';')
(gi env:path).value.split(';') | sort

#set path value (note the "$" prefix)
$env:path = 'c:\windows;c:\windows\system32;'