简体   繁体   English

如何删除C ++中Word文档的写保护?

[英]How can I remove the write protection of a Word Document in C++?

I am copying a Word-document from a Server into my %localappdata%\\temp -Directory. 我正在将Word文档从服务器复制到我的%localappdata%\\temp -Directory。 But the Document is write-protected, and I can't modify or delete it. 但是该文档受写保护,我无法对其进行修改或删除。 I don't want to manually remove the protection, it needs to get done automatically 我不想手动删除保护,它需要自动完成

My code to copy and remove the protection is 我复制和删除保护的代码是

CopyFile(strTemplate, userTempDir, TRUE);
        SetFileAttributesA(userTempDir, FILE_ATTRIBUTE_NORMAL);

strTemplate is the PathToFile on the Server, userTempDir is the PathToFile to the copy directory (in this case "%localappdata%\\temp\\copy.doc") strTemplate是服务器上的PathToFile, userTempDir是复制目录的PathToFile(在这种情况下为“%localappdata%\\ temp \\ copy.doc”)

But

SetFileAttributesA(userTempDir, FILE_ATTRIBUTE_NORMAL);

doesn't work. 不起作用。 I'm pretty new to C++ so I don't know how to remove that Write-Protection 我是C ++的新手,所以我不知道如何删除该Write-Protection

SetFileAttributes(userTempDir, GetFileAttributes(userTempDir) &~FILE_ATTRIBUTE_READONLY);

如果存在一个只读属性,它将删除该属性。

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

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