简体   繁体   中英

Windows 7: MFC ActiveX control does not create files in any folder

I have developed an MFC ActiveX control for use in Internet Explorer. This control creates files on hard drive. I have installed the control on Windows 7 (32-bit). If I run IE as administrator, the control creates files as expected. But if I run IE as normal user with UAC turned on, the control does not create any files.

Below is the code to create file:

int WriteDataToFile()
{
    CString Data;
    int DataLength;
    CString FilePath;
    std::ofstream File;

    // Set Data, DataLength and FilePath

    try
    {
        File.open(FilePath, std::ios::binary | std::ios::out);

        if (TRUE == File.fail())
        {
            return ERROR;
        }

        File.write((const char *)Data.GetBuffer(), DataLength);

        if (TRUE == File.bad())
        {
            File.close();

            return ERROR;
        }

        File.close();
    }
    catch (...)
    {
        return ERROR;
    }

    return SUCCESS;
}

The function returns SUCCESS if the program is run as administrator or normal user. Why does the program not create the files for normal user?

Thank you very much for any help which you can provide.

Which folder did your program write the file? Folders, such as 'Program Files' in system driver, are protected by Windows7, not allowed to create new files for normal users.

Maybe your should write your files to some folders not protected by Windows7.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM