Results 1 to 7 of 7

Thread: Reg import issue

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Posts
    195

    Reg import issue

    Hi,
    I had an issue with some code yesterday but have managed to get it working. The only issue I have with the code is the fact that the regimprt "file" section doesn't detect whether the file exists.

    I have got code at the top which detects if the folders exist and proceeds if so, but will fail if not. However I can't figure out how I can set this up with the reg import, Any ideaS?


    Code:
    Private Sub regimprt_a(RegFileName As String) ' BPFTP Registry Import
    
            wshell.Exec "regedit /s ""C:\Maintainer\BPFTP\Reg\" & RegFileName
    
    
    Private Sub cmdBPFTPRepair_Click()
    
    
            If objFSO.FileExists("C:\Maintainer\BPFTP\Default Settings\Default.bps") And objFSO.FolderExists("C:\Program Files\BPFTP\") Then
            objFSO.CopyFile "C:\Maintainer\BPFTP\Default Settings\Default.bps", "C:\Program Files\BPFTP\Default.bps", OverwriteExisting
            MsgBox "Files Copied", vbInformation + vbOKOnly, Me.Caption
            
            
            regimprt_a "CacheExpiry.reg"
            regimprt_a "EmailAddress.reg"
            regimprt_a "LogFileName.reg"
            regimprt_a "MaximumNumberRetries.reg"
            regimprt_a "RetryDelay.reg"
            regimprt_a "TimeoutSecs.reg"
            regimprt_a "Viewer.reg"
    
            Else
            MsgBox "Copy Failed", vbCritical + vbOKOnly, Me.Caption
        
            
            End If
    
    End Sub

  2. #2
    Addicted Member
    Join Date
    Oct 2006
    Location
    Chennai, India
    Posts
    198

    Re: Reg import issue

    You can very well use the FSO object to check the File existance before attempting to use the path in the Shell script.

    You cannot include this check in the parameters of the Shell command.
    Regards
    Srinivasan Baskaran
    India

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Posts
    195

    Re: Reg import issue

    So I can use FSO on "regedit /s ""C:\Maintainer\BPFTP\Reg\" & RegFileName to check the path?

    This didn't seem to work for me. The reason I need &RegFileName as I need to check all the files.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Posts
    195

    Re: Reg import issue

    I've now updated my code and managed to get it all working, only problem is that a message box will keep appearing several times (in this example it would appear 3 times).

    It seems like my program continues to run through each file and give an outcome for each.

    The code itself does the job just fine, I have also tested it by removing files from the folder and it will give the msgbox I expect, but its just the fact that I have message boxes appearing for all 3 files, which is quite annoying.

    I guess the ideal scenario would be to have the program stop if it detects a file missing.

    Trying to find the easyiest solution, hence it would be nice to keep this code.

    Anyways heres the code.

    Code:
    Private Sub regimprt_b(regfilename As String) 'Net Meeting Registry Import
     
    If objFSO.FileExists("C:\Maintainer\Video Stream\Reg\" & regfilename) Then
            wshell.Exec "regedit /s ""C:\Maintainer\Video Stream\Reg\" & regfilename
            'gets the .reg file name from cmdVideoStream.click
      MsgBox "passed", vbInformation + vbOKOnly, Me.Caption
    Else
        MsgBox "File(s) missing within C:\Maintainer\Video Stream\Reg\", vbCritical + vbOKOnly, Me.Caption
    End If
    End Sub
    
    Private Sub cmdVideoStream_Click()
    
            'calls regimprt_b sub and imports the files into the registry
            regimprt_b "Auto Accept Calls Disabled.reg"
            regimprt_b "Auto Mix.reg"
            regimprt_b "Calibrated Volume.reg"
    end sub
    Oh and I have tried & regfilename in the msgbox which shows which file is missing but i'ts not really a requirement.
    Last edited by jbennett; Feb 13th, 2008 at 12:45 PM.

  5. #5
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: Reg import issue

    Change the sub to a function, so you can get a return value ...... and something like this:
    vb Code:
    1. Private Function regimprt_b(regfilename As String) As Boolean
    2.    If objFSO.FileExists("C:\Maintainer\Video Stream\Reg\" & regfilename) Then
    3.       wShell.Exec "regedit /s ""C:\Maintainer\Video Stream\Reg\" & regfilename
    4.      
    5.       regimprt_b = True
    6.    
    7.    Else
    8.      
    9.       regimprt_b = False
    10.    
    11.    End If
    12. End Function
    13.  
    14. Private Sub cmdVideoStream_Click()
    15.    
    16.    If regimprt_b("Auto Accept Calls Disabled.reg") = False Then GoTo msgError
    17.    If regimprt_b("Auto Mix.reg") = False Then GoTo msgError
    18.    If regimprt_b("Calibrated Volume.reg") = False Then GoTo msgError
    19.    
    20.    MsgBox "passed", vbInformation + vbOKOnly, Me.Caption
    21.    
    22.    Exit Sub
    23. msgError:
    24.    MsgBox "File(s) missing within C:\Maintainer\Video Stream\Reg\", vbCritical + vbOKOnly, Me.Caption
    25.    Exit Sub
    26. End Sub

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Posts
    195

    Re: Reg import issue

    Thanks again for your help,
    I've actually found an easyier way of achieving this now.

    I have cut out the regimprt stuff and just run wshell on the regedit /s ""C:\location\something\import.reg

    I just merged all the reg files into one, therefore I can now refer to just the one file. Makes life so much easyier this way.

    I do have 1 question regarding this though. I currently have the code checking if the 2 locations exist.

    i'm wondering if its possible to check both locations seperately and display a msgbox with the location thats missing (if it is missing). Hope I make sense

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Posts
    195

    Re: Reg import issue

    oopppss forgot the code. Here it is: (and yes I have 2 different things going on here, 1 part is copying a file called Default.bps and the other part is importing the reg file)

    Code:
    Private Sub cmdBPFTPRepair_Click()
    
            If objFSO.FileExists("C:\Maintainer\BPFTP\Default.bps") And objFSO.FolderExists("C:\Program Files\BPFTP\") Then
            objFSO.CopyFile "C:\Maintainer\BPFTP\Default.bps", "C:\Program Files\BPFTP\Default.bps", OverwriteExisting
    
            End If
            If objFSO.FileExists("C:\Maintainer\BPFTP\Reg\bpftpImport.reg") Then
            wshell.Exec "regedit /s ""C:\Maintainer\BPFTP\Reg\bpftpImport.reg"
            MsgBox "Configuration Applied", vbInformation + vbOKOnly, Me.Caption
            
            Else
            MsgBox "Configuration Failed", vbCritical + vbOKOnly, Me.Caption
            End If
    
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width