The template parameter in InitializeFromPrivateKey() on CX509CertificateRequestPkcs10 object causes exception when trying a specific Template
I am having an issue with specifying the template parameter in *InitializeFromPrivateKey()* on the *X509Enrollment.CX509CertificateRequestPkcs10* object. Anything other than a template of *"User"* is resulting in the following exception:-

**CertEnroll::CX509CertificateRequestPkcs10::InitializeFromPrivateKey: The requested certificate template is not supported by this CA. 0x80094800 (-2146875392)** 
 

There is a specific Certificate template that I need to be used, and when I try it then the code throws the exception. The template exists on the CA, and on the client machine which is running the following code.

Javascript code as follows:

     <script type="text/javascript">
    
         var sCertificate = null;
         var sDistinguishedName = "C=\"\";S=\"\";L=\"\";O=\"XXXXX\";OU=\"XXXXXXX\";E=\"XXXXX@XXXX.com\";CN=\"xxxxxxx\";";
         var template = "RegistrationCert"; //Anything Other than "User" fails, have tried template Oid too.
        
         var classFactory = new ActiveXObject("X509Enrollment.CX509EnrollmentWebClassFactory");
         var objEnroll = classFactory.CreateObject("X509Enrollment.CX509Enrollment");
         var objPrivateKey = classFactory.CreateObject("X509Enrollment.CX509PrivateKey");
         var objRequest = classFactory.CreateObject("X509Enrollment.CX509CertificateRequestPkcs10");
         var objDN = classFactory.CreateObject("X509Enrollment.CX500DistinguishedName");
          
         objPrivateKey.ProviderName = "Microsoft Enhanced Cryptographic Provider v1.0";
         objPrivateKey.KeySpec = "1";
         objPrivateKey.ProviderType = "1";
    
        try 
        {
                objRequest.InitializeFromPrivateKey(1, objPrivateKey, template);
                objDN.Encode(sDistinguishedName, 0);
                objRequest.Subject = objDN;
                objEnroll.InitializeFromRequest(objRequest);
                sCertificate = objEnroll.CreateRequest(1);
                document.writeln(sCertificate);
        }
        catch (ex)
        {
                 document.writeln(ex.description);
        }
     </script>

**Couple of other questions**  
- I assume that the template should exist on the Client Machine? Otherwise how does it know the location of the CA to query for templates?  
- Does CertEnroll on a Client even work against a Windows 2003 CA server??

If you can help me that it would be much appreciated!!!

**Additional Info**  
- Client is Windows 7, with MS IE9 Client running as Administrator.  
- Web App which hosts the above page is accessed over HTTPs.  
- Web App is hosted on a Win2003 CA Server.


**Before posting I have looked at...**    
- Stackoverflow threads regarding CertEnroll + InitializeFromPrivateKey  
- [Blogs about using Template OID not Template name](http://www.sambeauvois.be/blog/2010/04/the-ix509certificaterequestpkcs10-initializefromtemplatename-adventure/)  
- [MSDN / alejacma's Site](http://blogs.msdn.com/b/alejacma/archive/tags/certenroll/)  
- CertEnroll API on MSDN




The template parameter in InitializeFromPrivateKey() on CX509CertificateRequestPkcs10 object causes exception when trying a specific Template
===

I am having an issue with specifying the template parameter in *InitializeFromPrivateKey()* on the *X509Enrollment.CX509CertificateRequestPkcs10* object. Anything other than a template of *"User"* is resulting in the following exception:-

**CertEnroll::CX509CertificateRequestPkcs10::InitializeFromPrivateKey: The requested certificate template is not supported by this CA. 0x80094800 (-2146875392)** 
 

There is a specific Certificate template that I need to be used, and when I try it then the code throws the exception. The template exists on the CA, and on the client machine which is running the following code.

Javascript code as follows:

     <script type="text/javascript">
    
         var sCertificate = null;
         var sDistinguishedName = "C=\"\";S=\"\";L=\"\";O=\"XXXXX\";OU=\"XXXXXXX\";E=\"XXXXX@XXXX.com\";CN=\"xxxxxxx\";";
         var template = "RegistrationCert"; //Anything Other than "User" fails, have tried template Oid too.
        
         var classFactory = new ActiveXObject("X509Enrollment.CX509EnrollmentWebClassFactory");
         var objEnroll = classFactory.CreateObject("X509Enrollment.CX509Enrollment");
         var objPrivateKey = classFactory.CreateObject("X509Enrollment.CX509PrivateKey");
         var objRequest = classFactory.CreateObject("X509Enrollment.CX509CertificateRequestPkcs10");
         var objDN = classFactory.CreateObject("X509Enrollment.CX500DistinguishedName");
          
         objPrivateKey.ProviderName = "Microsoft Enhanced Cryptographic Provider v1.0";
         objPrivateKey.KeySpec = "1";
         objPrivateKey.ProviderType = "1";
    
        try 
        {
                objRequest.InitializeFromPrivateKey(1, objPrivateKey, template);
                objDN.Encode(sDistinguishedName, 0);
                objRequest.Subject = objDN;
                objEnroll.InitializeFromRequest(objRequest);
                sCertificate = objEnroll.CreateRequest(1);
                document.writeln(sCertificate);
        }
        catch (ex)
        {
                 document.writeln(ex.description);
        }
     </script>

**Couple of other questions**  
- I assume that the template should exist on the Client Machine? Otherwise how does it know the location of the CA to query for templates?  
- Does CertEnroll on a Client even work against a Windows 2003 CA server??

If you can help me that it would be much appreciated!!!

**Additional Info**  
- Client is Windows 7, with MS IE9 Client running as Administrator.  
- Web App which hosts the above page is accessed over HTTPs.  
- Web App is hosted on a Win2003 CA Server.


**Before posting I have looked at...**    
- Stackoverflow threads regarding CertEnroll + InitializeFromPrivateKey  
- [Blogs about using Template OID not Template name](http://www.sambeauvois.be/blog/2010/04/the-ix509certificaterequestpkcs10-initializefromtemplatename-adventure/)  
- [MSDN / alejacma's Site](http://blogs.msdn.com/b/alejacma/archive/tags/certenroll/)  
- CertEnroll API on MSDN



