Jump to content

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


Recommended Posts

Posted

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?

Posted

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

 

sFolder=""
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 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.

Posted

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... :)

  • 3 weeks later...
Posted

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

 

'*********************************************
'*	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:

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..

Posted
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.
Posted
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 :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...