Re: Adding a Key without overwriting what is already there
From: Torgeir Bakken \(MVP\) (Torgeir.Bakken-spam_at_hydro.com)
Date: 07/06/04
- Next message: Dave Patrick: "Re: KBA 306957"
- Previous message: Bob L.: "KBA 306957"
- In reply to: Chris Kitzmann: "Re: Adding a Key without overwriting what is already there"
- Next in thread: Chris Kitzmann: "Re: Adding a Key without overwriting what is already there"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: Dave Patrick: "Re: KBA 306957"
- Previous message: Bob L.: "KBA 306957"
- In reply to: Chris Kitzmann: "Re: Adding a Key without overwriting what is already there"
- Next in thread: Chris Kitzmann: "Re: Adding a Key without overwriting what is already there"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|