Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Giving a new pst password to a Profile

7 views
Skip to first unread message

financ...@gmail.com

unread,
Dec 12, 2007, 5:14:11 AM12/12/07
to
Hello

I am using Outlook 2003 and trying to set the password of a pst file.
The profile and its pst file already exists and I am trying to set a
password to this already existing pst file. I am using the following
code, but failing to set the password. Also, ConfigureMsgService()
doesnt give me any error so as to debug the issue, can anybody help
please.

HRESULT hr = S_OK;
LPSPropValue aPropVals = NULL;
LPSRowSet lpRows = NULL;
LPMAPITABLE lpTable = NULL;
LPPROFADMIN lpProfAdmin = NULL;
LPSERVICEADMIN lpSvcAdmin = NULL;
MAPIUID MsgStoreUID ;

LPSTR lpszProfileName = "sample";
LPSTR lpszProfilePassword = "";
LPSTR lpszPSTDisplayName = "Personal Folders";
LPSTR lpszPSTPath = "C:\\Documents and Settings\\LapTop\\Local Settings
\\Application Data\\Microsoft\\Outlook\\Outlook6.pst";
DWORD dwEncryption = 1;
LPSTR lpszPSTPassword = "abcd";


// Configure the MS Personal Information Store per NewPST entries.
ULONG cValues = 0;
LPSPropValue lpProp = NULL;

hr = MAPIInitialize(NULL);

// Get a profile administration object.
hr = MAPIAdminProfiles(0, &lpProfAdmin);

if (FAILED(hr))
{
goto cleanup;
}
// Get a service administration object.
hr = lpProfAdmin->AdminServices( (LPSTR)lpszProfileName,
(LPSTR)lpszProfilePassword,
0,
0,
&lpSvcAdmin);

if (FAILED(hr))
{
goto cleanup;
}


hr = lpSvcAdmin->GetMsgServiceTable(0, &lpTable);

if (FAILED(hr))
{
goto cleanup;
}


// We don't need to worry about checking all the columns; there
should
// only be one since we just created the profile and added
oneservice.

hr = lpTable->QueryRows(1, 0, &lpRows);
if (FAILED(hr))
{
goto cleanup;
}

if (lpRows == NULL)
{
// highly unlikely.
goto cleanup;
}

cValues = lpRows->aRow[0].cValues;
lpProp = lpRows->aRow[0].lpProps;

while (cValues)
{
if (lpProp->ulPropTag == PR_SERVICE_UID)
{
MsgStoreUID = *((LPMAPIUID)lpProp->Value.bin.lpb);
break;
}
lpProp++;
cValues--;
}

if (cValues == 0)
{
// highly unlikely.
goto cleanup;
}

cValues = 6;
hr = MAPIAllocateBuffer(cValues * sizeof(SPropValue),
(LPVOID *)&aPropVals);

if ( FAILED(hr) )
{
goto cleanup;
}


aPropVals[0].ulPropTag = PR_DISPLAY_NAME;
aPropVals[0].Value.LPSZ = (LPSTR)lpszPSTDisplayName;

aPropVals[1].ulPropTag = PR_PST_PATH;
aPropVals[1].Value.LPSZ = (LPSTR)lpszPSTPath;;

aPropVals[2].ulPropTag = PR_PST_REMEMBER_PW;
aPropVals[2].Value.b = TRUE;

aPropVals[3].ulPropTag = PR_PST_ENCRYPTION;
aPropVals[3].Value.l = dwEncryption;

aPropVals[4].ulPropTag = PR_PST_PW_SZ_NEW;
aPropVals[4].Value.LPSZ = (LPSTR)lpszPSTPassword;

aPropVals[5].ulPropTag = PR_PST_PW_SZ_OLD;
aPropVals[5].Value.LPSZ = (LPSTR)lpszPSTPassword;

hr = lpSvcAdmin->ConfigureMsgService(&MsgStoreUID,
0,
0,
cValues,
aPropVals); // returned MAPI_E_FAILONEPROVIDER if second calling

if(hr == MAPI_E_FAILONEPROVIDER)
{
printf("test");
}


cleanup:

if( lpRows )
FreeProws(lpRows);

if( lpTable )
lpTable->Release() ;

if( aPropVals )
MAPIFreeBuffer(aPropVals);

if( lpSvcAdmin )
lpSvcAdmin->Release();

if( lpProfAdmin )
lpProfAdmin->Release();

MAPIUninitialize();

Thanx.

0 new messages