+ Post New Thread
Results 1 to 7 of 7
Scripts Thread, [help] Script to regsvr32 ocx files in set directory(s) in Coding and Web Development; I've been having a bit of a mare with 2 simple stuff of late and not quite managed to work ...
  1. #1
    contink's Avatar
    Join Date
    Jul 2006
    Location
    South Yorkshire
    Posts
    3,791
    Thank Post
    303
    Thanked 327 Times in 233 Posts
    Rep Power
    118

    [help] Script to regsvr32 ocx files in set directory(s)

    I've been having a bit of a mare with 2 simple stuff of late and not quite managed to work out the cause but a solution seems to be to run the cmd regsvr32.exe on each of the ocx files in set directories. For some reason this fixes the problem.

    Anyways, rather than manually go through locating each ocx and running the command I figured there has to be a simple way to use VBS to locate an OCX in a specific folder and then run the cmd thus automating the process.

    Anyone done anything like this or can suggest a link/resource that does something similar?

  2. #2

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,156
    Thank Post
    116
    Thanked 529 Times in 452 Posts
    Blog Entries
    2
    Rep Power
    124

    Re: [help] Script to regsvr32 ocx files in set directory(s)

    Add this to the machine startup script (needs to be machine not user - user won't have rights to register OCXs)

    Code:
    sFolder="<foldername>"
    set oShell=createobject("wscript.shell")
    set ofso=createobject("scripting.filesystemobject")
    if not ofso.fileexists sFolder & "\ocxregistered.ok" then 
      set oFolder=ofso.getfolder(sFolder)
      for each oFile in oFolder.files
        sName=lcase(ofile.name)
        if right(sname,3)="ocx" then
         sCmd="regsvr32 /s " & sFolder & "\" & sName
        oShell.run sCmd,,true
        end if
      next
    else
      set oFile=ofso.createtextfile(sFolder & "\ocxregistered.ok")
      oFile.writeline now
      oFile.close
    end if
    Put the folder name in place of <foldername> at the top.

    The "ocxregistered.ok" is just so that you don't run this every time - won't harm but is unnecessary and slows things down.

  3. #3

    Join Date
    Feb 2006
    Posts
    1,187
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Re: [help] Script to regsvr32 ocx files in set directory(s)

    Or you could do this
    Code:
     FOR /R "<folder name>" %f IN (*.OCX) DO regsvr32 /S "%f"
    and put the kettele on

  4. #4
    contink's Avatar
    Join Date
    Jul 2006
    Location
    South Yorkshire
    Posts
    3,791
    Thank Post
    303
    Thanked 327 Times in 233 Posts
    Rep Power
    118

    Re: [help] Script to regsvr32 ocx files in set directory(s)

    Perfect... thanks for those two suggestions

    I'll have to do a little tweaking so it goes through a bunch of folders but that's simple enough with an array and a loop..

    Kettle time it is...

  5. #5
    contink's Avatar
    Join Date
    Jul 2006
    Location
    South Yorkshire
    Posts
    3,791
    Thank Post
    303
    Thanked 327 Times in 233 Posts
    Rep Power
    118

    Re: [help] Script to regsvr32 ocx files in set directory(s)

    Had a play with this to resolve some syntax errors and make it a little more versatile so that it runs through subfolders too...

    Code:
    '*********************************************
    '*	Fix_ocx_reg.vbs
    '*
    '*	$Author: martin $
    '*	$Date: 2007-06-14 22:09:31 +0100 (Thu, 14 Jun 2007) $
    '*	$Revision: 13 $
    '*
    '*********************************************
    
    ' Script to regsvr32.exe missing OCX
    ' 
    
    
    Set oShell=createobject("wscript.shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    Set objFolder = objFSO.GetFolder("C:\program files\2Simple")
    
    
    ShowSubfolders objFSO.GetFolder(objFolder)
    
    
    Sub ShowSubFolders(Folder)
    
        For Each objSubfolder in Folder.SubFolders
        
        	If Not objFSO.fileExists(objSubfolder.Path & "\ocxregistered.ok") Then
        		Set objFolder=objFSO.getfolder(objSubfolder.Name)
        		
        		sFoundOCX = False
        		
        		For Each objFile in oFolder.files
    					sName=lcase(objFile.name)
    					If Right(sName,3)="ocx" Then
    						sCmd="regsvr32 /s " And objSubfolder.Path & "\" & sName
    						oShell.run sCmd,,True
    						sFoundOCX = True
    					End If
    				Next
    				
    				If sFoundOCX = True Then
    					Set oFile=objFSO.createtextfile(objSubfolder.Path & "\ocxregistered.ok")
    					oFile.writeline now
    					oFile.close
    				End If
    				
            ' Wscript.Echo Subfolder.Path
            ShowSubFolders Subfolder
          End If
          
        Next
        
    End Sub
    In this instance it's set to go through any 2Simple programs and sort out unregistered OCX controls but it's easy enough to tailor it to your needs by re-editing the line:
    Code:
    Set objFolder = objFSO.GetFolder("C:\program files\2Simple")
    One thing it doesn't do though is check the root folder for any OCX files but that should be an easy fix for anyone who needs it..

  6. #6

    Join Date
    Jan 2006
    Location
    Surburbia
    Posts
    2,178
    Thank Post
    74
    Thanked 307 Times in 243 Posts
    Rep Power
    115

    Re: [help] Script to regsvr32 ocx files in set directory(s)

    Mmm.. but couldn't you have put the kettle on again and used NGs (recursive) one-liner? Maybe you needed script, otherwise the latter definitely looks like uhh.. appropriate technology.

  7. #7
    contink's Avatar
    Join Date
    Jul 2006
    Location
    South Yorkshire
    Posts
    3,791
    Thank Post
    303
    Thanked 327 Times in 233 Posts
    Rep Power
    118

    Re: [help] Script to regsvr32 ocx files in set directory(s)

    Quote Originally Posted by PiqueABoo
    Mmm.. but couldn't you have put the kettle on again and used NGs (recursive) one-liner? Maybe you needed script, otherwise the latter definitely looks like uhh.. appropriate technology.
    What can I say... I'm a glutton for punishment

SHARE:
+ Post New Thread

Similar Threads

  1. Active Directory-Script for Creating Bulk Users
    By calapso in forum How do you do....it?
    Replies: 8
    Last Post: 14th January 2009, 06:32 PM
  2. script for active directory
    By chalkwellstu in forum Scripts
    Replies: 8
    Last Post: 24th September 2007, 01:53 PM
  3. Script to set active directory object security
    By meastaugh1 in forum Windows
    Replies: 4
    Last Post: 5th January 2007, 04:28 AM
  4. Replies: 19
    Last Post: 20th June 2006, 03:53 PM
  5. Loading .reg files in a startup script
    By Ric_ in forum Windows
    Replies: 7
    Last Post: 27th September 2005, 04:23 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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