I have a script changes some snmp community settings on our servers.
It deletes the existing key, creates a new one and populates it with
our new traps. Only problem is that when it creates the new key, the
default vaule looks wrong. It gets assigned a value instead of the (no
value).. its not causing any issues, but was wondering if anyone found
better syntax than what I am using to create a new key.. Here is the
line and below it I posted the whole script


'recreate the key
WshShell.RegWrite
"HKLM\system\currentcontrolset\services\snmp\parameters\trapconfiguration\delltrap\",
1, "REG_SZ"




Whole script

On Error Resume Next

'set the traps.
value1 = "blah"
value2 = "blah2"
value3 = "blah3"
value4 = "blah4"



'create the scripting object
Set WshShell = WScript.CreateObject("WScript.Shell")

'delete the existing key
WshShell.RegDelete
"HKLM\system\currentcontrolset\services\snmp\parameters\trapconfiguration\delltrap\"

'recreate the key
WshShell.RegWrite
"HKLM\system\currentcontrolset\services\snmp\parameters\trapconfiguration\delltrap\",
1, "REG_SZ"




WshShell.RegWrite
"HKLM\system\currentcontrolset\services\snmp\parameters\trapconfiguration\delltrap\1",value1
WshShell.RegWrite
"HKLM\system\currentcontrolset\services\snmp\parameters\trapconfiguration\delltrap\2",Value2
WshShell.RegWrite
"HKLM\system\currentcontrolset\services\snmp\parameters\trapconfiguration\delltrap\3",Value3
WshShell.RegWrite
"HKLM\system\currentcontrolset\services\snmp\parameters\trapconfiguration\delltrap\4",Value4

Re: Creating new reg key, but default value is messed up. by Jase

Jase
Tue Aug 15 14:39:06 CDT 2006

The WScript.Shell object isn't the best tool to just create keys. For
that, you might want to look into using the WMI StdRegProv class as in
this example:

Const HKEY_LOCAL_MACHINE = &H80000002
Const RegPath = "hive\key\subkey"
Set
objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\def
ault:StdRegProv")
RetVal = objReg.CreateKey(HKEY_LOCAL_MACHINE, RegPath)
If RetVal = 0 Then WScript.Echo "Created" Else WScript.Echo "Failed: "
& RetVal

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/
wmi/createkey_method_in_class_stdregprov.asp

Re: Creating new reg key, but default value is messed up. by Greg

Greg
Tue Aug 15 14:47:48 CDT 2006

masg2 when you create a registry key it forces a default value of
"REG_SZ". Perhaps im missunderstanding you but it sounds like you would
like to dump a blank value into the registry, which you can't do. Also
if you definatly want to make sure your imputting the correct value.
Perhaps you want a double instead of an expanded string.

-Greg


masg2 wrote:
> I have a script changes some snmp community settings on our servers.
> It deletes the existing key, creates a new one and populates it with
> our new traps. Only problem is that when it creates the new key, the
> default vaule looks wrong. It gets assigned a value instead of the (no
> value).. its not causing any issues, but was wondering if anyone found
> better syntax than what I am using to create a new key.. Here is the
> line and below it I posted the whole script
>
>
> 'recreate the key
> WshShell.RegWrite
> "HKLM\system\currentcontrolset\services\snmp\parameters\trapconfiguration\delltrap\",
> 1, "REG_SZ"
>
>
>
>
> Whole script
>
> On Error Resume Next
>
> 'set the traps.
> value1 = "blah"
> value2 = "blah2"
> value3 = "blah3"
> value4 = "blah4"
>
>
>
> 'create the scripting object
> Set WshShell = WScript.CreateObject("WScript.Shell")
>
> 'delete the existing key
> WshShell.RegDelete
> "HKLM\system\currentcontrolset\services\snmp\parameters\trapconfiguration\delltrap\"
>
> 'recreate the key
> WshShell.RegWrite
> "HKLM\system\currentcontrolset\services\snmp\parameters\trapconfiguration\delltrap\",
> 1, "REG_SZ"
>
>
>
>
> WshShell.RegWrite
> "HKLM\system\currentcontrolset\services\snmp\parameters\trapconfiguration\delltrap\1",value1
> WshShell.RegWrite
> "HKLM\system\currentcontrolset\services\snmp\parameters\trapconfiguration\delltrap\2",Value2
> WshShell.RegWrite
> "HKLM\system\currentcontrolset\services\snmp\parameters\trapconfiguration\delltrap\3",Value3
> WshShell.RegWrite
> "HKLM\system\currentcontrolset\services\snmp\parameters\trapconfiguration\delltrap\4",Value4