Programatically show Certificate Dialog,...

Programatically show Certificate Dialog,...

Post by Kerem Gr » Tue, 03 Mar 2009 20:51:59


Hi,

how can i show this:

http://www.yqcomputer.com/

programatically for from my exe for my exe (Exe is signed
with X509 Certifcate),...

TIA,...

Regards

Kerem

--
--
-----------------------
Beste Grse / Best regards / Votre bien devoue
Kerem Grc Latest Project: http://www.yqcomputer.com/
Latest Open-Source Projects: http://www.yqcomputer.com/
-----------------------
"This reply is provided as is, without warranty express or implied."
 
 
 

Programatically show Certificate Dialog,...

Post by Kerem Gr » Wed, 04 Mar 2009 15:27:24

i,

in the meantime i answered the question by myself. here is
the solution inf someone is interessted in. Its a C#/.NET Example
but as the function does not change, it can be "translated" to any
programming language that can target the Windows API:



[StructLayout(LayoutKind.Sequential,CharSet= CharSet.Unicode)]
public struct CRYPTUI_VIEWCERTIFICATE_STRUCT
{
public int dwSize;
public IntPtr hwndParent;
public int dwFlags;
[MarshalAs(UnmanagedType.LPWStr)]
public String szTitle;
public IntPtr pCertContext;
public IntPtr rgszPurposes;
public int cPurposes;
public IntPtr pCryptProviderData;
public Boolean fpCryptProviderDataTrustedUsage;
public int idxSigner;
public int idxCert;
public Boolean fCounterSigner;
public int idxCounterSigner;
public int cStores;
public IntPtr rghStores;
public int cPropSheetPages;
public IntPtr rgPropSheetPages;
public int nStartPage;
}



[DllImport("CryptUI.dll", CharSet = CharSet.Unicode, SetLastError =
true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern Boolean CryptUIDlgViewCertificate(
ref CRYPTUI_VIEWCERTIFICATE_STRUCT pCertViewInfo,
ref bool pfPropertiesChanged);





A ready to use function in C#:


public static bool ShowBinaryImageCertificateDialogFromFile(string
FileName, IntPtr ParentWindowHandle, ref Exception Error)
{
try
{
bool pPropertyChanged = false;

X509Certificate certificate =
X509Certificate.CreateFromSignedFile(FileName);

CRYPTUI_VIEWCERTIFICATE_STRUCT cuivcs = new
CRYPTUI_VIEWCERTIFICATE_STRUCT();
cuivcs.dwSize = Marshal.SizeOf(cuivcs);
cuivcs.hwndParent = ParentWindowHandle;
cuivcs.pCertContext = certificate.Handle;
cuivcs.szTitle = "Certificate Info for " +
Application.ProductName + " " + AssemblyVersion;
cuivcs.dwFlags = 0;
cuivcs.nStartPage = 0;

if (CryptUIDlgViewCertificate(ref cuivcs, ref
pPropertyChanged) == false)
{
Win32Exception winerr = new Win32Exception();

if (winerr.ErrorCode != -2147467259) //user abort
{
throw winerr;
}
}

Error = null;
return true;
}
catch (Exception err)
{
Error = err;
return false;
}
}


Hope this helps someone with same problem....

Regards

Kerem

--
--
-----------------------
Beste Grse / Best regards / Votre bien devoue
Kerem Grc Latest Project: http://www.pro-it-education.de/software/deviceremover
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------
"This reply is provided as is, without warranty express or implied."

"Kerem Grclt; < XXXX@XXXXX.COM >m> schrieb im Newsbeitrag
news:gogh91$k8p$01$ XXXX@XXXXX.COM ...> > Hi,> >> > how can i show this:> >> > http://www.pro-it-education.de/staff/keremg/misc/drcert.jpg> >>