header image

Creating Registry Key

Posted by: | November 20, 2015 Comments Off on Creating Registry Key |

I had a question left on the blog asking how to create a registry key. My preferred method is to use the CIM class = StdRegProv. Its a static class so you don’t need to create an object


[uint32]$hklm = 2147483650
$newkey = ‘SOFTWARE\NewKey’

Invoke-CimMethod -ClassName StdRegProv -MethodName CreateKey -Arguments @{hDefKey = $hklm; sSubKeyName = $newkey}


Define the variables for the HIVE in this case HKLM – local machine .  Notice that the value has to be an unsigned integer.


The key you want to create is just the path to the key. if you need to create multiple levels of subkeys they will all create from a single path.


Then use Invoke-CimMethod to call the CreateKey method on StdRegProv. The hash table in Arguments parameter has the method parameter names and appropriate  values.


If everything works you’ll get a return value of 0.


How did I know which parameters the method took?


I used Get-CimClass but that’s a story for another post.

under: PowerShell and CIM, PowerShell and WMI

Comments are closed.