Try this code (minimum testing with AutoCAD 2012 x86):
using System;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
// This line is not mandatory, but improves loading performances
[assembly: CommandClass(typeof(Rivilis.ClearPassword))]
namespace Rivilis
{
// This class is instantiated by AutoCAD for each document when
// a command is called by the user the first time in the context
// of a given document. In other words, non static data in this class
// is implicitly per-document!
public class ClearPassword
{
[StructLayout(LayoutKind.Sequential)]
// From dbsecurity.h
public struct SecurityParams
{
public uint cbSize;
public uint ulFlags; // see enum above for flag values
// data relevant to password protection
public string wszPassword;
public uint ulProvType;
public string wszProvName;
public uint ulAlgId; // SECURITYPARAMS_ALGID_RC4
public uint ulKeyLength;
// data relevant to digital signatures
public string wszCertSubject;
public string wszCertIssuer;
public string wszCertSerialNum;
public string wszComment;
public string wszTimeServer;
};
[DllImport("acdb18.dll", CallingConvention = CallingConvention.ThisCall,
EntryPoint = "?setSecurityParams@AcDbDatabase@@QAE_NPBUSecurityParams@@_N@Z")]
static extern private bool setSecurityParamsX32(IntPtr db, ref SecurityParams pSecParams, bool bSetDbMod = true);
[DllImport("acdb18.dll", CallingConvention = CallingConvention.ThisCall,
EntryPoint = "?setSecurityParams@AcDbDatabase@@QEAA_NPEBUSecurityParams@@_N@Z")]
static extern private bool setSecurityParamsX64(IntPtr db, ref SecurityParams pSecParams, bool bSetDbMod = true);
static public bool setSecurityParams(Database db, ref SecurityParams parms, bool bSetDbMod = true)
{
if (IntPtr.Size == 4) return setSecurityParamsX32(db.UnmanagedObject, ref parms, bSetDbMod);
else return setSecurityParamsX64(db.UnmanagedObject, ref parms, bSetDbMod);
}
[CommandMethod("ClearPWD", CommandFlags.Modal)]
public void ClearPWD()
{
Database db = HostApplicationServices.WorkingDatabase;
SecurityParams parms = new SecurityParams();
parms.cbSize = (uint)Marshal.SizeOf(parms);
parms.ulFlags = 0; // Clear security flag
setSecurityParams(db, ref parms);
}
}
}
For VB.NET you can convert C# code: http://www.developerfusion.com/tools/convert/csharp-to-vb/
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
