我问过 here关于如何通过自动化设置Word文档的文件名而不保存它的问题。感谢 Remou,我通过调用 FileSummaryInfo-Dialog 并设置 Title-property 获得了一个很好的方法。
但是现在我遇到的问题是客户希望在(点和下划线)中包含带有特殊字符的文档名称,并且它似乎是单词的一个错误(或一个功能),它削减了标题并且只在用于构建文件名的第一个特殊字符!我已经用谷歌搜索了很多,但是无法找到解决此问题的方法。
这个问题也注意到了here (见陷阱下),但是没有解决方案。
有没有人在不保存的情况下设置文件名的另一种解决方案,或者提到的奇怪行为的解决方法/错误修复?
请您参考如下方法:
试试 easyhook ,因为这几天除了我手边没有Windows机器。
以下只是调用流程(就像我几年前所做的那样,通过 Detours 将软件的套接字绑定(bind)端口更改为不同的端口)
关于 Hook CreateFileW:
easyhook's wiki 中的示例正是我们想要的。
CreateFileHook = LocalHook.Create(
LocalHook.GetProcAddress("kernel32.dll", "CreateFileW"),
new DCreateFile(CreateFile_Hooked),
this);
在
CreateFile_Hooked
您可以更改参数
InFileName
,然后调用真正的 CreateFileW
static IntPtr CreateFile_Hooked(
String InFileName,
UInt32 InDesiredAccess,
UInt32 InShareMode,
IntPtr InSecurityAttributes,
UInt32 InCreationDisposition,
UInt32 InFlagsAndAttributes,
IntPtr InTemplateFile)
{
// FIGURE OUT THE FILE NAME THAT YOU WANT HERE
// IF the InFileName is not your Document name "My.doc", then call orignal CreateFile
// with all the parameter unchanged.
// call original API...
return CreateFile(
YOUR_CHANGED_FILE_NAME_HERE,
InDesiredAccess,
InShareMode,
InSecurityAttributes,
InCreationDisposition,
InFlagsAndAttributes,
InTemplateFile);
}
调用流程:
将标题更改为“My_Document_2012_11_29”后,
然后 Hook Word 进程的 CreateFileW。
例如,当 InFileName 为“My.doc”时,
那么您应该将其更改为“My_Document_2012_11_29”。
因为这是在Word过程中完成的,所以Detoured函数不知道
“My.doc”映射到“My_Document_2012_11_29”。
有很多方法可以获取此映射信息,一种是将映射信息保存到
应用程序中的一个已知文件,并在 Detoured 函数中读取该文件。