WAS command line

on Sunday, August 19, 2012

Just a reference for the WAS commands from the command line.

net stop was /y # stop was and w3svc/iis
net start was # start was
net start w3svc # start w3svc/iis


So, I found this tracking down an issue with using a shared config in a web farm. (Which is not the right way to configure a web farm.) http://technet.microsoft.com/en-us/library/cc735179(v=ws.10).aspx

appwiz.cpl for Server Core

on Tuesday, August 14, 2012

appwiz.cpl is the Add/Remove Programs dialog. On Windows Server Core the control panel is not available. Instead the wmic program can be used to gather the install list. The output from the command is pretty long, so it’s best to store it in a file and open it with notepad.

wmic product get > list.txt 
notepad list.txt


(http://technet.microsoft.com/en-us/magazine/dd630943.aspx)



Or, with powershell (if .NET 3.5.1 is installed)



gp HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select DisplayName, DisplayVersion, Publisher, InstallDate, HelpLink, UninstallString | ogv


(http://blogs.msdn.com/b/powershell/archive/2009/11/15/i-can-do-that-with-1-line-of-powershell-installed-software.aspx)

PowerShell Script for a WebFarm Server

on Sunday, August 5, 2012

I’m not sure where gbecerra got this script, but it is very nice. And, the reason it was posted on experts-exchange is because it was being executed in PowerShell ISE, which doesn’t support the *-Tracing commands (they are only supported from the command line on the host).

http://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/Q_26769992.html

The only slight improvement that was added to the script was implementing MS Knowledge Base issue 977754 (http://support.microsoft.com/kb/977754). For some odd reason, some of our servers had this problem.

########################## Implement KB977754 fix ##########################
# http://support.microsoft.com/kb/977754
Write-Host "Implementing KB977754 fix"

$kb977754Files = Get-Item $Env:ALLUSERSPROFILE\Microsoft\Crypto\RSA\MachineKeys\76944fb33636aeddb9590521c2e8815a_*
foreach($i in $kb977754Files) {
$acl = Get-Acl $i
$permissionSet = "NT AUTHORITY\LOCAL SERVICE",”Read”,”Allow”
$ar = New-Object  system.security.accesscontrol.filesystemaccessrule $permissionSet
$acl.SetAccessRule($ar)
Set-Acl $i $acl
}

PowerShell to setup Self-Signed SSL on a Website

on Sunday, July 29, 2012

This is pretty much a reprint of http://learn.iis.net/page.aspx/491/powershell-snap-in-configuring-ssl-with-the-iis-powershell-snap-in/

Import-Module WebAdministration

# Setup Certificate Data
$bdate = Get-Date -Format "MM/dd/yyyy"
$edate = ([DateTime]::Now).AddYears(50).ToString("MM/dd/yyyy")

$makecertPath = "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin"
$subject = "CN=www.local.mywebsite.com"

$ipAddress = "127.0.0.7"

# Make the Certificate
cd $makecertPath
./makecert.exe -r -pe -n "$subject" -b $bdate -e $edate -eku 1.3.6.1.5.5.7.3.1 -ss my -sr localMachine -sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12

# Get the Certificate for PowerShell
$cert = Get-ChildItem cert:\LocalMachine\My | Where-Object {$_.Subject -eq $subject} | Select-Object -First 1
$thumb = $cert.Thumbprint

# Add Certificate to Website
Set-Location IIS:\SslBindings
Get-Item cert:\LocalMachine\My\$thumb | New-Item $ipAddress!443


Resources:



[1] http://msdn.microsoft.com/en-us/library/bfsktky3.aspx (definition of makecert –sp & –sy)

Commands For Windows Server Core

on Sunday, July 22, 2012

This is a small collection of command line commands that make working with server core easier:

start cmd: open a new command prompt window

taskmgr: the classic command works

notepad: still works, as is always useful

shutdown –l: logoff the server

C:\Program Files\Microsoft Network Monitor 3\netmon.exe: If netmon is installed through the GUI setup, then the installer adds the directory to that path; which makes it even easier to run. But, if you use a command line quiet (/q) install, then you need to type out the whole path.

powershell:

Control VPN Connections Through IIS

on Sunday, July 15, 2012

Using IIS as a service provider, you can call Windows internal Rasdial system to connect, disconnect, and check the status of VPN connections.

Rasdial.exe (http://technet.microsoft.com/en-us/library/ff859533(v=ws.10)) is an internal program which Windows uses to create VPN connections. It’s command line interface can also be used to disconnect a connection or check what connections are currently active. This is a small wrapper website that calls Rasdial, in order to handle VPN connections from a remote location through http.

To set this up, you’ll need an ASP.NET MVC website, and a few changes. This example is using IIS 7.5, ASP.NET MVC 4, on .NET 4.5.

Once the basic ASP.NET MVC website is created, the updates are:

1) Change the Default route:

routes.MapRoute(
    name: "Default",
    url: "{action}/{id}",
    defaults: new { controller = "Vpn", action = "Disconnect", id = UrlParameter.Optional }
);

2) Add a VpnController for the default route to use:


using System;   
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Timers;
using System.Web;
using System.Web.Mvc;
namespace mpfiles.VpnReset.Controllers
{
    public class VpnController : Controller
    {
        private const string DefaultName = "vpn connection name";

        public ActionResult Disconnect(string name = DefaultName)
        {
            var arguments = string.Format("\"{0}\" /d", name);
            return HandleRasDial(arguments);
        }

        public ActionResult Connect(
            string name = DefaultName,
            string username = "username",
            string password = "password"
        ) {
            var arguments = string.Format("\"{0}\" {1} {2}", name, username, password);
            return HandleRasDial(arguments);
        }

        public ActionResult Status(string name = DefaultName)
        {
            return HandleRasDial(string.Empty);
        }

        public ActionResult HandleRasDial(string arguments)
        {
            var startTime = DateTime.Now;
            var message = RasDial(arguments);
            message = message.Replace("\n", "<br />");
            var endTime = DateTime.Now;
            message += "<br />" + String.Format("[{0}]", (endTime - startTime));

            return new ContentResult { Content = message };
        }

        public string RasDial(string arguments)
        {
            var proc = new Process();

            proc.StartInfo.FileName = "rasdial";
            proc.StartInfo.WorkingDirectory = HttpContext.Request.PhysicalApplicationPath;
            proc.StartInfo.Arguments = arguments;
            proc.StartInfo.RedirectStandardError = true;
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.UseShellExecute = false;
            proc.StartInfo.CreateNoWindow = true;
            proc.EnableRaisingEvents = false;

            proc.Start();
            var output = proc.StandardOutput.ReadToEnd();
            output += proc.StandardError.ReadToEnd();
            proc.WaitForExit();
            proc.Dispose();

            return output;
        }

    }
}



I hope someone else will find this useful.

Testing a local IIS website with a VM

on Friday, October 7, 2011

I had been putting off updating to IE9 for a while because 9’s “IE8 Mode” didn’t perfectly replicate IE8. Fortunately, a coworker pointed out that you can test out a local website using a VM.

I’m gonna use VirtualBox as the VM host software. I used an old copy of XP that I have lying around and updated it to IE8 (and security updates).

The virtual machine I created uses a NAT network interface. Most of the questions over on StackOverflow suggest using a Bridged interface, but I was having trouble getting that going.

Once you have the virtual machine up, all you have to do is edit your hosts file (C:\Windows\system32\drivers\etc) to map a dns address (eg. vmtest.local.mycomputer.com) to the local IP address of your machine (eg. 192.168.1.X).

image

As long as your local IIS instance uses host names to determine what the processing website is, then it will work.

image

Inside of your VM, you should now be able to type in the address and get a result.

image

With SSL certs it’s a little more tricky. You have to bind an SSL cert with an IP address. In this case, the only way to really do it is to bind the SSL cert either to ‘All Unassigned’ or to the actual IP address of the machine. If you already have a cert bound to ‘All Unassigned’ associated with any website it should just work.

image


Creative Commons License
This site was leeching Alex Gorbatchev's SyntaxHighlighter from Scott Hanselman's blog. UCSB is currently hosting the files.