Solved

Problem writing to NT registry using WSHShell.RegWrite

Posted on 2001-07-24
7
284 Views
Last Modified: 2010-05-18
Hi, I use the following function to read and write to the system registry, and apply default values if requried. I need to access HKEY_LOCAL_MACHINE rather than USER for an NT application therefore could not use GetSetting etc.

This function works fine on Win2000 and all the Win98 machines I have tested it on. HOWEVER!!! on the clients pesky Windows NT machine there is NO entries in the registry !!! My function normally creates a node called OmniTerm but with this NT machine there is no entry. Very confused ! Yes, I am logged onto the machine as an administrator at both install and run time.

Any ideas ?

Stewart

Public Function Registry(VariableName As String, VariableValue As Variant, Writing As Boolean) As Variant
On Error Resume Next
Dim WSHShell As Object
Set WSHShell = CreateObject("WScript.Shell")
If Writing = True Then
'Write values:
  WSHShell.RegWrite "HKEY_LOCAL_MACHINE\Software\OmniTerm\"_ & Trim(VariableName), VariableValue
  Registry = ""
Else
'Read values:
 Registry = WSHShell.RegRead("HKEY_LOCAL_MACHINE\Software\OmniTerm\" & Trim_(VariableName))
' Set defaults, can be passed from calling code
  If Registry = Empty Then_ WSHShell.RegWrite "HKEY_LOCAL_MACHINE\Software\OmniTerm\"_ & VariableName, VariableValue: Registry = VariableValue
End If
Set WSHShell = Nothing
If Err Then Debug.Print Error$ 'Do not report, always_ err's if registry empty
End Function
0
Comment
Question by:nvms
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 8

Accepted Solution

by:
Dave_Greene earned 100 total points
ID: 6313224
How about giving this a shot, much easier :)

Dim sValue As String
dim KeyFound  as Boolean

Dim Reg As New Registry

Result = Reg.UpdateKey (HKEY_LOCAL_MACHINE, "Software\OmniTerm", "VariableName", "NEW VALUE")

sValue = ""

KeyFound = Reg.GetKeyValue(HKEY_LOCAL_MACHINE, _
  "Software\OmniTerm", "VariableName", sValue)

MsgBox sValue
0
 

Author Comment

by:nvms
ID: 6315470
Looks good so far except that:

Dim Reg As New Registry

must be referring to a class object or something because VB gives a large shrug when the line is reached...

Cheers !

Stewart
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6315476
what version of vb are you running?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:nvms
ID: 6320353
6.0 ... I was at the clients yesterday and noticed that wscript.exe was not in c:\winnt\system32 as it is on my W2K machine. Simply copying the file onto their machine made no difference. I wonder if it needed to be registered somehow ? Anyway, sort of worked around by using the GetSetting SaveSetting commands but now the registry settings change between users which is a main in the arm.

Cheers

Stewart
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6729042
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6743533
There has been no activity in this question in quite some time, and it looks like it has been abandoned. As part of our ongoing mission to clean up the topic areas, a Moderator will finalize this question within the next seven (7) days. At that time, either I or one of the other Moderators will force/accept the comment of Dave_Greene.

DO NOT ACCEPT THIS COMMENT AS AN ANSWER. If you have further comments on this question or the recommendation, please leave them here.

Thanks,

Netminder
Community Support Moderator
Experts Exchange
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6759799
nvms,

You last logged in on 1/14/2002, and you have disregarded our requests for you to clean up your open questions. I am therefore force/accepting a comment to close this question.

Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question