Leaderboard
Popular Content
Showing content with the highest reputation on 10/26/2017 in all areas
-
Version 1.6.3.0
17,293 downloads
Extensive library to control and manipulate Microsoft Active Directory. Threads: Development - General Help & Support - Example Scripts - Wiki Previous downloads: 30467 Known Bugs: (last changed: 2020-10-05) None Things to come: (last changed: 2020-07-21) None BTW: If you like this UDF please click the "I like this" button. This tells me where to next put my development effort1 point -
After reading this page, (http://www.drububu.com/illustration/tsp/index.html) I was curious and I put together this script. it is not a "stand alone" script, as it uses some third parties programs*, but in few steps it acomplish the conversion to the TSP art. The generated images are quite nice, but you have to try more attempts to find the right combinations of parameters for different source images. Best results can easily obtained with schematic black and wite images. Drag and drop for example something like in this link. Also, set the "Variable thickness line" option and try with the image at this link for another example: (https://images.fineartamerica.com/images/artworkimages/mediumlarge/1/david-michelangelo-murphy-elliott.jpg) Since used programs generate also some temporay files, please save this script and the dependencies into a single folder so to avoid the scattering of files around and also allowing the main script to find the needed programs. Example of an TSP art generated with this script and related programs (the image on the left is converted in the image on the right) just drag and drop images on the GUI of the script and all is done automatically. * Here are the links to download the needed "dependencies": ( just put all the stuff in a single folder along with the script.) voronoi.exe http://www.drububu.com/illustration/tsp/voronoi.zip stippler.dll also contained in the above archive concorde.exe http://www.math.uwaterloo.ca/tsp/concorde/downloads/codes/cygwin/concorde.exe.gz this program needs the cygwin dll (a very nice one) (I've used 7zip to open this archive) cygwin1.dll https://cygwin.com/snapshots/ get one x86 cygwin1-xxxxxxxx.dll.xz (only dll) svg_extract.exe http://www.drububu.com/illustration/tsp/svg_extract.zip tsp2svg.exe http://www.drububu.com/illustration/tsp/tsp2svg.zip here the script: ; TSP Art generator #include <FileConstants.au3> #include <WinAPISys.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiEdit.au3> #include <GDIPlus.au3> If Not _CheckDependencies() Then Exit ; can't run without dependencies. Global $bDropped, $sFile, $bDropAllowed = True ; create a blank file, or empty it if it's already created Global $hTail, $sLogFile = FileGetShortName(@ScriptDir & "\LogFile.txt") _GDIPlus_Startup() ; just for image format conversion to PNG (if needed) $Form1 = GUICreate("TSP art generator", 500, 650, -1, -1, -1, $WS_EX_ACCEPTFILES) ; --- options $Combo1 = GUICtrlCreateCombo("", 350, 505, 60, 25) GUICtrlCreateLabel("Sampling points", 415, 510, 80, 25) GUICtrlSetData($Combo1, "1000|2000|4000|6000|8000|10000|20000|40000|60000", "4000") ; some sampling rate $Checkbox1 = GUICtrlCreateCheckbox("Variable thickness line", 350, 535, 145, 25) $Checkbox2 = GUICtrlCreateCheckbox("Color (voronoi only)", 350, 565, 145, 25) ; --- Log viewer Global $hLog = GUICtrlCreateEdit("", 5, 500, 340, 145, BitOR($WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_MULTILINE, $ES_READONLY)) ; log viewer GUICtrlSetBkColor(-1, 0x000000) GUICtrlSetColor(-1, 0x00FF00) GUICtrlSetFont(-1, 9, -1, -1, "Courier New") ; following is a transparent control over the browser control ; purpose is to avoid that the drop event is captured by the browser control $hGlass = GUICtrlCreateLabel("", 0, 0, 500, 650) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) ; This is like a glass over the following underlying browser Control GUICtrlSetCursor(-1, 2) ; Cursor is an arrow (instead of the default I-beam) ; --- Embed a browser control Global $oIE = ObjCreate("Shell.Explorer.2") $hIE = GUICtrlCreateObj($oIE, 5, 5, 490, 490) $oIE.navigate("about:blank") AutoItSetOption("GUIOnEventMode", 1) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES") GUISetState(@SW_SHOW, $Form1) _LogPrint(@CRLF & _ "Hello," & @CRLF & _ "Drag and dropping images here above," & @CRLF & _ "will be converted into a TSP Art." & @CRLF & _ "have fun...") ; --- Main loop While 1 $nMsg = GUIGetMsg() Select Case $nMsg = $GUI_EVENT_CLOSE _Exit() Case $bDropped = True $bDropped = False $bDropAllowed = False ; Drop not allowed while generating _Generate_PST_Art() $bDropAllowed = True EndSelect WEnd ; --- Call externa programs the right sequence Func _Generate_PST_Art() _EmptyLog() ; empty the temporary log file _checkFileFormat($sFile) ; if dropped image isn't a PNG convert it to PNG _ShowInBrowser($sFile) ; show dropped image in the browser control ; step 1) Transform PNG image into a voronoi svg image ; ============================================================================ If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then ; variable thickness line? $sOptions = "" Else $sOptions = " -f " ; fixed radus EndIf If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then ; color points for voronoi? $sOptions = " -c " & $sOptions EndIf ; _call_External_Program(".\voronoi.exe " & $sOptions & "-s " & GUICtrlRead($Combo1) & " -n -I " & $sFile & " -O out.svg", True) _call_External_Program(FileGetShortName(@ScriptDir & '\voronoi.exe') & $sOptions & ' -s ' & GUICtrlRead($Combo1) & ' -n -I ' & $sFile & ' -O out.svg', True) _ShowInBrowser(FileGetShortName(@ScriptDir & "\out.svg")) ; show generated voronoi image in the browser control ; ; step 2) Extract points from the voronoi svg image and save to positions.tsp file ; for later input by the concorde TSP solver ; ============================================================================ _call_External_Program(FileGetShortName(@ScriptDir & '\svg_extract.exe') & " out.svg") _LogPrint("... going to next step ...") ; ; step 3) Resolve the Traveling Salesman Problem using the very good ; concorde.exe program (it needs the presence of the cygwin1.dll to work) ; ============================================================================ _call_External_Program(FileGetShortName(@ScriptDir & "\concorde.exe") & " -V -o tour.cyc positions.tsp", True) _LogPrint("... going to next step ...") ; ; step 3a) some adjustments to the tour.cyc file generated by concorde.exe ; ============================================================================ $hfile = FileOpen(FileGetShortName(@ScriptDir & '\tour.cyc')) Local $sContent = FileRead($hfile) FileClose($hfile) FileDelete(FileGetShortName(@ScriptDir & '\tour.cyc')) $sContent = StringReplace($sContent, Chr(0x20), Chr(0x0A)) _LogPrint("Replaced 0x20 with 0x0A " & @extended & " times.") $sContent = StringReplace($sContent, Chr(0x0A) & Chr(0x0A), Chr(0x0A)) _LogPrint("Replaced 0x0A 0x0A with 0x0A " & @extended & " times." & @CRLF) Local $x = StringInStr($sContent, Chr(0x0A)) ; first 0A $sContent = StringMid($sContent, $x + 1) ; remove first data (it's the number of points, not a point) $hfile = FileOpen(FileGetShortName(@ScriptDir & '\tour.cyc'), $FO_OVERWRITE + $FO_BINARY) FileWrite($hfile, $sContent) ; save adjusted data FileFlush($hfile) FileClose($hfile) ; ; step 4) "merge" data from out.svg and tour.cyc into the final tsp_art.svg file ; ============================================================================ If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then $sOptions = " +w" ; variable thickness line Else $sOptions = "" ; fixed thickness line EndIf $sOptions = FileGetShortName(@ScriptDir & "\tsp2svg.exe") & " out.svg tour.cyc" & $sOptions _call_External_Program($sOptions) _ShowInBrowser(FileGetShortName(@ScriptDir & "\tsp_art.svg")) _LogPrint(@CRLF & _ "+-----------------------------------+" & @CRLF & _ "| End of conversion --> tsp_art.svg |" & @CRLF & _ "+-----------------------------------+" & @CRLF) EndFunc ;==>_Generate_PST_Art ; === Functions Func _call_External_Program($sCommand, $bVerbose = False) Local $sLine If $bVerbose = True Then $sCommand = @ComSpec & " /c " & $sCommand & ">>" & $sLogFile & " 2>>&1" EndIf Local $hPid = Run($sCommand, ".", @SW_HIDE) If Not $hPid Then _LogPrint("Error on run external program" & @CRLF) Return SetError(1) EndIf Do If $bVerbose Then $sLine = FileReadLine($hTail) If Not @error Then _LogPrint($sLine) EndIf EndIf Until Not ProcessExists($hPid) If $bVerbose Then $sLine = "..." ; "Task execution terminated ...." Do _LogPrint($sLine) $sLine = FileReadLine($hTail) Until @error EndIf EndFunc ;==>_call_External_Program Func _LogPrint($sLine) If StringLen(GUICtrlRead($hLog)) > 25000 Then ; Max Len of a CtrlBox is 30000 char _GUICtrlEdit_SetText($hLog, StringRight(GUICtrlRead($hLog), 20000)) ; short the content of CtrlBox to 20000 char EndIf _GUICtrlEdit_AppendText($hLog, $sLine & @CRLF) EndFunc ;==>_LogPrint Func WM_DROPFILES($hWnd, $iMsg, $wParam, $lParam) If $bDropAllowed Then Local $sExt = ".bmp|.png|.jpg|.gif" ; img drop filtering thanks to @UEZ Local $aFileList = _WinAPI_DragQueryFileEx($wParam) If Not @error Then For $i = 1 To $aFileList[0] If StringInStr($sExt, StringRegExpReplace($aFileList[$i], ".*(\.+)", "$1")) Then $bDropped = True $sFile = FileGetShortName($aFileList[$i]) ExitLoop EndIf Next Else _LogPrint("Error on drop" & @CRLF) EndIf _WinAPI_DragFinish($wParam) _LogPrint("Droped: " & $sFile & @CRLF) Return 0 EndIf EndFunc ;==>WM_DROPFILES Func _ShowInBrowser($sImg) ; setup Javascript engine with also embeded the "entity" library If StringRight($sImg, 3) = "svg" Then Else EndIf ; *** create a minimal 'html' page listing for the browser control Local $sHTML = "<HTML><HEAD>" & @CRLF & _ "<meta http-equiv=""X-UA-Compatible"" content=""IE=edge"" />" & @CRLF & _ "</HEAD>" & @CRLF & _ "<body>" & @CRLF & _ '<img src="' & $sImg & '" style="width:100%; height:100%;" />' & @CRLF & _ "</body>" & @CRLF & _ "</HTML>" & @CRLF ; html closing tags ; *** end of html page listing ; _LogPrint(">_" & @CRLF) $oIE.navigate('about:blank') While Not String($oIE.readyState) = 'complete' ; wait for about:blank Sleep(100) WEnd $oIE.document.Write($sHTML) ; inject lising directly to the HTML document: $oIE.document.close() ; close the write stream Sleep(1000) $oIE.document.execCommand("Refresh") EndFunc ;==>_ShowInBrowser Func _checkFileFormat($sFile) Local $hImage = _GDIPlus_ImageLoadFromFile($sFile) Local $aFormat = _GDIPlus_ImageGetRawFormat($hImage) If $aFormat[1] <> "PNG" Then _ConvertToPNG($hImage) _GDIPlus_ImageDispose($hImage) EndFunc ;==>_checkFileFormat Func _ConvertToPNG(ByRef $hImage) Local $CLSID = _GDIPlus_EncodersGetCLSID('PNG') $sFile = FileGetShortName(@ScriptDir & "\Input.png") _GDIPlus_ImageSaveToFileEx($hImage, $sFile, $CLSID) EndFunc ;==>_ConvertToPNG Func _EmptyLog() FileClose($hTail) $hTail = FileOpen($sLogFile, $FO_OVERWRITE) FileWrite($hTail, "Start log: " & @YEAR & '/' & @MON & '/' & @MDAY & ' ' & @HOUR & ':' & @MIN & ':' & @SEC & @CRLF) FileFlush($hTail) FileClose($hTail) $hTail = FileOpen($sLogFile) ; read only EndFunc ;==>_EmptyLog Func _CheckDependencies() Local $iDependencie = 0 $iDependencie += FileExists(@ScriptDir & "\voronoi.exe") ; http://www.drububu.com/illustration/tsp/voronoi.zip $iDependencie += FileExists(@ScriptDir & "\stippler.dll") ; " also contained in the above archive $iDependencie += FileExists(@ScriptDir & "\concorde.exe") ; http://www.math.uwaterloo.ca/tsp/concorde/downloads/codes/cygwin/concorde.exe.gz $iDependencie += FileExists(@ScriptDir & "\cygwin1.dll") ; get one from here https://cygwin.com/snapshots/ get cygwin1-xxxxxxxxx.dll.xz $iDependencie += FileExists(@ScriptDir & "\svg_extract.exe") ; http://www.drububu.com/illustration/tsp/svg_extract.zip $iDependencie += FileExists(@ScriptDir & "\tsp2svg.exe") ; http://www.drububu.com/illustration/tsp/tsp2svg.zip Return $iDependencie = 6 EndFunc ;==>_CheckDependencies Func _Exit() _GDIPlus_Shutdown() FileClose($hTail) AutoItSetOption("GUIOnEventMode", 0) GUIRegisterMsg($WM_DROPFILES, "") Exit EndFunc ;==>_Exit1 point
-
Here's your script, modified so that it can actually run, and color coding your labels to prove I was right. #include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> $Form1 = GUICreate("Login", 416, 206, 192, 124) $Username = GUICtrlCreateInput("", 40, 16, 329, 21) $password = GUICtrlCreateInput("", 40, 61, 329, 21, $ES_PASSWORD) $port = GUICtrlCreateInput("500", 40, 106, 50, 21, $ES_NUMBER) $Login = GUICtrlCreateButton("Login", 225, 144, 137, 33, $BS_DEFPUSHBUTTON) $Luser = GUICtrlCreateLabel("Username", 40, 38, 298, 50) GUICtrlSetBkColor(-1, 0x38F568) $Lpass = GUICtrlCreateLabel("Password", 40, 86, 298, 50) GUICtrlSetBkColor(-1, 0x6634FA) $Lport = GUICtrlCreateLabel("Port", 40, 130, 298, 50) GUICtrlSetBkColor(-1, 0xFB336F) $Status2 = GUICtrlCreateLabel("", 225, 100, 298, 50) GUICtrlSetBkColor(-1, 0x38F5EC) GUISetState() While GUIGetMsg() <> $gui_event_close WEnd1 point
-
Calling executables Best Practice
Earthshine reacted to JLogan3o13 for a topic
Most definitely you should be doing some level of error checking when calling an external application from your script. The precise method depends, of course, on the external executable being run, and what the result of its running produces (a new file on the hard drive, an entry in the Event Viewer, a new table in a database, etc.). As for running an Exit, just realize that is a hard stop. Again, without a hard example of a script you're working on it is difficult to say what you should do in every case. The big question regarding exit code on the script is, are you going to be reporting on that code somewhere else? If there is benefit to it exiting with a specific code as identified by you, then by all means include it. Otherwise, again, you can look at writing to a log file or the Event Viewer for run history reporting.1 point -
1 point
-
button click not working on windows server 2008
Earthshine reacted to JLogan3o13 for a topic
Where, precisely, are you getting the Delay function from?1 point -
1 point
-
button click not working on windows server 2008
Earthshine reacted to mLipok for a topic
Are you sure "WindowsForms10.BUTTON.app.0.378734a" still exist ?1 point -
Thanks, very useful.1 point
-
Hi @Chimp, I am just guessing here... Is this perhaps an analogous problem to deleting from an Array? Is it possible that your Outlook index gets corrupted (or confused) with the deletions? Should you delete from the other end? Or simple restart the entire process? What happens if you delete one item. Stop, start the script again, and only delete one item? This is merely speculation...1 point
-
Hello. basically You need to traslate this to AutoIt. #include <windows.h> #include <wincrypt.h> #include <wintrust.h> #include <stdio.h> #include <tchar.h> #pragma comment(lib, "crypt32.lib") #define ENCODING (X509_ASN_ENCODING | PKCS_7_ASN_ENCODING) typedef struct { LPWSTR lpszProgramName; LPWSTR lpszPublisherLink; LPWSTR lpszMoreInfoLink; } SPROG_PUBLISHERINFO, *PSPROG_PUBLISHERINFO; BOOL GetProgAndPublisherInfo(PCMSG_SIGNER_INFO pSignerInfo, PSPROG_PUBLISHERINFO Info); BOOL GetDateOfTimeStamp(PCMSG_SIGNER_INFO pSignerInfo, SYSTEMTIME *st); BOOL PrintCertificateInfo(PCCERT_CONTEXT pCertContext); BOOL GetTimeStampSignerInfo(PCMSG_SIGNER_INFO pSignerInfo, PCMSG_SIGNER_INFO *pCounterSignerInfo); int _tmain(int argc, TCHAR *argv[]) { WCHAR szFileName[MAX_PATH]= L"C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe"; HCERTSTORE hStore = NULL; HCRYPTMSG hMsg = NULL; PCCERT_CONTEXT pCertContext = NULL; BOOL fResult; DWORD dwEncoding, dwContentType, dwFormatType; PCMSG_SIGNER_INFO pSignerInfo = NULL; PCMSG_SIGNER_INFO pCounterSignerInfo = NULL; DWORD dwSignerInfo; CERT_INFO CertInfo; SPROG_PUBLISHERINFO ProgPubInfo; SYSTEMTIME st; ZeroMemory(&ProgPubInfo, sizeof(ProgPubInfo)); __try { /* if (argc != 2) { _tprintf(_T("Usage: SignedFileInfo <filename>\n")); return 0; } */ #ifdef UNICODE lstrcpynW(szFileName, argv[1], MAX_PATH); #else if (mbstowcs(szFileName, argv[1], MAX_PATH) == -1) { printf("Unable to convert to unicode.\n"); __leave; } #endif // Get message handle and store handle from the signed file. fResult = CryptQueryObject(CERT_QUERY_OBJECT_FILE, szFileName, CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED, CERT_QUERY_FORMAT_FLAG_BINARY, 0, &dwEncoding, &dwContentType, &dwFormatType, &hStore, &hMsg, NULL); if (!fResult) { _tprintf(_T("CryptQueryObject failed with %x\n"), GetLastError()); __leave; } // Get signer information size. fResult = CryptMsgGetParam(hMsg, CMSG_SIGNER_INFO_PARAM, 0, NULL, &dwSignerInfo); if (!fResult) { _tprintf(_T("CryptMsgGetParam failed with %x\n"), GetLastError()); __leave; } // Allocate memory for signer information. pSignerInfo = (PCMSG_SIGNER_INFO)LocalAlloc(LPTR, dwSignerInfo); if (!pSignerInfo) { _tprintf(_T("Unable to allocate memory for Signer Info.\n")); __leave; } // Get Signer Information. fResult = CryptMsgGetParam(hMsg, CMSG_SIGNER_INFO_PARAM, 0, (PVOID)pSignerInfo, &dwSignerInfo); if (!fResult) { _tprintf(_T("CryptMsgGetParam failed with %x\n"), GetLastError()); __leave; } // Get program name and publisher information from // signer info structure. if (GetProgAndPublisherInfo(pSignerInfo, &ProgPubInfo)) { if (ProgPubInfo.lpszProgramName != NULL) { wprintf(L"Program Name : %s\n", ProgPubInfo.lpszProgramName); } if (ProgPubInfo.lpszPublisherLink != NULL) { wprintf(L"Publisher Link : %s\n", ProgPubInfo.lpszPublisherLink); } if (ProgPubInfo.lpszMoreInfoLink != NULL) { wprintf(L"MoreInfo Link : %s\n", ProgPubInfo.lpszMoreInfoLink); } } _tprintf(_T("\n")); // Search for the signer certificate in the temporary // certificate store. CertInfo.Issuer = pSignerInfo->Issuer; CertInfo.SerialNumber = pSignerInfo->SerialNumber; pCertContext = CertFindCertificateInStore(hStore, ENCODING, 0, CERT_FIND_SUBJECT_CERT, (PVOID)&CertInfo, NULL); if (!pCertContext) { _tprintf(_T("CertFindCertificateInStore failed with %x\n"), GetLastError()); __leave; } // Print Signer certificate information. _tprintf(_T("Signer Certificate:\n\n")); PrintCertificateInfo(pCertContext); _tprintf(_T("\n")); // Get the timestamp certificate signerinfo structure. if (GetTimeStampSignerInfo(pSignerInfo, &pCounterSignerInfo)) { // Search for Timestamp certificate in the temporary // certificate store. CertInfo.Issuer = pCounterSignerInfo->Issuer; CertInfo.SerialNumber = pCounterSignerInfo->SerialNumber; pCertContext = CertFindCertificateInStore(hStore, ENCODING, 0, CERT_FIND_SUBJECT_CERT, (PVOID)&CertInfo, NULL); if (!pCertContext) { _tprintf(_T("CertFindCertificateInStore failed with %x\n"), GetLastError()); __leave; } // Print timestamp certificate information. _tprintf(_T("TimeStamp Certificate:\n\n")); PrintCertificateInfo(pCertContext); _tprintf(_T("\n")); // Find Date of timestamp. if (GetDateOfTimeStamp(pCounterSignerInfo, &st)) { _tprintf(_T("Date of TimeStamp : %02d/%02d/%04d %02d:%02d\n"), st.wMonth, st.wDay, st.wYear, st.wHour, st.wMinute); } _tprintf(_T("\n")); } } __finally { // Clean up. if (ProgPubInfo.lpszProgramName != NULL) LocalFree(ProgPubInfo.lpszProgramName); if (ProgPubInfo.lpszPublisherLink != NULL) LocalFree(ProgPubInfo.lpszPublisherLink); if (ProgPubInfo.lpszMoreInfoLink != NULL) LocalFree(ProgPubInfo.lpszMoreInfoLink); if (pSignerInfo != NULL) LocalFree(pSignerInfo); if (pCounterSignerInfo != NULL) LocalFree(pCounterSignerInfo); if (pCertContext != NULL) CertFreeCertificateContext(pCertContext); if (hStore != NULL) CertCloseStore(hStore, 0); if (hMsg != NULL) CryptMsgClose(hMsg); } return 0; } BOOL PrintCertificateInfo(PCCERT_CONTEXT pCertContext) { BOOL fReturn = FALSE; LPTSTR szName = NULL; DWORD dwData; __try { // Print Serial Number. _tprintf(_T("Serial Number: ")); dwData = pCertContext->pCertInfo->SerialNumber.cbData; for (DWORD n = 0; n < dwData; n++) { _tprintf(_T("%02x "), pCertContext->pCertInfo->SerialNumber.pbData[dwData - (n + 1)]); } _tprintf(_T("\n")); // Get Issuer name size. if (!(dwData = CertGetNameString(pCertContext, CERT_NAME_SIMPLE_DISPLAY_TYPE, CERT_NAME_ISSUER_FLAG, NULL, NULL, 0))) { _tprintf(_T("CertGetNameString failed.\n")); __leave; } // Allocate memory for Issuer name. szName = (LPTSTR)LocalAlloc(LPTR, dwData * sizeof(TCHAR)); if (!szName) { _tprintf(_T("Unable to allocate memory for issuer name.\n")); __leave; } // Get Issuer name. if (!(CertGetNameString(pCertContext, CERT_NAME_SIMPLE_DISPLAY_TYPE, CERT_NAME_ISSUER_FLAG, NULL, szName, dwData))) { _tprintf(_T("CertGetNameString failed.\n")); __leave; } // print Issuer name. _tprintf(_T("Issuer Name: %s\n"), szName); LocalFree(szName); szName = NULL; // Get Subject name size. if (!(dwData = CertGetNameString(pCertContext, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, NULL, NULL, 0))) { _tprintf(_T("CertGetNameString failed.\n")); __leave; } // Allocate memory for subject name. szName = (LPTSTR)LocalAlloc(LPTR, dwData * sizeof(TCHAR)); if (!szName) { _tprintf(_T("Unable to allocate memory for subject name.\n")); __leave; } // Get subject name. if (!(CertGetNameString(pCertContext, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, NULL, szName, dwData))) { _tprintf(_T("CertGetNameString failed.\n")); __leave; } // Print Subject Name. _tprintf(_T("Subject Name: %s\n"), szName); fReturn = TRUE; } __finally { if (szName != NULL) LocalFree(szName); } return fReturn; } LPWSTR AllocateAndCopyWideString(LPCWSTR inputString) { LPWSTR outputString = NULL; outputString = (LPWSTR)LocalAlloc(LPTR, (wcslen(inputString) + 1) * sizeof(WCHAR)); if (outputString != NULL) { lstrcpyW(outputString, inputString); } return outputString; } BOOL GetProgAndPublisherInfo(PCMSG_SIGNER_INFO pSignerInfo, PSPROG_PUBLISHERINFO Info) { BOOL fReturn = FALSE; PSPC_SP_OPUS_INFO OpusInfo = NULL; DWORD dwData; BOOL fResult; __try { // Loop through authenticated attributes and find // SPC_SP_OPUS_INFO_OBJID OID. for (DWORD n = 0; n < pSignerInfo->AuthAttrs.cAttr; n++) { if (lstrcmpA(SPC_SP_OPUS_INFO_OBJID, pSignerInfo->AuthAttrs.rgAttr[n].pszObjId) == 0) { // Get Size of SPC_SP_OPUS_INFO structure. fResult = CryptDecodeObject(ENCODING, SPC_SP_OPUS_INFO_OBJID, pSignerInfo->AuthAttrs.rgAttr[n].rgValue[0].pbData, pSignerInfo->AuthAttrs.rgAttr[n].rgValue[0].cbData, 0, NULL, &dwData); if (!fResult) { _tprintf(_T("CryptDecodeObject failed with %x\n"), GetLastError()); __leave; } // Allocate memory for SPC_SP_OPUS_INFO structure. OpusInfo = (PSPC_SP_OPUS_INFO)LocalAlloc(LPTR, dwData); if (!OpusInfo) { _tprintf(_T("Unable to allocate memory for Publisher Info.\n")); __leave; } // Decode and get SPC_SP_OPUS_INFO structure. fResult = CryptDecodeObject(ENCODING, SPC_SP_OPUS_INFO_OBJID, pSignerInfo->AuthAttrs.rgAttr[n].rgValue[0].pbData, pSignerInfo->AuthAttrs.rgAttr[n].rgValue[0].cbData, 0, OpusInfo, &dwData); if (!fResult) { _tprintf(_T("CryptDecodeObject failed with %x\n"), GetLastError()); __leave; } // Fill in Program Name if present. if (OpusInfo->pwszProgramName) { Info->lpszProgramName = AllocateAndCopyWideString(OpusInfo->pwszProgramName); } else Info->lpszProgramName = NULL; // Fill in Publisher Information if present. if (OpusInfo->pPublisherInfo) { switch (OpusInfo->pPublisherInfo->dwLinkChoice) { case SPC_URL_LINK_CHOICE: Info->lpszPublisherLink = AllocateAndCopyWideString(OpusInfo->pPublisherInfo->pwszUrl); break; case SPC_FILE_LINK_CHOICE: Info->lpszPublisherLink = AllocateAndCopyWideString(OpusInfo->pPublisherInfo->pwszFile); break; default: Info->lpszPublisherLink = NULL; break; } } else { Info->lpszPublisherLink = NULL; } // Fill in More Info if present. if (OpusInfo->pMoreInfo) { switch (OpusInfo->pMoreInfo->dwLinkChoice) { case SPC_URL_LINK_CHOICE: Info->lpszMoreInfoLink = AllocateAndCopyWideString(OpusInfo->pMoreInfo->pwszUrl); break; case SPC_FILE_LINK_CHOICE: Info->lpszMoreInfoLink = AllocateAndCopyWideString(OpusInfo->pMoreInfo->pwszFile); break; default: Info->lpszMoreInfoLink = NULL; break; } } else { Info->lpszMoreInfoLink = NULL; } fReturn = TRUE; break; // Break from for loop. } // lstrcmp SPC_SP_OPUS_INFO_OBJID } // for } __finally { if (OpusInfo != NULL) LocalFree(OpusInfo); } return fReturn; } BOOL GetDateOfTimeStamp(PCMSG_SIGNER_INFO pSignerInfo, SYSTEMTIME *st) { BOOL fResult; FILETIME lft, ft; DWORD dwData; BOOL fReturn = FALSE; // Loop through authenticated attributes and find // szOID_RSA_signingTime OID. for (DWORD n = 0; n < pSignerInfo->AuthAttrs.cAttr; n++) { if (lstrcmpA(szOID_RSA_signingTime, pSignerInfo->AuthAttrs.rgAttr[n].pszObjId) == 0) { // Decode and get FILETIME structure. dwData = sizeof(ft); fResult = CryptDecodeObject(ENCODING, szOID_RSA_signingTime, pSignerInfo->AuthAttrs.rgAttr[n].rgValue[0].pbData, pSignerInfo->AuthAttrs.rgAttr[n].rgValue[0].cbData, 0, (PVOID)&ft, &dwData); if (!fResult) { _tprintf(_T("CryptDecodeObject failed with %x\n"), GetLastError()); break; } // Convert to local time. FileTimeToLocalFileTime(&ft, &lft); FileTimeToSystemTime(&lft, st); fReturn = TRUE; break; // Break from for loop. } //lstrcmp szOID_RSA_signingTime } // for return fReturn; } BOOL GetTimeStampSignerInfo(PCMSG_SIGNER_INFO pSignerInfo, PCMSG_SIGNER_INFO *pCounterSignerInfo) { PCCERT_CONTEXT pCertContext = NULL; BOOL fReturn = FALSE; BOOL fResult; DWORD dwSize; __try { *pCounterSignerInfo = NULL; // Loop through unathenticated attributes for // szOID_RSA_counterSign OID. for (DWORD n = 0; n < pSignerInfo->UnauthAttrs.cAttr; n++) { if (lstrcmpA(pSignerInfo->UnauthAttrs.rgAttr[n].pszObjId, szOID_RSA_counterSign) == 0) { // Get size of CMSG_SIGNER_INFO structure. fResult = CryptDecodeObject(ENCODING, PKCS7_SIGNER_INFO, pSignerInfo->UnauthAttrs.rgAttr[n].rgValue[0].pbData, pSignerInfo->UnauthAttrs.rgAttr[n].rgValue[0].cbData, 0, NULL, &dwSize); if (!fResult) { _tprintf(_T("CryptDecodeObject failed with %x\n"), GetLastError()); __leave; } // Allocate memory for CMSG_SIGNER_INFO. *pCounterSignerInfo = (PCMSG_SIGNER_INFO)LocalAlloc(LPTR, dwSize); if (!*pCounterSignerInfo) { _tprintf(_T("Unable to allocate memory for timestamp info.\n")); __leave; } // Decode and get CMSG_SIGNER_INFO structure // for timestamp certificate. fResult = CryptDecodeObject(ENCODING, PKCS7_SIGNER_INFO, pSignerInfo->UnauthAttrs.rgAttr[n].rgValue[0].pbData, pSignerInfo->UnauthAttrs.rgAttr[n].rgValue[0].cbData, 0, (PVOID)*pCounterSignerInfo, &dwSize); if (!fResult) { _tprintf(_T("CryptDecodeObject failed with %x\n"), GetLastError()); __leave; } fReturn = TRUE; break; // Break from for loop. } } } __finally { // Clean up. if (pCertContext != NULL) CertFreeCertificateContext(pCertContext); } return fReturn; } I really have not time to do it. but I hope you got it. Saludos1 point