none
Validating Ms Word Signatures from vb.Net application RRS feed

  • Question

  • I am trying to validate digital signatures contained in a Ms Word Document from a vb.Net Windows Forms Application. I am using Office Automation with late binding: wordApplication = CreateObject("Word.Application") .

    I managed to retrieve a number of properties for each signature of the Word document e.g. Issuer, Signer, IsCertificateExpired from the Signature object and even more properties e.g. SignatureComment, SignatureText from the Signature.SignatureInfo object.

    However, I didn't manage to retrieve further information e.g. SuggestedSigner from the Signature.Setup object. I noticed that the property Signature.CanSetup returns false. If I insert a breakpoint and wait for a while the Signature.CanSetup property returns true and then the value Signature.Setup.SuggestedSigner is available.

    I tried to insert a loop delaying the execution but it didn't work. I noticed that in order for the property Signature.Setup.SuggestedSigner to be available the program must enter debug mode and shift the focus to Word Application for a while.

    I assume that a Word background process is idle and only when the Word windows is activated it starts to work and as a consequence the property becomes Signature.Setup.SuggestedSigner available and the property Signature.CanSetup returns true.

    Any help would be greatly appreciated.

    Regards,

    Nikolaos Nikolaou

    Friday, August 26, 2016 12:09 PM

All replies

  • it's impossible to mimic your situation without code and certificate but can you try to insert

    Application.ScreenUpdating = False

    <do something in VBA code>

    Application.ScreenUpdating = True


    Best regards, George

    Friday, August 26, 2016 3:24 PM
  • Hi NPNikolaou,

    you had mentioned that when you wait for some time it is available. can you able to access the suggested signer value?

    I don't know how you are trying to access it.

    Generally in the VB.Net it uses Microsoft.Office.core

    and it returns the string value.

    below is an syntax example of that.

    'Declaration
    <DispIdAttribute()> _
    Property SuggestedSigner As String
    	Get
    	Set
    'Usage
    Dim instance As SignatureSetup
    Dim value As String
    
    value = instance.SuggestedSigner
    
    instance.SuggestedSigner = value
    

    For further information regarding this topic please visit the link below.

    SignatureSetup.SuggestedSigner property

    SignatureSetup.SuggestedSigner Property (Office)

    if you need any further assistance then please try to provide a sample demo code to reproduce the issue on our side.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, August 29, 2016 2:29 AM
    Moderator
  • Dear Deepak,

    thank you for your reply. I have created a very simple sample project illustrating the issue I am referring to. I have also included a test signed document for your test. Please note that in the source code you have to change  the path location of the word document.

    When I run the sample project it throws an exception. If a transfer the focus to the word application, wait for a while and then return to the debugger and choose to continue the execution the program completes succesfully.

    I also noticed that if the document is smaller this issue doesn't arise, that is why I have added sample content from wikipedia.

    Unfortunaterly I have no way to upload the project. Please advise me if there is anything I am missing.

    Thank you in advance for your help.

    Kind Regards,

    Nikolaos Nikolaou


    • Edited by NPNikolaou Wednesday, August 31, 2016 11:48 AM
    Wednesday, August 31, 2016 11:01 AM
  • Dear Deepak,

    thank you for your reply. I have created a very simple sample project illustrating the issue I am referring to. I have also included a test signed document for your test. Please note that in the source code you have to change  the path location of the word document.

    When I run the sample project it throws an exception. If a transfer the focus to the word application, wait for a while and then return to the debugger and choose to continue the execution the program completes succesfully.

    I also noticed that if the document is smaller this issue doesn't arise, that is why I have added sample content from wikipedia.

    Unfortunaterly I have no way to upload the project. Please advise me if there is anything I am missing.

    Thank you in advance for your help.

    Kind Regards,

    Nikolaos Nikolaou

    Wednesday, August 31, 2016 11:49 AM
  • Hi NPNikolaou,

    you can use free Sharing and uploading websites like dropbox. there are many this kind of websites available.

    you can upload your project there and then you need to share the link of uploaded project here in this thread.

    so that we can try to download it and test it.

    Hope it helps to you to understand how you can share your demo test solution with us.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, September 1, 2016 3:13 AM
    Moderator
  • Dear Deepak,

    thank you for your reply.

    Please find below the link to the sample project I have created. In the zip file a signed Word document is also included.

       http://www.filedropper.com/testwordproject_1

    Best Regards,

    N. Nikolaou

    Thursday, September 1, 2016 4:21 AM
  • Hi NPNikolaou,

    I am facing some problem with your file and with your solution.\

    First of all if we talk about solution then it is created in vs2008. but I am using vs2016.

    The project is not compatible with vs2016 and I am not available with vs2008.

    I try to migrate the solution from 2008 to 2016 but it giving some errors.

    if we talk about your file then when I double click on file. word shows that it is open in the taskbar. but when I click on it. it's not showing me and doesn't get focused.

    I can view the content of file in preview of file explorer.

    is it any problem with file? is it behaving same at your side?

    if so then I suggest you to create a new file and test it with your code. it is possible that it is affecting the execution of your project.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, September 1, 2016 7:36 AM
    Moderator
  • Dear Deepak,

    thanks once again for your reply.

    I updated the project to VS2015. Please find below the link for the updated project as well as the sample Word document.

      http://www.filedropper.com/testwordproject_2

    I tried the Word document on my side and it opens propertly. Perhaps you need to Unblock the file from the properties dialog box of windows explorer.

    Regards,

    N. Nikolaou


    • Edited by NPNikolaou Thursday, September 1, 2016 12:32 PM
    Thursday, September 1, 2016 12:31 PM
  • Hi NPNikolaou,

    I test your code and reproduce the same behavior of code like you.

    As you had mentioned if we focus the word manually then the code works correctly and error will not raise.

    so I try to set the focus using code . I set the focus to word just before error raise in the code and I also try to set the focus to word after opening the document. but in both ways issue not solved and error still occurs.

    you can try to look in to the code that I modified.

    Module basMainModule
        Const wordClassName As String = "OpusApp"
        Declare Function SetForegroundWindow Lib "User32.dll" Alias "SetForegroundWindow" (ByVal hWnd As IntPtr) As Boolean
        Declare Function FindWindow Lib "User32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
    
        Sub Main()
            'Dim wordApp As Word.Application = Nothing
            'Dim wordDoc As Word.Document = Nothing
    
            Debug.Print(">>> Start of program")
    
            ' Word Object Variables
            Dim wordApplication As Object
            Dim wordDocument As Object
    
            Dim wordSignature As Object
    
            wordApplication = CreateObject("Word.Application") ' New Word.Application
            wordApplication.DisplayAlerts = False
            wordApplication.Visible = True
            wordApplication.WindowState = 1 ' wdWindowStateMinimize
    
            ' Please change the path before running
            wordDocument = wordApplication.Documents.Open(Filename:="C:\Users\v-padee\Desktop\TestWordProject1\TestWordProject\Test signed Word Document.docx", ReadOnly:=True)
    
            wordSignature = wordDocument.Signatures.Item(1)
    
            Debug.Print(">>> wordSignature.Issuer: " & wordSignature.Issuer)
            Dim hWndWord As IntPtr = FindWindow(wordClassName, wordApplication.Caption)
            ' Set the focus
            Dim bResult As Boolean = SetForegroundWindow(hWndWord)
    
            Debug.Print(">>> wordSignature.Setup.SuggestedSigner: " & wordSignature.Setup.SuggestedSigner())
    
            Debug.Print(">>> End of program")
    
        End Sub
    
    End Module
      

    so here at first it looks like issue is related with Focusing the word application. but may be it's something different.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, September 2, 2016 5:56 AM
    Moderator
  • Hi NPNikolaou,

    is your issue solved? or you are still facing the problem?

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, September 12, 2016 9:17 AM
    Moderator
  • Dear Despair,

    Thank you for your support.

    Unfortunately so far I haven't find a solution.

    Any idea is welcomed.

    Regards,

    Nikolaos Nikolaou

    Monday, September 12, 2016 7:01 PM
  • Hi  NPNikolaou,

    I will try to report this issue to Word User Voice Team internally and try to submit the feedback given by you regarding this issue.

    if they have any solution regarding this issue I will provide you.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, September 15, 2016 9:00 AM
    Moderator
  • Dear Deepak, once again I would like to thank you for your reply. I am looking forward for your response. Kind Regards, Nikolaos Nikolaou
    Thursday, September 15, 2016 7:29 PM