StdRegProv

原创 2012年03月21日 12:09:48

The StdRegProv class contains methods that manipulate system registry keys and values.

To check all the methods that are available from the class StdRegProv:
$Reg = [WMIClass]"root\default:stdRegProv"
$Reg | Get-Member

 

Registry keys are classified into six different categories (hives) identified by the following unique registry hive constants. You need these unique numbers to access the right keys and their values.

Hive Decimal Value Hexidecimal Value
HKEY_CLASSES_ROOT 2147483648 0x80000000
HKEY_CURRENT_USER 2147483649 0x80000001
HKEY_LOCAL_MACHINE 2147483650 0x80000002
HKEY_USERS 2147483651 0x80000003
HKEY_CURRENT_CONFIG 2147483653 0x80000005
HKEY_DYN_DATA 2147483654 0x80000006

 

To get a list of service names listed as subkeys under the SYSTEM\CurrentControlSet\Services key in the HKEY LOCAL MACHINE registry hive:

$Reg = [WMIClass]"root\default:stdRegProv"
$HKEY_LOCAL_MACHINE = 2147483650 $strKeyPath = "SYSTEM\CurrentControlSet\Services"
$services=$Reg.EnumKey($HKEY_LOCAL_MACHINE,$strKeyPath)
$services.sNames

 

To query certain information about SQL Server, such as what network libraries are installed and whether they are enabled(value=1):

$Reg = [WMIClass]"root\default:stdRegProv"
$HKEY_LOCAL_MACHINE = 2147483650
$strKeyPath = "SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQLServer\SuperSocketNetLib"
$netlib=$Reg.EnumKey($HKEY_LOCAL_MACHINE,$strKeyPath)
$netlib.sNames | Foreach-Object { $_ + "=" +
$Reg.GetDWORDValue($HKEY_LOCAL_MACHINE,$strKeyPath+'\'+ $_,"Enabled").uValue}

 

To obtain all the values under the Named Pipes registry key:

$Reg = [WMIClass]"root\default:stdRegProv"
$HKEY_LOCAL_MACHINE = 2147483650
$strKeyPath = "SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQLServer\SuperSocketNetLib\Np"
$namedpipe=$Reg.EnumValues($HKEY_LOCAL_MACHINE,$strKeyPath)
$namedpipe.sNames

 

The name of the named pipe and the TCP/IP port number are of type REG SZ, which is a string. You can obtain them with the GetStringValue method using the following commands:
$Reg = [WMIClass]"root\default:stdRegProv"
$HKEY_LOCAL_MACHINE = 2147483650
$strKeyPath = "SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQLServer\SuperSocketNetLib\Np"
$pipeName=$reg.GetStringValue($HKEY_LOCAL_MACHINE,$strKeyPath,"Pipename").svalue
$pipeName
$strKeyPath = "SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQLServer\SuperSocketNetLib\Tcp\IPAll"
$TcpPort=$reg.GetStringValue($HKEY_LOCAL_MACHINE,$strKeyPath,"TcpPort").svalue
$TcpPort

 

To create a new value name and value data under SOFTWARE\Microsoft\MSSQLServer\MSSQLServer\SuperSocketNetLib\Np in the registry:

$HKEY_LOCAL_MACHINE = 2147483650
$Reg = [WMIClass]"root\default:stdRegProv"
$strKeyPath = "SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQLServer\SuperSocketNetLib\Np"
$strValueName = "TestValueName"
$strValue = "TestValue"
$Reg.CreateKey($HKEY_LOCAL_MACHINE,$strKeyPath)
$Reg.SetStringValue($HKEY_LOCAL_MACHINE,$strKeyPath,$strValueName,$strValue)
$Reg.GetStringValue($HKEY_LOCAL_MACHINE,$strKeyPath,"TestValueName").svalue

 

To delete this key, use the DeleteValue method:
$Reg.DeleteValue($HKEY_LOCAL_MACHINE, $strKeyPath, "TestValueName")

 

 

相关文章推荐

WMI 中 root/DEFAULT/StdRegProv 的使用例程

StdRegProv的读写注册表时的使用方法。(纯粹自己看自己用)

StdRegProv类所属方法的使用(之六)

13)        SetStringValue 为指定键值名称的键值设置键值类型为REG_SZ的键值数值。这种方法是最简单最常用的方法。 uint32 SetStringValue(  ...
  • lxfmq0
  • lxfmq0
  • 2011年08月15日 10:29
  • 910

StdRegProv类所属方法的使用(之三)

(04)        GetBinaryValue 返回键值类型为REG_BINARY的指定键值名称的键值数值。         uint32 GetBinaryValue(   [in, o...
  • lxfmq0
  • lxfmq0
  • 2011年08月15日 10:25
  • 861

StdRegProv类所属方法的使用(之二)

(02)        EnumValues 列举给定子键的键值名称和键值类型。如果没有改变过,总是返回子键的默认键值,如果数据是空则返回空串("")。 uint32 EnumValues( ...
  • lxfmq0
  • lxfmq0
  • 2011年08月15日 10:24
  • 873
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:StdRegProv
举报原因:
原因补充:

(最多只允许输入30个字)