::::::::: PowerShell :::::::::
Friday, January 13, 2006
  [MSH] Change Default "Get-Credential" Prompt Behavior
/\/\o\/\/ has pointed out that the default prompt mode for "get-content" in Monad Beta 3 is through "CredUI", meaning, if you type "get-content" in Monad Beta 3,
you will see one of these familiar Windows Credential UI:

Image hosted by Photobucket.com

According to Abhishek Agrawal on Usenet post,

The default implementation for get-credential now uses the Windows CredUI
functionality for collecting credentials. This is a requirement for being
complaint with Windows Common Criteria. We still retain the console mode
which can be enabled by setting the registry key "ConsolePrompting" under
HLKM:\SOFTWARE\Microsoft\MSH\1\ShellIds to "True" (string)


Ah, now, i go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSH\1\ShellIds(Well, I can see that Registry structure has been modified slightly from pre-Beta 3 version of Monad), you won't see a registry key named "ConsolePrompting". You can simply create that key and set the value to whichever mode you set the value of key to. I prefer "GUI" mode so mine is set to "false". But i just want to switch between two modes easily so created the following script that will simply change the prompt mode with a simple function(SetConsoleCredPrompt).


MSH> SetConsoleCredPrompt
Your Credential Prompting Mode has been changed to "Console" Mode.
MSH> SetConsoleCredPrompt($false)
Your Credential Prompting Mode has been changed to "Gui" Mode.


SetConsoleCredPrompt simply navigates to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSH\1\ShellIds and then change the value of "ConsolePrompt" to "true" or "false".

This is one of the advantage of knowing how to script... I don't have to do much manually by having to open up the registry editor, navigate to the right path and change the key(BTW, isn't Registry Provider just awesome or what?).

Well the source? Nothing interesting about it...

# author: DBMwS
# date: 01/12/2005 @ 11:14 PM
# description: "Get-Credential" prompting method between "console" and "CredUI"
# note: Works only for Beta 3 of Monad
function SetConsoleCredPrompt() {
# default is $private:false since in Monad Beta 3, CredUI is the default way to
# prompt end-user for entering username and password
# But should i throw an Exception here or not... That's the problem...
param([bool] $ConsoleMode = $private:true)

# Ready for the unexpected...(such as running this script for non beta 3 version of Monad
trap { Write-Host "Some Unknown error has occurred, Aborting Mission..."; return; }

# MSH Beta 3 ShellID
$private:path = [string] "HKLM:\SOFTWARE\Microsoft\MSH\1\ShellIds"
# A new key name to create.
$private:key = [string] "ConsolePrompting"

# Check if the location we need to reach exists or not, else abort the script
if (test-path $private:path) {
set-property $private:path -Property $private:key -Type String -Value $ConsoleMode.ToString()
} else {
throw "Could not find Registry Path($($private:path)) to change Creditial Prompt Setting`nMaybe you are running pre-beta3 MSH?"
}

Write-host -n "Your Credential Prompting Mode has been changed to `""
if($ConsoleMode) { Write-host -n -f "red" "Console" } else { Write-Host -n -f "green" "Gui" }
Write-host "`" Mode."
}



Tags :
 
Comments:
tanks
 
Post a Comment



<< Home
Let's get lazy with PowerShell!

Name:
Location: Flushing, NY, United States

Experimenting with a different format of blogs...

Links
ARCHIVES
10/01/2005 - 11/01/2005 / 11/01/2005 - 12/01/2005 / 12/01/2005 - 01/01/2006 / 01/01/2006 - 02/01/2006 / 02/01/2006 - 03/01/2006 / 03/01/2006 - 04/01/2006 / 04/01/2006 - 05/01/2006 / 05/01/2006 - 06/01/2006 / 06/01/2006 - 07/01/2006 / 07/01/2006 - 08/01/2006 / 08/01/2006 - 09/01/2006 / 10/01/2006 - 11/01/2006 / 11/01/2006 - 12/01/2006 /


Powered by Blogger