Skip to content

Instantly share code, notes, and snippets.

@RedTahr
Last active August 29, 2015 14:23
Show Gist options
  • Save RedTahr/dcb1795490f9e942ec21 to your computer and use it in GitHub Desktop.
Save RedTahr/dcb1795490f9e942ec21 to your computer and use it in GitHub Desktop.
SmartCard PnP Disable
# Disable Smart Card PnP
# [x86]
# [HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\ScPnP]
# "EnableScPnP"=dword:00000000
# [64-bit]
# HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\ScPnP]
# "EnableScPnP"=dword:00000000
# this Wow6432Node entry is a "hardlink" to the above entry, so you create/delete/edit that and the changes are mirrored in Wow6432Node
# [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\ScPnP]
# "EnableScPnP"=dword:00000000
# http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/09/use-powershell-to-easily-create-new-registry-keys.aspx
# http://www.vistax64.com/powershell/265907-determine-32-bit-64-bit-os.html
# Windows 7 doesn't have PropertyType (powershell version 2 I think it was), but -Type DWORD works on Windows 8.1
$rootPath = "HKLM:\Software\Policies\Microsoft\Windows"
$fullPath = "HKLM:\Software\Policies\Microsoft\Windows\ScPnP"
#$rootWowPath = "HKLM:\Software\Wow6432Node\Policies\Microsoft\Windows"
#$fullWowPath = "HKLM:\Software\Wow6432Node\Policies\Microsoft\Windows\ScPnP"
# 1 for enabled, 0 for disabled
$value = "0"
$name = "EnableScPnP"
$directory = "ScPnP"
# Set-ExecutionPolicy Unrestricted
# http://stackoverflow.com/questions/7690994/powershell-running-a-command-as-administrator
if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments
break
}
if (Test-Path $fullPath) {
echo 'default registry path exists'
$exists = Get-ItemProperty -Path $fullPath -Name $name
if (($exists -ne $null) -and ($exists.Length -ne 0)) {
echo 'EnableScPnP property exists and its value is:'
(Get-ItemProperty -Path $fullPath -Name $name).$name
Set-ItemProperty -Path $fullPath -Name $name -Value $value
echo 'value set to:'
(Get-ItemProperty -Path $fullPath -Name $name).$name
}
else {
echo 'EnableScPnP property does not exist'
New-ItemProperty -Path $fullPath -Name $name -Value $value -Type DWORD -Force | Out-Null
}
}
else {
echo 'default registry path does not exist, attempting to force creation'
New-Item -Path $rootPath -Name $directory -Force -Type Directory
New-ItemProperty -Path $fullPath -Name $name -Value $value -Type DWORD -Force | Out-Null
}
Write-Host -NoNewLine "Press any key to continue..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
# Set-ExecutionPolicy Restricted
# this duplicate key under Wow6432Node is a "hardlink" or something to the key created above
<# if ($ENV:Processor_Architecture -eq 'x86' -and (test-path env:\PROCESSOR_ARCHITEW6432)) {
echo 'WOW layer 64 bit OS/32 bit process'
}
elseif ($ENV:Processor_Architecture -eq 'x86') {
echo '32 bit OS'
}
elseif ($ENV:Processor_Architecture -eq 'AMD64') {
echo '64 bit OS'
if (Test-Path $fullWowPath) {
echo 'wow registry path exists'
$wowExists = Get-ItemProperty -Path $fullWowPath -Name $name
if (($wowExists -ne $null) -and ($wowExists.Length -ne 0)) {
echo 'wow EnableScPnP property exists, and its value is:'
(Get-ItemProperty -Path $fullWowPath -Name $name).$name
Set-ItemProperty -Path $fullWowPath -Name $name -Value $value
echo 'value set to:'
(Get-ItemProperty -Path $fullWowPath -Name $name).$name
}
else {
echo 'wow EnableScPnP property does not exist'
#New-ItemProperty -Path $fullWowPath -Name $name -Value $value -Type DWORD -Force | Out-Null
}
}
else {
echo 'wow registry path does not exist, attempting to force creation'
New-Item -Path $rootWowPath -Name $directory -Force -Type Directory
#New-ItemProperty -Path $fullWowPath -Name $name -Value $value -Type DWORD -Force | Out-Null
}
}
else {
echo 'Unknown'
} #>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment