473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Word 2003 and Digital Signatures

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.
Any suggestions gratefully received.

Nov 21 '05 #1
1 2887
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

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Guangxi Wu | last post by:
Hi all, Happy New Year. I am using SignedXML and an X509 certificate to digitally sign a SOAP message body and put the signature in the SOAP header for a B2B business application. Can you...
5
by: John Campbell | last post by:
Hi everyone I've been doing my best to understand the specifics of implimentating XML Digital Signatures, but I seem to be missing a fundamental concept. Let me start with a description of the...
0
by: Bradley Ward | last post by:
I have been searching and searching online for code examples of using both ..net framework and also WSE 2.0 classes to digitally sign a SOAP document and then verify the document. I got a few...
0
by: CLarkou | last post by:
I bought a digital signature for my MSaccess application in Office 2003. I select TOOLS\Digital Signatures in Visual Basic Editor and I am not able to see my digital signature in the available...
1
by: a94ws7 | last post by:
I am trying to automate a digital signature process with Microsoft Word, I have experimented by loading the word document into word and then from there placing that document inside a picturebox so...
6
by: simon | last post by:
I created an access database and digitally signed it. I then gave a copy of this Database to a friend. A few months later he wanted me to make some changes to it so i took an up-to-date copy from...
6
by: BillCo | last post by:
I've been working to date almost exclusively with a2k, but it looks like i need to move a major app to 2003. I've heard that there are various complications surrounding Digital signatures and...
1
by: ckpoll2 | last post by:
Hi, I have a rookie question for you. I have a database where people create a form that has to be signed. Rather than print off a hard copy, I'd like the spot for the signature to have a digital...
5
by: troy_lee | last post by:
We have an application developed by one developer. He compiled the database into an application and digitally signed the application. He doesn't know if he used selfcert of makecert to make the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.