Results 1 to 6 of 6

Thread: altering the registry

  1. #1
    New Member
    Join Date
    Aug 12
    Posts
    3

    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

  2. #2
    Addicted Member
    Join Date
    Sep 04
    Posts
    129

    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.

  3. #3
    New Member
    Join Date
    Aug 12
    Posts
    3

    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

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 02
    Posts
    21,655

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.*
    *Proof positive that searching the forums does work: View Thread *
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *
    * Use Offensive Programming, not Defensive Programming. * On Error Resume Next is error ignoring, not error handling(tm).
    "There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN

  5. #5
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,502

    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.

  6. #6
    New Member
    Join Date
    Aug 12
    Posts
    3

    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
  •