hql 发表于 2008-4-6 23:19:00

[求助]怎样用VBA对AutoCAD2004图纸文件进行加密?

大家好,怎样用VBA对AutoCAD2004图纸文件进行加密?手工加密只有用securityoptions命令,但文件多了太麻烦。

hql 发表于 2008-4-7 00:20:00

<p>哈,我在网上找到答案了:</p><p>Public Sub jm()<br/>Dim oSecurity As AcadSecurityParams<br/>Set oSecurity = New AcadSecurityParams<br/>With oSecurity<br/>.Action = AcadSecurityParamsType.ACADSECURITYPARAMS_ENCRYPT_DATA<br/>.Algorithm = AcadSecurityParamsConstants.ACADSECURITYPARAMS_ALGID_RC4<br/>.Comment = "My test"<br/>.Issuer = "MTuersley"<br/>.KeyLength = 40<br/>.Password = UCase("mypassword")<br/>.ProviderName = "Microsoft Base Cryptographic Provider v1.0"<br/>.ProviderType = 1<br/>.TimeServer = ""<br/>End With<br/>ActiveDocument.SaveAs "C:\MyDrawing.dwg", , oSecurity<br/>End Sub</p><p>谢谢网上的牛人</p>

hql 发表于 2008-4-7 13:44:00

<p>Delphi版:</p><p>unit Unit1;</p><p>interface</p><p>uses<br/>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br/>&nbsp; Dialogs, StdCtrls, ComObj, AutoCAD_TLB;</p><p>type<br/>&nbsp; TForm1 = class(TForm)<br/>&nbsp;&nbsp;&nbsp; Button1: TButton;<br/>&nbsp;&nbsp;&nbsp; Button2: TButton;<br/>&nbsp;&nbsp;&nbsp; Label1: TLabel;<br/>&nbsp;&nbsp;&nbsp; Button3: TButton;<br/>&nbsp;&nbsp;&nbsp; procedure Button1Click(Sender: TObject);<br/>&nbsp;&nbsp;&nbsp; procedure Button2Click(Sender: TObject);<br/>&nbsp;&nbsp;&nbsp; procedure Button3Click(Sender: TObject);<br/>&nbsp; private<br/>&nbsp;&nbsp;&nbsp; { Private declarations }<br/>&nbsp;&nbsp;&nbsp; acadapp:AcadApplication;<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp; public<br/>&nbsp;&nbsp;&nbsp; { Public declarations }<br/>&nbsp; end;</p><p>var<br/>&nbsp; Form1: TForm1;</p><p>implementation</p><p>{$R *.dfm}</p><p>{连接到AutoCAD}<br/>procedure TForm1.Button1Click(Sender: TObject);<br/>begin<br/>&nbsp; acadapp:=GetActiveOleObject('AutoCAD.Application') as AcadApplication;<br/>end;</p><p>{加密AutoCAD图形文件}<br/>procedure TForm1.Button2Click(Sender: TObject);<br/>var<br/>&nbsp; lx:AcadSecurityParams;<br/>begin<br/>&nbsp; lx:=acadapp.GetInterfaceObject('AutoCAD.SecurityParams.16') as AcadSecurityParams;<br/>&nbsp; lx.Action:=ACADSECURITYPARAMS_ENCRYPT_DATA;<br/>&nbsp; lx.Algorithm:=ACADSECURITYPARAMS_ALGID_RC4;<br/>&nbsp; lx.Comment:='My test';<br/>&nbsp; lx.Issuer:='MTuersley';<br/>&nbsp; lx.KeyLength:=40;<br/>&nbsp; lx.Password:=UpperCase('abc');<br/>&nbsp; lx.ProviderName:='Microsoft Base Cryptographic Provider v1.0';<br/>&nbsp; lx.ProviderType:=1;<br/>&nbsp; lx.TimeServer:='';<br/>&nbsp; acadapp.ActiveDocument.SaveAs('c:\1.dwg',ac2004_dwg,lx);<br/>end;</p><p>{打开加密文件}<br/>procedure TForm1.Button3Click(Sender: TObject);<br/>begin<br/>&nbsp; acadapp.Documents.Open('c:\1.dwg',1,'abc');<br/>end;</p><p>end.<br/></p>

yxr_MJTD 发表于 2008-4-16 10:46:00

<p>请问楼主,这样加密后还可以打开浏览吗?</p><p>有没有这样的代码可以给我一个吗?</p><p></p>
页: [1]
查看完整版本: [求助]怎样用VBA对AutoCAD2004图纸文件进行加密?