WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: hienpham on August 27, 2013, 06:39:40 PM

Title: Install CAPICOM on Win7 and Server 2003 SP2
Post by: hienpham on August 27, 2013, 06:39:40 PM
Hi,
  In order to use:
ObjectCreate("CAPICOM.Certificate") and CreateObject( "CAPICOM.Store.2" )
we need to install the CAPICOM.
I did some research on the web and got some aticles such as:
http://www.microsoft.com/en-us/download/details.aspx?id=25281    : Platform SDK Redistributable: CAPICOM
http://social.technet.microsoft.com/Forums/windows/en-US/b977ef42-7b65-439e-a95b-5d4d204501fd/installing-capicomdll-on-windows-7

I have tried several download but still failed to create the CAPICOM.Certificate.
I have windows 7 and Server 2003 SP2.
What can I do to be able to run :   
http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WIL~Extenders/ADSI+COM~-~Active~Directory~Published~Certificates~Info~.txt
and
http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WinBatch/OLE~COM~ADO~CDO~ADSI~LDAP/Samples~from~Users+Enumerate~Certificates.txt

Thanks for any help.
Title: Re: Install CAPICOM on Win7 and Server 2003 SP2
Post by: Deana on August 28, 2013, 08:34:33 AM
Deprecated on Windows 7. Some interesting info here:  http://blogs.msdn.com/karinm/archive/2009/01/19/capicom-dll-removed-from-windows-sdk-for-windows-7.aspx

CAPICOM is a 32-bit only component that is available for use in the following operating systems: Windows Server 2008, Windows Vista, Windows XP.

If you insist on using CAPICOM on Windows 7, you might try these steps...
(UNTESTED!)
[li]Register the dll  using this Command: [/li][/list]regsvr32.exe X64 version. %windir%\syswow64\regsvr32.exe /s %windir%\syswow64\capicom.dll
Alternatively you might consider using

Title: Re: Install CAPICOM on Win7 and Server 2003 SP2
Post by: Deana on August 28, 2013, 08:50:28 AM
Here is an example using certutil.exe that is installed on Windows 7 by default:

Code (winbatch) Select
;use cerutil
#DefineFunction udfCaptureDosOutput( DosCommand )
   DebugTrace(22, ''); Allow DebugTrace continuation (inherit the debug mode from the caller).
   DataArray=ArrDimension(4)               ;Allocate return array
   ArrInitialize(DataArray,"")             ;initialize to all null strings
   ;Stuff the cmd in the 4 element of the array
   DataArray[3] = DosCommand
   oShell = ObjectCreate("WScript.Shell")    ;open shell object

   ;If 64 bit turn off redirection?
   If WinMetrics(-7) == 2
      ;64-bit Windows
      oldvalue = IntControl( 92, "disable", 0, 0, 0 )
      oScriptExec = oShell.Exec(DosCommand)   ;run the command
      IntControl( 92, "revert", oldvalue, 0, 0 )
   Else
      oScriptExec = oShell.Exec(DosCommand)   ;run the command
   EndIf

   ;Open output objects
   oStdOut = oScriptExec.StdOut
   oStdErr = oScriptExec.StdErr

   While (oScriptExec.Status==0)           ;wait for completion

      ;Caputure StdOut data
      oStdOut = oScriptExec.StdOut
      While ! oStdOut.AtEndOfStream
         strLine = oStdOut.ReadLine
         DataArray[1] = StrCat(DataArray[1],strLine,@CRLF)
      EndWhile

      ;Capture StdErr data
      oStdErr = oScriptExec.StdErr
      While ! oStdErr.AtEndOfStream
         strLine = oStdErr.ReadLine
         DataArray[2] = StrCat(DataArray[2],strLine,@CRLF)
      EndWhile

      TimeDelay(0.1)
   EndWhile

   ;Get remainder of data, if any

      ;Caputure StdOut data
      oStdOut = oScriptExec.StdOut
      While ! oStdOut.AtEndOfStream
         strLine = oStdOut.ReadLine
         DataArray[1] = StrCat(DataArray[1],strLine,@CRLF)
      EndWhile

      ;Capture StdErr data
      oStdErr = oScriptExec.StdErr
      While ! oStdErr.AtEndOfStream
         strLine = oStdErr.ReadLine
         DataArray[2] = StrCat(DataArray[2],strLine,@CRLF)
      EndWhile


   DataArray[0]=oScriptExec.ExitCode         ;save errorlevel/exit code

   ;Close handles that were opened
   oStdOut = 0
   oStdErr = 0
   oScriptExec = 0
   oShell = 0

   ;Return the array
   Return(DataArray)

#EndFunction

#DefineFunction udfDisplayResult( dataarray )
   Exitcode = dataarray[0]
   StdOut = dataarray[1]
   StdErr = dataarray[2]
   DosCommand = dataarray[3]
   If stdErr != ""
      Message(DosCommand: " - STDERR", StdErr)
      Message(DosCommand:" - EXITCODE", Exitcode)
   Else
      Message(DosCommand:" - STDOUT", StdOut)
   EndIf
   Return 1
#EndFunction

strFileName = '"C:\Program Files (x86)\Common Files\Adobe AIR\Versions\1.0\Resources\Thawte Root Certificate.cer"'
doscmd2 = "certutil ":strFileName
dataarray = udfCaptureDosOutput( doscmd2 )
;udfDisplayResult( dataarray )
data = dataarray[1]
lookfor =  'NotAfter:'
startpos = StrIndex( data, lookfor , 1, @Fwdscan )
expiration = StrSub( data, startpos+StrLen(lookfor), 11 )
Pause('Certificate Expiration Date',expiration)
Title: Re: Install CAPICOM on Win7 and Server 2003 SP2
Post by: Deana on August 28, 2013, 09:09:19 AM
Here is an example using dotNet on Windows 7:

Code (winbatch) Select
;dotNet x509certificate
;Alternatively you might consider using the dotNet x509certificate class: http://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509certificate.getexpirationdatestring(v=vs.90).aspx
;***************************************************************************
;**   Read Expiration date from a .CER certificate file
;**
;** Purpose: Read Expiration date from a .CER certificate file
;** Inputs:  .cer file path
;** Outputs: Message with expiration date of certificate file
;** Reference:
;**       REQUIRES WinBatch 2013A or newer
;**
;** Developer: Deana Falk 2013.08.28
;***************************************************************************
If Version( )< '2013A'
   Pause('Notice', 'Need 2013A or Newer Version of WinBatch')
   Exit
EndIf

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Load assemblies into the WinBatch process.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; mscorlib assembly is automatically loaded by WinBatch when the CLR is loaded.
;ObjectClrOption ('use','mscorlib, version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Prompt for input
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; The path to the certificate.
strFileName = 'C:\Program Files (x86)\Common Files\Adobe AIR\Versions\1.0\Resources\Thawte Root Certificate.cer'

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Associate a Framework based type name with a value.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Create a class implemented by a managed assembly.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

; Load the certificate into an X509Certificate object.
X509Certificate =  ObjectClrNew( 'System.Security.Cryptography.X509Certificates.X509Certificate' )
cert = X509Certificate.CreateFromCertFile(strFileName);
;Get the value.
results = cert.GetExpirationDateString();
;Display the value
Pause('GetExpirationDateString', results)
Exit
Title: Re: Install CAPICOM on Win7 and Server 2003 SP2
Post by: hienpham on August 28, 2013, 12:00:48 PM
Hi Deana,
   I don't really know how to thank you for all your help!!  :)
   With your detailed instruction I was able to implement CAPICOM on my Win7, I still have some programs using CAPICOM that you have showed me how to do few years ago, they are very valuable.
   This Tech Support Forum with your help is one of the main reason why I keep using WinBatch for over 15 years, since we still have Marty by your side.
Whenever I cannot find an answer, you recue me. I always know that I can rely on you and the WinBatch team for help while working on my projects!! Thanks again Deana.

Hien Pham
Siemens PLM Software Inc.
Title: Re: Install CAPICOM on Win7 and Server 2003 SP2
Post by: Deana on August 28, 2013, 12:22:06 PM
Thank you! Glad to hear you have it working on Windows 7.
Title: Re: Install CAPICOM on Win7 and Server 2003 SP2
Post by: hienpham on August 28, 2013, 04:16:57 PM
Hi Deana,
  FYI I want to clarify some extra steps that I have to do when installing the Capicom.dll:Please correct me if I was wrong.

Again thanks for your help Deana.

hien
Title: Re: Install CAPICOM on Win7 and Server 2003 SP2
Post by: Deana on August 29, 2013, 09:57:45 AM