Re: Adding a Key without overwriting what is already there

From: Torgeir Bakken \(MVP\) (Torgeir.Bakken-spam_at_hydro.com)
Date: 07/06/04


Date: Tue, 06 Jul 2004 22:34:00 +0200

Chris Kitzmann wrote:

> Today is a busy day huh?
>
> How about this one. Can I add the Group4 in a VB Script file.
> I do not have a Group with a key to read from like I did with
> the NumStartUp.
>
> Any Ideas?
>
> [HKEY_CURRENT_USER\SOFTWARE\Autodesk\AutoCAD\R15.0\ACAD-1:409\Profiles\<<Unnamed Profile>>\Menus]
>
> "Group1"="ACAD C:\\ACAD2000\\Support\\acad"
> "Group2"="BUTLER C:\\ACAD2000\\Support\\butler"
> "Group3"="EXPRESS \\\\Bmkc1alsol01\\acad2k\\acad2000\\EXPRESS\\acetmain"
>
> ADD THIS ->"Group4"="CUSTOMMENU C:\\ACAD2000\\Support\\custommenu1"
Hi

One way to do it (no check to see if CUSTOMMENU already exists, see
another version further below that do check and only update that
registry value instead of creating yet another registry entry):

'--------------------8<----------------------
Set oShell = CreateObject("WScript.Shell")

sRegValueName = "HKCU\Software\Autodesk\AutoCAD\R15.0\ACAD-1:409" _
                & "\Profiles\<<Unnamed Profile>>\Menus"

For iIndex = 1 To 100 ' support up to 100 group entries in registry

   sGroupValue = "" ' init value in case registry value does not exist
   On Error Resume Next
   sGroupValue = oShell.RegRead(sRegValueName & "\Group" & iIndex)
   On Error Goto 0
   If sGroupValue = "" Then
     oShell.RegWrite sRegValueName & "\Group" & iIndex, _
              "CUSTOMMENU C:\\ACAD2000\\Support\\custommenu1", "REG_SZ"
     Exit For ' finished, exit the loop
   End If

Next
'--------------------8<----------------------

Here is a version that checks to see if the CUSTOMMENU already exists
and update that registry value in that case. If no existing CUSTOMMENU
is found, a new registry entry is added:

'--------------------8<----------------------
Set oShell = CreateObject("WScript.Shell")

sRegValueName = "HKCU\Software\Autodesk\AutoCAD\R15.0\ACAD-1:409" _
                & "\Profiles\<<Unnamed Profile>>\Menus"

For iIndex = 1 To 100 ' support up to 100 group entries in registry

   sGroupValue = "" ' init value in case registry value does not exist
   On Error Resume Next
   sGroupValue = oShell.RegRead(sRegValueName & "\Group" & iIndex)
   On Error Goto 0

   If sGroupValue = "" Then
     oShell.RegWrite sRegValueName & "\Group" & iIndex, _
              "CUSTOMMENU C:\\ACAD2000\\Support\\custommenu1", "REG_SZ"
     Exit For ' finished, exit the Loop

   Elseif UCase(Left(sGroupValue, 11)) = UCase("CUSTOMMENU ") Then
     oShell.RegWrite sRegValueName & "\Group" & iIndex, _
              "CUSTOMMENU C:\\ACAD2000\\Support\\custommenu1", "REG_SZ"
     Exit For ' finished, exit the Loop

   End If

Next
'--------------------8<----------------------

-- 
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/community/scriptcenter/default.mspx


Relevant Pages

  • Re: Multiple computers
    ... strComputer = Trim ... ' Also trap error if you lack permission to create user. ... On Error GoTo 0 ... Microsoft MVP Scripting and ADSI ...
    (microsoft.public.windows.server.scripting)
  • Re: VBScript - Find the latest file in a folder
    ... For Each oFile In oFiles ... On Error Goto 0 ... DateDiff("n", dFileModDate, Now) and see it if returns more or less than 240 minutes. ... torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway ...
    (microsoft.public.scripting.wsh)
  • Re: getting mail adresses from all objects in an OU
    ... Dim strFilePath, objFSO, objFile, objConnection, objCommand, objRootDSE ... On Error GoTo 0 ... -- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: ...
    (microsoft.public.scripting.vbscript)
  • Re: Retrieve all userss e-mail address from AD with a script
    ... take a look at "Active Directory attributes" and "Tips on using ADO ... Dim strFilePath, objFSO, objFile, objConnection, objCommand, objRootDSE ... On Error GoTo 0 ... -- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: ...
    (microsoft.public.windows.server.scripting)
  • Re: english/german XP?
    ... > Language Options"? ... names and text in dialog boxes is in German. ... On Error Goto 0 ... -- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: ...
    (microsoft.public.windowsxp.configuration_manage)