StdRegProv

来源:互联网 发布:人工智能猜密码 编辑:程序博客网 时间:2024/05/16 16:07

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.

HiveDecimal ValueHexidecimal ValueHKEY_CLASSES_ROOT21474836480x80000000HKEY_CURRENT_USER21474836490x80000001HKEY_LOCAL_MACHINE21474836500x80000002HKEY_USERS21474836510x80000003HKEY_CURRENT_CONFIG21474836530x80000005HKEY_DYN_DATA21474836540x80000006

 

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")

 

 

原创粉丝点击