ObjectARX

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

any way to remove password from a dwg

822 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!
Distinguished Mentor
owenwengerd
Posts: 594
Registered: ‎08-06-2002
Message 2 of 9 (819 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: 159
Registered: ‎10-21-2010
Message 3 of 9 (803 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,389
Registered: ‎04-09-2008
Message 4 of 9 (801 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: 159
Registered: ‎10-21-2010
Message 5 of 9 (799 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,389
Registered: ‎04-09-2008
Message 6 of 9 (796 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: 159
Registered: ‎10-21-2010
Message 7 of 9 (792 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,389
Registered: ‎04-09-2008
Message 8 of 9 (786 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: 159
Registered: ‎10-21-2010
Message 9 of 9 (782 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!

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community