明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1764|回复: 3

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

[复制链接]
发表于 2008-4-6 23:19:00 | 显示全部楼层 |阅读模式
大家好,怎样用VBA对AutoCAD2004图纸文件进行加密?手工加密只有用securityoptions命令,但文件多了太麻烦。
 楼主| 发表于 2008-4-7 00:20:00 | 显示全部楼层

哈,我在网上找到答案了:

Public Sub jm()
Dim oSecurity As AcadSecurityParams
Set oSecurity = New AcadSecurityParams
With oSecurity
.Action = AcadSecurityParamsType.ACADSECURITYPARAMS_ENCRYPT_DATA
.Algorithm = AcadSecurityParamsConstants.ACADSECURITYPARAMS_ALGID_RC4
.Comment = "My test"
.Issuer = "MTuersley"
.KeyLength = 40
.Password = UCase("mypassword")
.ProviderName = "Microsoft Base Cryptographic Provider v1.0"
.ProviderType = 1
.TimeServer = ""
End With
ActiveDocument.SaveAs "C:\MyDrawing.dwg", , oSecurity
End Sub

谢谢网上的牛人

 楼主| 发表于 2008-4-7 13:44:00 | 显示全部楼层

Delphi版:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComObj, AutoCAD_TLB;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Label1: TLabel;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
    acadapp:AcadApplication;
   
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{连接到AutoCAD}
procedure TForm1.Button1Click(Sender: TObject);
begin
  acadapp:=GetActiveOleObject('AutoCAD.Application') as AcadApplication;
end;

{加密AutoCAD图形文件}
procedure TForm1.Button2Click(Sender: TObject);
var
  lx:AcadSecurityParams;
begin
  lx:=acadapp.GetInterfaceObject('AutoCAD.SecurityParams.16') as AcadSecurityParams;
  lx.Action:=ACADSECURITYPARAMS_ENCRYPT_DATA;
  lx.Algorithm:=ACADSECURITYPARAMS_ALGID_RC4;
  lx.Comment:='My test';
  lx.Issuer:='MTuersley';
  lx.KeyLength:=40;
  lx.Password:=UpperCase('abc');
  lx.ProviderName:='Microsoft Base Cryptographic Provider v1.0';
  lx.ProviderType:=1;
  lx.TimeServer:='';
  acadapp.ActiveDocument.SaveAs('c:\1.dwg',ac2004_dwg,lx);
end;

{打开加密文件}
procedure TForm1.Button3Click(Sender: TObject);
begin
  acadapp.Documents.Open('c:\1.dwg',1,'abc');
end;

end.

发表于 2008-4-16 10:46:00 | 显示全部楼层

请问楼主,这样加密后还可以打开浏览吗?

有没有这样的代码可以给我一个吗?

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-26 08:36 , Processed in 0.160253 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表