简体   繁体   English

Windows 7:MFC ActiveX控件不会在任何文件夹中创建文件

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

I have developed an MFC ActiveX control for use in Internet Explorer. 我已经开发了用于Internet Explorer的MFC ActiveX控件。 This control creates files on hard drive. 该控件在硬盘驱动器上创建文件。 I have installed the control on Windows 7 (32-bit). 我已经在Windows 7(32位)上安装了控件。 If I run IE as administrator, the control creates files as expected. 如果我以管理员身份运行IE,则控件会按预期创建文件。 But if I run IE as normal user with UAC turned on, the control does not create any files. 但是,如果我以打开UAC的普通用户身份运行IE,则控件不会创建任何文件。

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. 如果程序以管理员或普通用户身份运行,则该函数返回SUCCESS 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. 文件夹(例如系统驱动程序中的“程序文件”)受Windows7保护,不允许为普通用户创建新文件。

Maybe your should write your files to some folders not protected by Windows7. 也许您应该将文件写入不受Windows7保护的某些文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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