|
-
Aug 30th, 2012, 09:26 AM
#1
Thread Starter
New Member
altering the registry
Hi,
I'm a java developer, but as of yesterday, it's expected of me to maintain and fix a massive VB prog. Anyway, I've been trying to run scripts to alter the registry. The code completes without error but the registries don't change. i found two paradigms to follow, but the result is the same in both cases. I'm using Access 2010 and VS 9.0.
Here is the method:
Code:
Private Function AllowWriting() As Boolean
Dim WshShell As Object
Set WshShell = CreateObject("WScript.Shell")
Dim oExec As Object
AllowWriting = False
If Me.TestDBBox.value = True Then
MsgBox "Proceeding with test database."
'EXECUTE ONE OR THE OTHER. IN EITHER CASE, REG DOESN'T CHANGE
' WshShell.Run "regedit /S C:\ListWizard\RatsDBRegistryEntries\RWWprod.reg", 1, True
' Set oExec = WshShell.Exec("regedit /S C:\ListWizard\RatsDBRegistryEntries\RWWdev.reg")
AllowWriting = True
ElseIf Me.TestDBBox.value = False Then
MsgBox "Proceeding with live database. Exercise judgement and discretion."
' WshShell.Run "regedit /S C:\ListWizard\RatsDBRegistryEntries\RWWprod.reg", 1, True
' Set oExec = WshShell.Exec("regedit /S C:\ListWizard\RatsDBRegistryEntries\RWWprod.reg")
AllowWriting = True
End If
End Function
Also, i tried numerous versions of this method:
Shell("C:\ListWizard\RatsDBRegistryEntries\RWWdev.reg", 1)
no matter what i put in the parameters, it throws a runtime error. But I think this Shell() is for .exe, so .reg will always fail, right?
Thank you
-
Aug 30th, 2012, 02:52 PM
#2
Hyperactive Member
Re: altering the registry
Code:
Imports Microsoft.Win32 'Needed to edit the registry.
'This line navigates to HKEY_CURRENT_USER\Control Panel\Desktop and changes the value of the Key "MYNEWVALUE" to "SomeValueIWantToSave"
'IF "MYNEWVALUE" does not exist it will be created.
Call Registry.SetValue("HKEY_CURRENT_USER\Control Panel\Desktop", "MYNEWVALUE", "SomeValueIWantToSave")
'The next two lines will delete the Key created above.
Dim toDel = My.Computer.Registry.CurrentUser.OpenSubKey("Control Panel\Desktop", True)
toDel.DeleteSubKey("MYNEWVALUE")
Last edited by Maverickz; Aug 30th, 2012 at 05:30 PM.
-
Aug 31st, 2012, 07:32 AM
#3
Thread Starter
New Member
Re: altering the registry
Thanks for your reply. Can't I just run the reg script? There is more than one thing I want to change.
Here is one of the scripts i want to run:
This is RWWdev.reg
Code:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\RWW\RaTS]
"ConnStr"="Provider=SQLOLEDB.1;Integrated Security=SSPI;Initial Catalog=RaTSTest;Data Source=sql1.realwinwin.local;"
"ConnStr2"="Provider=SQLOLEDB.1;Initial Catalog=RaTS;Data Source=sql1.realwinwin.local; Uid=rwwRaTS; pwd=RaTS1728;"
"CRPath"=""
"CRYear"="2010"
"CommandTimeout"=dword:00000014
"QB_Interface"=dword:00000001
"QB_TrustBankAccount"="TD Bank, Rebate Trust Acc"
"QB_TrustLiabilityAccount"="Rebate Trust, TD Bank"
[HKEY_LOCAL_MACHINE\SOFTWARE\RWW\RaTS\Project]
"TrackingNumber"="XXXXX"
"StatusId"=dword:00000007
"STCode"="WIPR"
"StatusReasonId"=dword:00000016
"SRCode"="NA"
"MilestoneId"=dword:00000001
"MSCode"="NEW"
"MSDescription"="Project Received by RWW"
"EstFUP"=dword:0000003c
"EstPFD"=dword:0000001e
"AutoDate"=dword:00000001
"EditComments"=dword:00000000
The file is a clickable. It prompts me if I want to change the registry, and after a confirmation, it makes the change.
When I execute this command: WshShell.Run "regedit C:\ListWizard\RatsDBRegistryEntries\RWWdev.reg", 1, True
The same prompt and confirmation occurs. But it doesn't actually change the registry. It says it is in the alert box, but it doesn't.
I don't want to code each one of these into the application. I just want to run this .reg file successfully!
thanks
-
Aug 31st, 2012, 09:56 AM
#4
Re: altering the registry
Don't use shell.... Use Process.Start ...
http://msdn.microsoft.com/en-us/libr....process.start
you'll probably want this specific one...
http://msdn.microsoft.com/en-us/library/h6ak8zt5
the first parameter would the be the app you want to run (regedit.exe) and the second would be commandline parameters to pass to it (/s someregfile.reg)
-tg
-
Aug 31st, 2012, 11:12 AM
#5
Re: altering the registry
This is all getting unnecessarily complicated. To run a .reg file it's ...
Process.Start(YourRegFilePathAndName)
That's it. Everything done.
As for values not 'registering', you did remember that some changes require you to log off and some restart Windows? If there's anything not in place after that then it's the .reg file which is at fault. If Windows said it merged the file then it merged the file.
-
Aug 31st, 2012, 12:15 PM
#6
Thread Starter
New Member
Re: altering the registry
Thank you all for you help. Problem solved!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|