Google Answers Logo
View Question
 
Q: Word 2003 and Digital Signatures ( No Answer,   2 Comments )
Question  
Subject: Word 2003 and Digital Signatures
Category: Computers
Asked by: karflips33-ga
List Price: $10.00
Posted: 08 Jul 2005 06:34 PDT
Expires: 14 Jul 2005 01:10 PDT
Question ID: 541227
Is it possible to automate the signing of Word 2003 docs with 
Digital Signatures? 

My problem with the code approach using 

ActiveDocument.Signatures.Add 

is that Word comes up with a prompt. Obviously this is no good 
when trying to automate document creation, etc. 

There doesn't appear to be any way to specify a particular 
certificate, or to suppress the prompt. 

I assume there must be some way to add digital signatures to 
Word 2003 docs thru code, but how? 

I am using VB.Net to automate Word.

Clarification of Question by karflips33-ga on 08 Jul 2005 09:59 PDT
I've seen that article.

No offence, but it's useless from a development perspective.

The article claims to show you how to "Programmatically Sign 
a Document", what it really shows you is how to programmatically
display a prompt.

It's fine if you want to digitally sign one doc, but what if
you want to sign 10,000?
Answer  
There is no answer at this time.

Comments  
Subject: Re: Word 2003 and Digital Signatures
From: dreamboat-ga on 08 Jul 2005 09:48 PDT
 
Try this:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnword2k2/html/odc_wdds.asp
Subject: Re: Word 2003 and Digital Signatures
From: karflips33-ga on 14 Jul 2005 01:08 PDT
 
Well, after several days of sweat and tears I've finally come up with something.

It's almost the hackiest code I've ever written but it works. If anyone comes
up with something better, please post it.

In the end I run the ActiveDocument.Signatures.Add code as normal and then 
"hit enter" from another thread, making sure to direct the keystroke to the
correct window.


'waiting for certificate prompt to be shown
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

'API declarations, etc that allow us to talk directly to our running
instance of Word
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Int32
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA"
(ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32,
ByVal lParam As Int32) As Int32
Public Const WM_CHAR = &H102
Public Const VK_RETURN = &HD
Public Const WM_KEYDOWN = &H100
Public Const WM_KEYUP = &H101
Public rc As Int32


sub SignDoc()

wrdApp.Documents.Open(drContracts("DocLocation"))

'''
'
'We want to digitally sign the doc, make it read only for the client
Dim sig As Microsoft.Office.Core.Signature
Dim t As WordSignatureDelegate
t = AddressOf WordSignature
If blnFirstRun Then
    t.BeginInvoke(True, Nothing, Nothing)
Else
    t.BeginInvoke(False, Nothing, Nothing)
End If

Logger.Write("Attempting to add signature to : " & drContracts("DocLocation"))
sig = wrdApp.ActiveDocument.Signatures.Add
sig.AttachCertificate = True
wrdApp.ActiveDocument.Signatures.Commit()
Logger.Write("Signature added to : " & impDealRef)

'
'''

wrdApp.ActiveDocument.Close()

End Sub

Public Delegate Sub WordSignatureDelegate(ByVal blnFirstRun As Boolean)

Public Sub WordSignature(ByVal blnFirstRun As Boolean)

Dim intHandle As Int32

	Sleep(5000) 'wait for Signatures.Add to run

	intHandle = FindWindow("#32770", "select certificate")
	rc = PostMessage(intHandle, WM_KEYDOWN, 13, 0)
	rc = PostMessage(intHandle, WM_KEYUP, 13, 0)

	'on the first run, we need to hit enter twice
	If blnFirstRun Then
	Sleep(5000) 'wait for next dialog to show

	intHandle = FindWindow("#32770", "Signing data with your private exchange key")
	rc = PostMessage(intHandle, WM_KEYDOWN, 13, 0)
	rc = PostMessage(intHandle, WM_KEYUP, 13, 0)
	End If
End Sub

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy