ObjectARX

Reply
Distinguished Contributor
421232206
Posts: 164
Registered: ‎10-21-2010
Message 1 of 9 (932 Views)
Accepted Solution

any way to remove password from a dwg

932 Views, 8 Replies
04-23-2012 08:33 PM

I want to remove password from dwgs whose password is know.  I can open these dwgs by known pasword, but I can't find a way to save them without password.

 

        SecurityParams secParams;
        {
            secParams.cbSize = 48;
            secParams.ulFlags = 1;
            secParams.ulProvType = 1;
            secParams.ulAlgId = 26625;
            secParams.ulKeyLength = 40;
            secParams.wszPassword = szPassword;//if I give NULL to this param, the "saveAs" method crushes.
            secParams.wszProvName = _T("Microsoft Base Cryptographic Provider v1.0");
        }

     es = pDb->saveAs(szFileName,&secParams);// I want to remove their passsword

 

Technology change world! Coding change technology! We coders are coding!

OK. Working code:

static bool RemovePasswordProtection(AcDbDatabase *pDb)
{
const SecurityParams *parSecOld = pDb->cloneSecurityParams();
SecurityParams parSecNew = *parSecOld;
parSecNew.ulFlags = 0; // Clear all security flags
return (pDb->setSecurityParams(&parSecNew));
}
// Main function remove password from current drawing
static void PWDRemovePwd(void)
{
AcDbDatabase *pCurDb = acdbCurDwg();
AcApDocument *pCurDoc = curDoc();
RemovePasswordProtection(pCurDb);
pCurDb->saveAs(pCurDoc->fileName(),NULL);
}

 

Distinguished Mentor
owenwengerd
Posts: 642
Registered: ‎08-06-2002
Message 2 of 9 (929 Views)

Re: any way to remove password from a dwg

04-23-2012 09:09 PM in reply to: 421232206

Pass NULL for the second argument to saveAs().

--
Owen Wengerd
ManuSoft
Distinguished Contributor
421232206
Posts: 164
Registered: ‎10-21-2010
Message 3 of 9 (913 Views)

Re: any way to remove password from a dwg

04-25-2012 12:48 AM in reply to: owenwengerd

thanks, but are you sure? I tried the following code,  it dosen't work. The password of the dwg still exists.

          

             AcDbDatabase* pDb = new AcDbDatabase(false);
            Acad::ErrorStatus es = pDb->readDwgFile(iterS->c_str(),_SH_DENYWR,false,szOldPassword);
            if (Acad::eOk == es)
            {
                if (_tcscmp(szPassword,_T("")) == 0)
                {
                    es = pDb->saveAs(iterS->c_str(),NULL);
                }
                else
                {
                    es = pDb->saveAs(iterS->c_str(),&secParams);
                }
                
                if (Acad::eOk == es ) ++nCount;
            }

Technology change world! Coding change technology! We coders are coding!
Moderator
Alexander.Rivilis
Posts: 1,430
Registered: ‎04-09-2008
Message 4 of 9 (911 Views)

Re: any way to remove password from a dwg

04-25-2012 12:58 AM in reply to: 421232206

Try:

secParams.wszPassword =_T("");

 

 

 


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Distinguished Contributor
421232206
Posts: 164
Registered: ‎10-21-2010
Message 5 of 9 (909 Views)

Re: any way to remove password from a dwg

04-25-2012 01:06 AM in reply to: Alexander.Rivilis

CAD enters dead loop, If I pass an empty string(not null) .

Technology change world! Coding change technology! We coders are coding!
Moderator
Alexander.Rivilis
Posts: 1,430
Registered: ‎04-09-2008
Message 6 of 9 (906 Views)

Re: any way to remove password from a dwg

04-25-2012 01:11 AM in reply to: 421232206

What about save dwg with other filename without password?

There is a method AcDbDatabase::setSecurityParams. Try pass NULL to it.


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Distinguished Contributor
421232206
Posts: 164
Registered: ‎10-21-2010
Message 7 of 9 (902 Views)

Re: any way to remove password from a dwg

04-25-2012 01:24 AM in reply to: Alexander.Rivilis

I tried, "save as" with a new file name, but the new dwg still has the same password from the old dwg.

Technology change world! Coding change technology! We coders are coding!
Moderator
Alexander.Rivilis
Posts: 1,430
Registered: ‎04-09-2008
Message 8 of 9 (896 Views)

Re: any way to remove password from a dwg

04-25-2012 02:01 AM in reply to: 421232206

OK. Working code:

static bool RemovePasswordProtection(AcDbDatabase *pDb)
{
    const SecurityParams *parSecOld = pDb->cloneSecurityParams();
    SecurityParams parSecNew = *parSecOld;
    parSecNew.ulFlags = 0; // Clear all security flags
    return (pDb->setSecurityParams(&parSecNew));
}
// Main function remove password from current drawing
static void PWDRemovePwd(void)
{
    AcDbDatabase *pCurDb  = acdbCurDwg();
    AcApDocument *pCurDoc = curDoc();
    RemovePasswordProtection(pCurDb);
    pCurDb->saveAs(pCurDoc->fileName(),NULL);
}

 


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Distinguished Contributor
421232206
Posts: 164
Registered: ‎10-21-2010
Message 9 of 9 (892 Views)

Re: any way to remove password from a dwg

04-25-2012 02:23 AM in reply to: Alexander.Rivilis

thanks so much. It did work.  I noticed that cad  automatically remembers password , but found no way to remove this mechanism.

Technology change world! Coding change technology! We coders are coding!
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.