Automatically signing a word document.

Hi, we're trying to make a document management setup in .Net 1.1 (we're not using 2.0 yet) . Where every outgoing document has to be signed by us and then signed again by the client for acceptance of the conditions.

Now the problem is that we would like to automate our signing process
(The clients sign using the built-in signature dialog in MS Word)

Right now we have these code snippets that handle the signing:

Word.Document aDoc ... // initialization etc
aDoc.Signatures.Add();
aDoc.Signatures.Commit();

At the moment we add the signature, the standard word dialog pops up asking us with which certificate we want to sign. Which is offcourse not what we want.

Now my question is is there any way we can get rid of that dialog and automatically sign using the first signature.

Or to manually calculate and insert the signature within the doc file. While remaining compatible with the word implementation.



Answer this question

Automatically signing a word document.

  • ss23

    Seems like you can not prevent the dialog from showing up, but you can programmatically click an OK button on the dialog which will accept the first signature. To achieve this you will need to spin up a thread before the doc.Signatures.Add call. The thread will wait for the dialog to show up and then will dismiss it.

    I do not have specific code handy but the idea is like this

    a) find out the window handle with FindWindow(). The caption and class name
    of the dialog box can be found out with Spy.
    b) SendMessage(hWnd,WM_COMMAND,IDOK,0)
    This simulates an OK click.



  • 虫豸

    Where did you find these code snippets I'm interested in this too.
    Thanks.

  • Automatically signing a word document.