Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista Tutorial - Set empty default registry key value using regwrite ?

Reply
 
Old 06-11-2009   #1 (permalink)
Vilius Mockûnas
Guest


 
 

Set empty default registry key value using regwrite ?

Hello,

RegWrite vbscript function is a bit tricky to me. For example I want to
create registry key:

dim obj1
set obj1 = CreateObject( "WScript.Shell" )
obj1.RegWrite( "HKCU\Software\somekey\", 1, "REG_SZ" )

So OK example above creates somekey key with default value 1, but my goal
here is to set default value to empty value, not 1. (emty value is displayed
like "(value not set)" in regedit).

How do I set default key value to emty value using RegWrite ?

thanks
Vilius



My System SpecsSystem Spec
Old 06-11-2009   #2 (permalink)
Jon Wallace
Guest


 
 

Re: Set empty default registry key value using regwrite ?

Hi,

You could try setting a dummy value and then removing the dummy value
leaving the key behind - this works...

dim obj1
set obj1 = CreateObject( "WScript.Shell" )
obj1.RegWrite "HKCU\Software\somekey\dummyval", 1, "REG_SZ"
obj1.RegDelete "HKCU\Software\somekey\dummyval"

Thanks,
Jon

www.insidetheregistry.com

---

"Vilius Mockûnas" <v_mockunas@xxxxxx> wrote in message
news:e35YS6l6JHA.1372@xxxxxx
Quote:

> Hello,
>
> RegWrite vbscript function is a bit tricky to me. For example I want to
> create registry key:
>
> dim obj1
> set obj1 = CreateObject( "WScript.Shell" )
> obj1.RegWrite( "HKCU\Software\somekey\", 1, "REG_SZ" )
>
> So OK example above creates somekey key with default value 1, but my goal
> here is to set default value to empty value, not 1. (emty value is
> displayed like "(value not set)" in regedit).
>
> How do I set default key value to emty value using RegWrite ?
>
> thanks
> Vilius
>
>
My System SpecsSystem Spec
Old 06-11-2009   #3 (permalink)
Vilius Mockunas
Guest


 
 

Re: Set empty default registry key value using regwrite ?

Thanks for workaround.
This one also works as expected but I get TypeMismatch error:

obj1.RegWrite "HKCU\Software\somekey\", null, "REG_SZ"

Using with "on error resume next" it's OK.


V

"Jon Wallace" <info@xxxxxx> wrote in message
news:e$WSyCp6JHA.1372@xxxxxx
Quote:

> Hi,
>
> You could try setting a dummy value and then removing the dummy value
> leaving the key behind - this works...
>
> dim obj1
> set obj1 = CreateObject( "WScript.Shell" )
> obj1.RegWrite "HKCU\Software\somekey\dummyval", 1, "REG_SZ"
> obj1.RegDelete "HKCU\Software\somekey\dummyval"
>
> Thanks,
> Jon
>
> www.insidetheregistry.com
>
> ---
>
> "Vilius Mockûnas" <v_mockunas@xxxxxx> wrote in message
> news:e35YS6l6JHA.1372@xxxxxx
Quote:

>> Hello,
>>
>> RegWrite vbscript function is a bit tricky to me. For example I want to
>> create registry key:
>>
>> dim obj1
>> set obj1 = CreateObject( "WScript.Shell" )
>> obj1.RegWrite( "HKCU\Software\somekey\", 1, "REG_SZ" )
>>
>> So OK example above creates somekey key with default value 1, but my goal
>> here is to set default value to empty value, not 1. (emty value is
>> displayed like "(value not set)" in regedit).
>>
>> How do I set default key value to emty value using RegWrite ?
>>
>> thanks
>> Vilius
>>
>>
>

My System SpecsSystem Spec
Old 06-11-2009   #4 (permalink)
mayayana
Guest


 
 

Re: Set empty default registry key value using regwrite ?

There doesn't seem to be a way to just create
a key. You can just use:
obj1.RegWrite "HKCU\Software\somekey\", ""

It sets "" instead of [value not set], but so what?
That's the same thing in practice. If you even just
click "modify" in the context menu for a new key, the
default value will be set to "". Either way, RegRead
will return "". It's just a quirk.

(Also, the default value is string type by definition.
You're treating it as DWORD even though you
specified REG_SZ.)


The help is kind of strange for RegWrite. It says
the 2nd parameter is:

"The name of the new key you want to create, the name of the value you want
to add to an existing key, or the new value you want to assign to an
existing value-name."

I don't know of any way to name the new key with
the 2nd parameter. I also don't know of any way to
name the new value that way. The 2nd parameter is
the value data.
(To add to the confusion, the help even gets the
terminology wrong. Generally it's known as key, value
and data, whereas the scripting help refers to
"value-name" for value and "value" for data.)

Quote:

>
> RegWrite vbscript function is a bit tricky to me. For example I want to
> create registry key:
>
> dim obj1
> set obj1 = CreateObject( "WScript.Shell" )
> obj1.RegWrite( "HKCU\Software\somekey\", 1, "REG_SZ" )
>
> So OK example above creates somekey key with default value 1, but my goal
> here is to set default value to empty value, not 1. (emty value is
displayed
Quote:

> like "(value not set)" in regedit).
>
> How do I set default key value to emty value using RegWrite ?
>
> thanks
> Vilius
>
>

My System SpecsSystem Spec
Old 06-11-2009   #5 (permalink)
James Whitlow
Guest


 
 

Re: Set empty default registry key value using regwrite ?

"Vilius Mockûnas" <v_mockunas@xxxxxx> wrote in message
news:e35YS6l6JHA.1372@xxxxxx
Quote:

> Hello,
>
> RegWrite vbscript function is a bit tricky to me. For example I want to
> create registry key:
>
> dim obj1
> set obj1 = CreateObject( "WScript.Shell" )
> obj1.RegWrite( "HKCU\Software\somekey\", 1, "REG_SZ" )
>
> So OK example above creates somekey key with default value 1, but my goal
> here is to set default value to empty value, not 1. (emty value is
> displayed like "(value not set)" in regedit).
>
> How do I set default key value to emty value using RegWrite ?
As an alternative to 'RegWrite', you could use the WMI registry object.

Const HKCU = &H80000001
Set oReg = GetObject("WinMgmts:\root\default:StdRegProv")
oReg.CreateKey HKCU, "Software\somekey"


My System SpecsSystem Spec
Old 06-11-2009   #6 (permalink)
OldDog
Guest


 
 

Re: Set empty default registry key value using regwrite ?

On Jun 11, 1:33*am, "Vilius Mockûnas" <v_mocku...@xxxxxx> wrote:
Quote:

> Hello,
>
> RegWrite vbscript function is a bit tricky to me. For example I want to
> create registry key:
>
> dim obj1
> set obj1 = CreateObject( "WScript.Shell" )
> obj1.RegWrite( "HKCU\Software\somekey\", 1, "REG_SZ" )
>
> So OK example above creates somekey key with default value 1, but my goal
> here is to set default value to empty value, not 1. (emty value is displayed
> like "(value not set)" in regedit).
>
> How do I set default key value to emty value using RegWrite ?
>
> thanks
> Vilius
I set the value to a space;

obj1.RegWrite( "HKCU\Software\somekey\", " ", "REG_SZ" )

Seems to work for me.

OldDog
My System SpecsSystem Spec
Old 06-26-2009   #7 (permalink)
\Rems
Guest


 
 

Re: Set empty default registry key value using regwrite ?



"James Whitlow" wrote:
Quote:

> "Vilius Mockûnas" <v_mockunas@xxxxxx> wrote in message
> news:e35YS6l6JHA.1372@xxxxxx
Quote:

> > Hello,
> >
> > RegWrite vbscript function is a bit tricky to me. For example I want to
> > create registry key:
> >
> > dim obj1
> > set obj1 = CreateObject( "WScript.Shell" )
> > obj1.RegWrite( "HKCU\Software\somekey\", 1, "REG_SZ" )
> >
> > So OK example above creates somekey key with default value 1, but my goal
> > here is to set default value to empty value, not 1. (emty value is
> > displayed like "(value not set)" in regedit).
> >
> > How do I set default key value to emty value using RegWrite ?
>
> As an alternative to 'RegWrite', you could use the WMI registry object.
>
> Const HKCU = &H80000001
> Set oReg = GetObject("WinMgmts:\root\default:StdRegProv")
> oReg.CreateKey HKCU, "Software\somekey"
>
>
Or, also as an alternative to 'RegWrite':

obj1.run "reg add ""HKCU\Software\somekey""", 0,true


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
RegWrite Syntax VB Script
Set Your Default Programs - Empty Vista General
question about: vista default user profile & registry\shell issues Vista installation & setup
How do I operate on (default) property of Registry provider? PowerShell
How to see and change the value of (Default) in a registry key PowerShell


Vista Forums 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 Ltd

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