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.
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!)
- Log in as Administrator.
- Download the CAPICOM.dll: Microsoft Windows SDK for Windows 7 and .NET Framework 3.5 SP1 (http://www.microsoft.com/en-us/download/details.aspx?id=3138)
- Copy the dll to the folder C:\Windows\System32.
- Start CMD, via right click, by choosing Run as Administrator. Answer a UAC prompt. Your command window will have the necessary administrator permissions to do privileged operation of registering a DLL.
[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
- certutil.exe and parse the output.
- dotNet x509certificate class: http://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509certificate.getexpirationdatestring(v=vs.90).aspx
Here is an example using certutil.exe that is installed on Windows 7 by default:
;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)
Here is an example using dotNet on Windows 7:
;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
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.
Thank you! Glad to hear you have it working on Windows 7.
Hi Deana,
FYI I want to clarify some extra steps that I have to do when installing the Capicom.dll:
- In the Microsoft Windows SDK for Windows 7 and .NET Framework 3.5 SP1 page (http://www.microsoft.com/en-us/download/details.aspx?id=3138) there is NO capicom.dll, I only knew this after reading the ReleaseNotes.htm that we got after installing the program. The part that they mention about Capicom is below:
5.3 SDK Tools and Compilers
5.3.1 Tools Removed from this Release
The following tools were included in the Windows SDK for Server 2008 and .NET Framework 3.5 release, but are not included in this release:
Ã,· capicom.dll
Ã,· iacom.dll
- We have to download the Capicom.dll from http://www.dll-files.com
- About installing Capicom.dll that is an 32-bit dll: depending on our OS (32 or 64-bit) we have to:
for 64-bit : copy capicom.dll to C:\Windows\systemWOW64 and run your command:
%windir%\syswow64\regsvr32.exe /s %windir%\syswow64\capicom.dll
for 32-bit : copy capicom.dll to C:\Windows\system32 and run the command:
%windir%\system32\regsvr32.exe /s %windir%\system32\capicom.dll
Please correct me if I was wrong.
Again thanks for your help Deana.
hien
As far as I am aware there is no 64 bit version of CAPICOM.CLL. I don't recommend getting this system dll from any third party site. Here is a set of revised steps on Windows 7 and newer.
If you insist on using CAPICOM on Windows 7, you might try these steps...
- Log in as Administrator.
- Download and install the CAPICOM.dll: Microsoft Platform SDK Redistributable: CAPICOM (http://www.microsoft.com/en-us/download/details.aspx?id=25281)
- Because the dll is 32-bit, copy the dll from C:\Program Files (x86)\Microsoft CAPICOM 2.1.0.2 SDK\Lib\X86\capicom.dll to the folder C:\Windows\SysWOW64\capicom.dll
- Start CMD, via right click, by choosing Run as Administrator. Answer a UAC prompt. Your command window will have the necessary administrator permissions to do privileged operation of registering a DLL
- Register the dll using this Command: %windir%\syswow64\regsvr32.exe %windir%\syswow64\capicom.dll .
Alternatively you might consider using
- certutil.exe and parse the output.
- dotNet x509certificate class: http://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509certificate.getexpirationdatestring(v=vs.90).aspx