powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Microsoft Office [игнор отключен] [закрыт для гостей] / ПРОГРАММНО добавить цифровую подпись к документу
6 сообщений из 6, страница 1 из 1
ПРОГРАММНО добавить цифровую подпись к документу
    #34118707
toc4875834758
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Я программно создаю документ. Хочу добавить к нему ЭЦП.

Можно ли ПРОГРАММНО добавить цифровую подпись к ворд документу?
how to programmatically Add signature to the word document?


ActiveDocument.Signatuires.Add - всего лишь отображает диалог.
...
Рейтинг: 0 / 0
ПРОГРАММНО добавить цифровую подпись к документу
    #34118859
Фотография orunbek
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Вот из сайта http://office.microsoft.com/en-us/ork2003/HA011403191033.aspx
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
Function AddSignature(ByVal strIssuer As String, strSigner As String) As Boolean
    On Error GoTo Error_Handler
    Dim sig As Signature
    'Display a dialog to the user with a list of digital signatures.
    'If the user selects a signature, then add it to the Signatures 
    'collection. If a selection is not made an error is returned.

    Set sig = ActiveDocument.Signatures.Add

    'Test the following properties before committing a Signature object
    'to disk.
    If sig.Issuer = strIssuer And sig.Signer = strSigner And _
        sig.IsCertificateExpired = False And _
        sig.IsCertificateRevoked = False And sig.IsValid = True Then
        MsgBox "Signed"
        AddSignature = True
    Else
    'Remove the Signature object from the SignatureSet collection.
        sig.Delete
        MsgBox "Not signed"
        AddSignature = False
    End If
    'Commit all signatures in the SignatureSet collection 
    'to the disk.
    ActiveDocument.Signatures.Commit
    Exit Function
Error_Handler:
    AddSignature = False
    MsgBox "Action cancelled."
End Function
http://%5D%5B/url]http://]
...
Рейтинг: 0 / 0
ПРОГРАММНО добавить цифровую подпись к документу
    #34118871
Фотография orunbek
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
но это полуавтоматом
...
Рейтинг: 0 / 0
ПРОГРАММНО добавить цифровую подпись к документу
    #34119030
toc4875834758
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
orunbek,

читал. Мне это не нужно.
...
Рейтинг: 0 / 0
ПРОГРАММНО добавить цифровую подпись к документу
    #34119162
Фотография orunbek
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
toc4875834758orunbek,

читал. Мне это не нужно.
так и думал ;)
...
Рейтинг: 0 / 0
Период между сообщениями больше года.
ПРОГРАММНО добавить цифровую подпись к документу
    #35724207
toc4875834758
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
http://answers.google.com/answers/threadview?id=541227
karflips33-ga
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.


Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
'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
...
Рейтинг: 0 / 0
6 сообщений из 6, страница 1 из 1
Форумы / Microsoft Office [игнор отключен] [закрыт для гостей] / ПРОГРАММНО добавить цифровую подпись к документу
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]