[求助]怎样用VBA对AutoCAD2004图纸文件进行加密?
大家好,怎样用VBA对AutoCAD2004图纸文件进行加密?手工加密只有用securityoptions命令,但文件多了太麻烦。 <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> <p>Delphi版:</p><p>unit Unit1;</p><p>interface</p><p>uses<br/> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br/> Dialogs, StdCtrls, ComObj, AutoCAD_TLB;</p><p>type<br/> TForm1 = class(TForm)<br/> Button1: TButton;<br/> Button2: TButton;<br/> Label1: TLabel;<br/> Button3: TButton;<br/> procedure Button1Click(Sender: TObject);<br/> procedure Button2Click(Sender: TObject);<br/> procedure Button3Click(Sender: TObject);<br/> private<br/> { Private declarations }<br/> acadapp:AcadApplication;<br/> <br/> public<br/> { Public declarations }<br/> end;</p><p>var<br/> Form1: TForm1;</p><p>implementation</p><p>{$R *.dfm}</p><p>{连接到AutoCAD}<br/>procedure TForm1.Button1Click(Sender: TObject);<br/>begin<br/> acadapp:=GetActiveOleObject('AutoCAD.Application') as AcadApplication;<br/>end;</p><p>{加密AutoCAD图形文件}<br/>procedure TForm1.Button2Click(Sender: TObject);<br/>var<br/> lx:AcadSecurityParams;<br/>begin<br/> lx:=acadapp.GetInterfaceObject('AutoCAD.SecurityParams.16') as AcadSecurityParams;<br/> lx.Action:=ACADSECURITYPARAMS_ENCRYPT_DATA;<br/> lx.Algorithm:=ACADSECURITYPARAMS_ALGID_RC4;<br/> lx.Comment:='My test';<br/> lx.Issuer:='MTuersley';<br/> lx.KeyLength:=40;<br/> lx.Password:=UpperCase('abc');<br/> lx.ProviderName:='Microsoft Base Cryptographic Provider v1.0';<br/> lx.ProviderType:=1;<br/> lx.TimeServer:='';<br/> acadapp.ActiveDocument.SaveAs('c:\1.dwg',ac2004_dwg,lx);<br/>end;</p><p>{打开加密文件}<br/>procedure TForm1.Button3Click(Sender: TObject);<br/>begin<br/> acadapp.Documents.Open('c:\1.dwg',1,'abc');<br/>end;</p><p>end.<br/></p> <p>请问楼主,这样加密后还可以打开浏览吗?</p><p>有没有这样的代码可以给我一个吗?</p><p></p>
页:
[1]