Skip to content

Instantly share code, notes, and snippets.

@josheinstein
Created May 21, 2012 15:28
Show Gist options
  • Save josheinstein/2762914 to your computer and use it in GitHub Desktop.
Save josheinstein/2762914 to your computer and use it in GitHub Desktop.
SCoreShell - Windows Server Core PowerShell prompt at login with auto-logoff on exit
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
namespace SCoreShell
{
/// <summary>
/// This application's sole purpose in life is to sit in for the default "shell" on a
/// Windows Server Core installation and launch PowerShell instead of cmd.exe.
/// When the PowerShell instance is exited, the session is logged off in order to
/// prevent a shell-less session from being abandoned on the server.
/// </summary>
/// <remarks>
/// To register this program as the default shell for Windows Server Core, you must
/// point the following registry key to the location of ScoreShell.exe:
/// HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Shell (REG_SZ)
/// </remarks>
public static class Program
{
public static void Main( )
{
string pathSystem32 = Environment.GetFolderPath( Environment.SpecialFolder.System );
string pathPowerShell = Path.Combine( pathSystem32, "WindowsPowerShell", "v1.0", "powershell.exe" );
var psProcess = Process.Start( pathPowerShell );
psProcess.WaitForExit( );
ExitWindowsEx( 0x0, 0x0 );
}
[DllImport( "user32.dll" )]
private static extern bool ExitWindowsEx( uint uFlags, uint dwReason );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment