Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Creating Registry-Keys with CreateSubKey-Method

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 10-09-2006   #1 (permalink)
Jens Schulze
Guest


 

Creating Registry-Keys with CreateSubKey-Method

Hello,
i have a little problem. I wish to create a Registry-Subkey and a value. I
am testing if the subkey exists, if not i get with Get-Item the parent Key
an use the methode CreateSubKey.
But i got an error. "In diesen Registrierungsschlüssel kann nicht
geschrieben werden", in englisch: "could not write in this Registry-Key".
But why? manual with regedit i can create the Key. I am logged in as admin.

Here ist my Code. To my mind it is correct.

$strSchluessel="HKLM:\SOFTWARE"

$strUSchluessel="MyTest"

$strWert="Test"

if ((Test-Path $strSchluessel) -eq $true)

{

#uebergeordneter Schluessel vorhanden

if ((Test-Path ($strSchluessel + $strUSchluessel)) -eq $false)

{

#untergeordneter Schluessel nicht vorhanden

#schluessel erstellen

$Schluessel=Get-Item $strSchluessel

echo $strUSchluessel

$USchluessel=$Schluessel.CreateSubKey($strUSchluessel)

echo "Schluessel erstellt!"

}

}


mfg Jens.



My System SpecsSystem Spec
Old 10-11-2006   #2 (permalink)
/\/\o\/\/ [MVP]
Guest


 

RE: Creating Registry-Keys with CreateSubKey-Method

standard the registry is opened Read-Only,
you can open it to write like this :

$Reg = Get-Item HKLM:
$Schluessel = $reg.OpenSubKey('SOFTWARE',$true)
$USchluessel=$Schluessel.CreateSubKey($strUSchluessel)
$USchluessel

gr /\/\o\/\/

More registry examples :

http://mow001.blogspot.com/2005/10/m...ry-access.html
http://mow001.blogspot.com/2005/10/startrdp-script.html


"Jens Schulze" wrote:

> Hello,
> i have a little problem. I wish to create a Registry-Subkey and a value. I
> am testing if the subkey exists, if not i get with Get-Item the parent Key
> an use the methode CreateSubKey.
> But i got an error. "In diesen Registrierungsschlüssel kann nicht
> geschrieben werden", in englisch: "could not write in this Registry-Key".
> But why? manual with regedit i can create the Key. I am logged in as admin.
>
> Here ist my Code. To my mind it is correct.
>
> $strSchluessel="HKLM:\SOFTWARE"
>
> $strUSchluessel="MyTest"
>
> $strWert="Test"
>
> if ((Test-Path $strSchluessel) -eq $true)
>
> {
>
> #uebergeordneter Schluessel vorhanden
>
> if ((Test-Path ($strSchluessel + $strUSchluessel)) -eq $false)
>
> {
>
> #untergeordneter Schluessel nicht vorhanden
>
> #schluessel erstellen
>
> $Schluessel=Get-Item $strSchluessel
>
> echo $strUSchluessel
>
> $USchluessel=$Schluessel.CreateSubKey($strUSchluessel)
>
> echo "Schluessel erstellt!"
>
> }
>
> }
>
>
> mfg Jens.
>
>
>

My System SpecsSystem Spec
Old 10-11-2006   #3 (permalink)
Alex K. Angelopoulos [MVP]
Guest


 

Re: Creating Registry-Keys with CreateSubKey-Method

As an alternative approach, you could also use driveless access, which
avoids both the Read-Only problem and the issue if that drive is not mapped
for some reason:

$strSchluessel = Get-Item
Microsoft.PowerShell.Core\Registry::hklm\software

"Jens Schulze" <webmaster@irgendwas.de> wrote in message
news:u3lllz96GHA.4232@TK2MSFTNGP02.phx.gbl...
> Hello,
> i have a little problem. I wish to create a Registry-Subkey and a value. I
> am testing if the subkey exists, if not i get with Get-Item the parent Key
> an use the methode CreateSubKey.
> But i got an error. "In diesen Registrierungsschlüssel kann nicht
> geschrieben werden", in englisch: "could not write in this Registry-Key".
> But why? manual with regedit i can create the Key. I am logged in as
> admin.
>
> Here ist my Code. To my mind it is correct.
>
> $strSchluessel="HKLM:\SOFTWARE"
>
> $strUSchluessel="MyTest"
>
> $strWert="Test"
>
> if ((Test-Path $strSchluessel) -eq $true)
>
> {
>
> #uebergeordneter Schluessel vorhanden
>
> if ((Test-Path ($strSchluessel + $strUSchluessel)) -eq $false)
>
> {
>
> #untergeordneter Schluessel nicht vorhanden
>
> #schluessel erstellen
>
> $Schluessel=Get-Item $strSchluessel
>
> echo $strUSchluessel
>
> $USchluessel=$Schluessel.CreateSubKey($strUSchluessel)
>
> echo "Schluessel erstellt!"
>
> }
>
> }
>
>
> mfg Jens.
>



My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Mcafee Registry Keys or other JustaUser VB Script 3 08-19-2008 05:11 PM
How to access the method of a registry key Seeker PowerShell 1 08-07-2008 12:41 PM
Unable to delete registry keys Art Vista General 3 12-04-2007 04:19 PM
BUG? Registry keys with / in names Roman Kuzmin PowerShell 9 09-04-2007 11:58 AM
Vista Registry Keys edde Vista General 3 02-19-2007 01:39 PM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51