Home |
Search |
Today's Posts |
|
#1
![]() |
|||
|
|||
![]()
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. |
#2
![]() |
|||
|
|||
![]()
As far as I know, this isn't possible. If one could sign
documents through code, then a digital signature might not be worth very much? In any case, this is an end-user newsgroup. A better place to ask this type of question would be one of the office.developer groups. 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. Cindy Meister INTER-Solutions, Switzerland http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004) http://www.word.mvps.org This reply is posted in the Newsgroup; please post any follow question or reply in the newsgroup and not by e-mail :-) |
#3
![]() |
|||
|
|||
![]()
Don't see how signing a doc thru code is any less secure.
You still need a certificate, just using code to remove the grunt work of signing individual docs. For example, see signcode.exe. It's a command line tool that allows signing code (dlls, exe, etc). This could easily be automated if one was so inclined. Wonder why there is no comparable tool for signing other files, incl ..doc? |
#4
![]() |
|||
|
|||
![]()
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 |
#5
![]() |
|||
|
|||
![]()
If you want help to refine your code, you would do better to post in one of
the word.vba NGs. If you read even a small sampling of the posts here, you would realize that this is an end-user NG that primarily deals with the most basic of questions. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA Word MVP FAQ site: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. wrote in message oups.com... 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 |
#6
![]() |
|||
|
|||
![]()
Just after any kind of input, even a debate on Microsoft's choice to
implement signatures in this way. End users with extensive experience might know of or have heard of an angle. |
Reply |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Macros Disabled | Microsoft Word Help | |||
How do I prevent unauthorized copying of sections of Word doc? | Microsoft Word Help | |||
Macro Security | Microsoft Word Help | |||
Ink Annotate on Windows XP word 2003 | Microsoft Word Help | |||
Word 2003 User's Guide | New Users |