Created
May 21, 2012 15:28
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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