Dim Result
Dim DirWin
Dim TmpDir
Dim fso
Dim MiOs
Dim Midir
Dim Lidx
Dim Silent
Dim ListaF (15)
Dim ErrList()
Dim ErrReg ()
Dim msg
Dim Miver
Miver = "1.00"
Silent = "/s "      ' sin mensajes

ListaF(0) = "msxml3.dll"
ListaF(1) = "comctl32.ocx"
ListaF(2) = "comdlg32.ocx"
ListaF(3) = "richtx32.ocx"
ListaF(4) = "tabctl32.ocx"
ListaF(5) = "mscomct2.ocx"
ListaF(6) = "mscomctl.ocx"
ListaF(7) = "mscomm32.ocx"
ListaF(8) = "msflxgrd.ocx"
ListaF(9) = "comct232.ocx"
ListaF(10) = "dbgrid32.ocx"
ListaF(11) = "dblist32.ocx"
ListaF(12) = "msscript.ocx"
ListaF (13) = ""
ListaF (14) = ""
ListaF (15) = ""

'*******************************************************************************
On error resume next

Set fso = CreateObject("Scripting.FileSystemObject")
if Err.Number <> 0 then
  Msgbox "No se encuentra instalado, o no funciona correctamente, IE4 o superior; requerido por el proceso de instalación.",vbcritical,"Restauración de archivos"
  wscript.quit
end if
err.clear

Set WshShell = Wscript.CreateObject("Wscript.Shell")
if Err.Number <> 0 then
  Msgbox "No se encuentra instalado, o no funciona correctamente, IE4 o superior; requerido por el proceso de instalación.",vbcritical,"Restauración de archivos"
  wscript.quit
end if
err.clear

'Obtener directorio de Windows
DirWin = GetWinDir

if DirWin = "" then
  wscript.quit
end if
'Determinar mi directorio
Midir = getmidir(wscript.scriptfullname)

MiOS = Getos
if MiOS = "" then
  'W95 W98 WMe
  TmpDir = DirWin & "system\"
else
  'NT 2000 XP
  TmpDir = DirWin & "system32\"
End if

'Presentar dialogo de seleccion de opciones
Return = 0
do
  Lidx=0
  Return = Getinp ()
loop until ((Return >= 1) and (Return <=5))

'Registrar las librerias originales
Redim ErrList (0)
Redim ErrReg (0)
do while ((ListaF(Lidx) <> "") and (Lidx <= Ubound(ListaF)))
  if fso.fileexists(TmpDir & ListaF(Lidx)) then
    Return = WshShell.Run("regsvr32 " & Silent & TmpDir & ListaF(Lidx) , 1, TRUE)
    if Return <> 0 then
      err.raise 51
      Redim Preserve ErrReg (ubound(ErrReg) + 1)
      ErrReg(Ubound(ErrReg)) = TmpDir & ListaF(Lidx)
    end if
  else
    Redim Preserve ErrList (ubound(ErrList) + 1)
    ErrList(Ubound(ErrList)) = TmpDir & ListaF(Lidx)
    err.raise 51
  end if
  Lidx = Lidx + 1
loop

if err.Number <> 0 then
  if ubound(errlist) > 0 then
    msg = "Los siguientes archivos no se encontraron:" & vbcrlf
    for i=1 to ubound(ErrList)
      msg = msg & ErrList(i) & vbcrlf
    next
    msg = msg & vbcrlf
  end if

  if ubound(ErrReg) > 0 then
    msg = msg & vbcrlf & "Los siguientes archivos produjeron errores al ser registrados:" & vbcrlf
    for i=1 to ubound(Errreg)
      msg = msg & ErrReg(i) & vbcrlf
    next
    msg = msg & vbcrlf
  end if

  msg = msg & "Han ocurrido errores durante el proceso del comando solicitado."
  msgbox msg,vbexclamation,"Restauración de archivos"
else
  msgbox "Operación finalizada.",,"Restauración de archivos"
end if
wscript.quit

'*******************************************************************************
Function GetWindir()
  Dim Tmp
  Set WshSysEnv = WshShell.Environment("process")
  Tmp = WshSysEnv("WINDIR")
  if len(Tmp) > 1 then
    Tmp = pathraya(Tmp)
    GetWinDir = Tmp
  else
    Msgbox "Imposible determinar el directorio del Sistema.",vbcritical,"Restauración de archivos"
    GetWinDir = ""
  End if
End Function
'*******************************************************************************
Function PathRaya(PathV )
    Dim Var1
    Var1 = Trim(PathV)
    If Right(Var1, 1) = "\" Then

    Else
        Var1 = Var1 + "\"
    End If
    PathRaya = Var1
End Function
'*******************************************************************************
Function GetOS()
  Dim Tmp
  Set WshSysEnv = WshShell.Environment("process")
  Tmp = WshSysEnv("OS")
  if len(Tmp) > 1 then
    GetOS = Tmp
  else
    GetOS = ""
  End if
End Function
'*******************************************************************************
Function GetMiDir (mifname)
  Dim K
  GetMiDir = ""
  K = instrrev(mifname,"\")
  if K>1 then
    GetMiDir = mid(mifname,1,k)
  end if
end function
'*******************************************************************************
Function GetInp ()
  Dim Return1
  Dim K
  Dim UnFile
  Silent = "/s "
  Unfile = ""
  Return1 = Inputbox ("Para restaurar los archivos presione Aceptar." & string(5,vbcr) & "Comando:","Restauración de archivos Ver. " & Miver,"Normal")
  Return1 = lcase ( trim (Return1))
  if Return1 <> "" then
    k = Instr (1,Return1," -mon")
    if k > 0 then
      Silent = ""
      Return1 = trim (replace (Return1," -mon",""))
    end if
  end if

  if Return1 <> "" then
    k = Instr (1,Return1," -moff")
    if k > 0 then
      Silent = "/s "
      Return1 = trim (replace (Return1," -moff",""))
    end if
  end if

  if Return1 <> "" then
    k = Instr (1,Return1,"-r:")
    if k > 0 then
      Silent = ""
      Return1 = trim (replace (Return1,"-r:",""))
      UnFile = Return1
    end if
  end if

  if Return1 <> "" then
    k = Instr (1,Return1,"-u:")
    if k > 0 then
      Silent = "/U "
      Return1 = trim (replace (Return1,"-u:",""))
      UnFile = Return1
    end if
  end if
  if Return1 <> "" then
    k = Instr (1,Return1,"-rf:")
    if k > 0 then
      TmpDir = ""
      Silent = ""
      Return1 = trim (replace (Return1,"-rf:",""))
      UnFile = Return1
    end if
  end if

  if Return1 <> "" then
    k = Instr (1,Return1,"-uf:")
    if k > 0 then
      TmpDir = ""
      Silent = "/U "
      Return1 = trim (replace (Return1,"-uf:",""))
      UnFile = Return1
    end if
  end if

  if Return1 = "help" or Return1 = "?" or Return1 = "-?" then
    msg = "Comandos válidos:" & vbcrlf
    msg = msg & "Normal" & vbtab & "Registra las ocx/dll quitadas por SIAP y SIE." & vbcrlf
    msg = msg & "Sie" & vbtab & "Registra las dll quitadas por SIE." & vbcrlf
    msg = msg & "Siap" & vbtab & "Registra las ocx quitadas por SIAP." & vbcrlf
    msg = msg & "Completa" & vbtab & "Registra todas las ocx/dll usadas por PW, IW e IDW." & vbcrlf
    if Return1 = "-?" then
      msg = msg & "-r:File" & vbtab & "Registra File. (Fuerza -Mon)." & vbcrlf
      msg = msg & "-u:File" & vbtab & "Quita del registro File. (Fuerza -Mon)." & vbcrlf
      msg = msg & "-rf:File" & vbtab & "Registra File(full path). (Fuerza -Mon)." & vbcrlf
      msg = msg & "-uf:File" & vbtab & "Quita del registro File(full path). (Fuerza -Mon)." & vbcrlf
      msg = msg & "Help o -?" & vbtab & "Presenta esta ayuda." & vbcrlf
      msg = msg & vbcrlf & "Opciones: " & vbcrlf
      msg = msg & "-Moff" & vbtab & "No se muestran mensajes de registro (default)." & vbcrlf
      msg = msg & "-Mon" & vbtab & "Se muestran mensajes de registro para cada archivo." & vbcrlf
    end if
    Return1 = ""
    Msgbox msg,,"Restauración de archivos - Ayuda"
    GetInp = 0
    exit function
  end if

  GetInp = 0
  If Return1 = "" then
    wscript.quit
  elseIf Return1 = "normal" then
    ListaF(5) = ""
    GetInp=1
  elseIf Return1 = "completa" then
    GetInp = 2
  elseIf Return1 = "sie" then
    GetInp = 3
    ListaF(1) = ""
  elseIf Return1 = "siap" then
    Lidx = 1
    ListaF(5) = ""
    GetInp = 4
  elseIf UnFile <> "" then
    Lidx = 0
    ListaF(0) = UnFile
    ListaF(1) = ""
    GetInp = 5
  else
    Msgbox "Opción no valida.",vbexclamation,"Restauración de archivos"
    GetInp = 0
  end if
end function



