![](/img/trans.png)
[英]Copying a file from C:\Windows\System32 folder to C:\Windows\SysWOW64 folder using Fortran and/or C++
[英]C++ Rename File @ C:\Windows\System32\Drivers
已解決:看看后面的帖子
任務:重命名一個名為 TabletFilter.sys 的文件(它是我的圖形平板電腦驅動程序),因為 Windows 8(我的操作系統)應用程序需要另一個驅動程序,然后是 photoshop 以獲取引腳壓力。 我想編寫一個 C++ 程序,將所有驅動程序文件重命名為 .old
基於 cplusplus.com 重命名示例的代碼
#include <stdio.h>
int main ()
{
int result;
char oldname[] ="TabletFilter.sys";
char newname[] ="TabletFilter.sys.old";
result= rename( oldname , newname );
if ( result == 0 )
puts ( "File successfully renamed" );
else{
result= rename( newname , oldname );
if( result == 0)
puts ( "File successfully renamed" );
else
perror( "Error renaming file" );
}
return 0;
}
我也試過“以管理員身份運行”,但我仍然得到
Error renaming file: No such file or directory
我能做什么?
編輯:
該文件肯定在同一個文件夾中......我將它們都復制到了那里......即使在 c:\\windows\\ 我也嘗試過......並且我使用了清單
Executable: TabletRenameDriver.exe
Manifest: TabletRenameDriver.exe.manifest
Sample application manifest file:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0"
processorArchitecture="X86"
name="TabletRenameDriver"
type="win32"/>
<description>Description of your application</description>
<!-- Identify the application security requirements. -->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="requireAdministrator"
uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
我試過 uiAccess 真假。
是的,我的權利有問題 驅動程序已加載,但我仍然可以更改他的名字...不知道為什么,但可能會。 我試過了。 我想用 C++ 解決這個問題,所以請不要告訴我有很多腳本語言可以很好地處理這個問題;-) 我知道這一點
錯誤信息
No such file or directory
表示當前目錄不包含文件名"TabletFilter.sys"
或"TabletFilter.sys.old"
。
你可以做的是:
但是,即使您這樣做,您的程序也很可能會失敗。 您可能沒有足夠的權限來修改該文件夾的內容。 如果操作系統已加載驅動程序,您嘗試重命名的文件很可能會被鎖定。
正如@Hans 指出的那樣, 文件系統重定向器很可能會讓您感到困惑。 避免這種情況的最佳方法是我們使用 64 位進程。
我認為沒有理由在這里使用 C++ 程序。 重命名文件是最適合腳本語言的任務。
感謝你的幫助
我完成了我的程序,現在它運行良好
注意:通過 VS2012 設置添加了“requireAdministrator”uiAccess="false"
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
void main ()
{
bool success = false;
bool somethingWentWrong = false;
PVOID OldValue = NULL;
if( Wow64DisableWow64FsRedirection(&OldValue) )
{
success = MoveFile("C:\\Windows\\System32\\Drivers\\TabletFilter.sys", "C:\\Windows\\System32\\Drivers\\TabletFilter.sys.old");
if(success){
puts("from .sys to .sys.old");
success = MoveFile("C:\\Windows\\System32\\DriverStore\\FileRepository\\tabletfilter.inf_amd64_e7d03235d8288d3b\\TabletFilter.sys", "C:\\Windows\\System32\\DriverStore\\FileRepository\\tabletfilter.inf_amd64_e7d03235d8288d3b\\TabletFilter.sys.old");
if(!success){ puts("ERROR: C:\\Windows\\System32\\DriverStore\\FileRepository\\tabletfilter.inf_amd64_e7d03235d8288d3b\\TabletFilter.sys not found"); somethingWentWrong = true;}
success = MoveFile("C:\\Windows\\System32\\DriverStore\\FileRepository\\tabletfilter.inf_amd64_e7d03235d8288d3b\\TabletFilter.inf", "C:\\Windows\\System32\\DriverStore\\FileRepository\\tabletfilter.inf_amd64_e7d03235d8288d3b\\TabletFilter.inf.old");
if(!success){ puts("ERROR: C:\\Windows\\System32\\DriverStore\\FileRepository\\tabletfilter.inf_amd64_e7d03235d8288d3b\\TabletFilter.inf not found"); somethingWentWrong = true;}
success = MoveFile("C:\\Windows\\System32\\DriverStore\\FileRepository\\tabletfilter.inf_amd64_e7d03235d8288d3b\\TabletFilter.cat", "C:\\Windows\\System32\\DriverStore\\FileRepository\\tabletfilter.inf_amd64_e7d03235d8288d3b\\TabletFilter.cat.old");
if(!success){ puts("ERROR: C:\\Windows\\System32\\DriverStore\\FileRepository\\tabletfilter.inf_amd64_e7d03235d8288d3b\\TabletFilter.cat not found"); somethingWentWrong = true;}
}else{
puts("from .sys.old to .sys");
success = MoveFile("C:\\Windows\\System32\\Drivers\\TabletFilter.sys.old", "C:\\Windows\\System32\\Drivers\\TabletFilter.sys");
if(!success){ puts("ERROR: C:\\Windows\\System32\\Drivers\\TabletFilter.sys.old not found"); somethingWentWrong = true;}
success = MoveFile("C:\\Windows\\System32\\DriverStore\\FileRepository\\tabletfilter.inf_amd64_e7d03235d8288d3b\\TabletFilter.sys.old", "C:\\Windows\\System32\\DriverStore\\FileRepository\\tabletfilter.inf_amd64_e7d03235d8288d3b\\TabletFilter.sys");
if(!success){ puts("ERROR: C:\\Windows\\System32\\DriverStore\\FileRepository\\tabletfilter.inf_amd64_e7d03235d8288d3b\\TabletFilter.sys.old not found"); somethingWentWrong = true;}
success = MoveFile("C:\\Windows\\System32\\DriverStore\\FileRepository\\tabletfilter.inf_amd64_e7d03235d8288d3b\\TabletFilter.inf.old", "C:\\Windows\\System32\\DriverStore\\FileRepository\\tabletfilter.inf_amd64_e7d03235d8288d3b\\TabletFilter.inf");
if(!success){ puts("ERROR: C:\\Windows\\System32\\DriverStore\\FileRepository\\tabletfilter.inf_amd64_e7d03235d8288d3b\\TabletFilter.inf.old not found"); somethingWentWrong = true;}
success = MoveFile("C:\\Windows\\System32\\DriverStore\\FileRepository\\tabletfilter.inf_amd64_e7d03235d8288d3b\\TabletFilter.cat.old", "C:\\Windows\\System32\\DriverStore\\FileRepository\\tabletfilter.inf_amd64_e7d03235d8288d3b\\TabletFilter.cat");
if(!success){ puts("ERROR: C:\\Windows\\System32\\DriverStore\\FileRepository\\tabletfilter.inf_amd64_e7d03235d8288d3b\\TabletFilter.cat.old not found"); somethingWentWrong = true;}
}
if(somethingWentWrong){
puts ( "ERROR: File were set to standart!" );
success = MoveFile("C:\\Windows\\System32\\Drivers\\TabletFilter.sys.old", "C:\\Windows\\System32\\Drivers\\TabletFilter.sys");
if(!success){ puts("ERROR: C:\\Windows\\System32\\Drivers\\TabletFilter.sys.old not found"); somethingWentWrong = true;}
success = MoveFile("C:\\Windows\\System32\\DriverStore\\FileRepository\\tabletfilter.inf_amd64_e7d03235d8288d3b\\TabletFilter.sys.old", "C:\\Windows\\System32\\DriverStore\\FileRepository\\tabletfilter.inf_amd64_e7d03235d8288d3b\\TabletFilter.sys");
if(!success){ puts("ERROR: C:\\Windows\\System32\\DriverStore\\FileRepository\\tabletfilter.inf_amd64_e7d03235d8288d3b\\TabletFilter.sys.old not found"); somethingWentWrong = true;}
success = MoveFile("C:\\Windows\\System32\\DriverStore\\FileRepository\\tabletfilter.inf_amd64_e7d03235d8288d3b\\TabletFilter.inf.old", "C:\\Windows\\System32\\DriverStore\\FileRepository\\tabletfilter.inf_amd64_e7d03235d8288d3b\\TabletFilter.inf");
if(!success){ puts("ERROR: C:\\Windows\\System32\\DriverStore\\FileRepository\\tabletfilter.inf_amd64_e7d03235d8288d3b\\TabletFilter.inf.old not found"); somethingWentWrong = true;}
success = MoveFile("C:\\Windows\\System32\\DriverStore\\FileRepository\\tabletfilter.inf_amd64_e7d03235d8288d3b\\TabletFilter.cat.old", "C:\\Windows\\System32\\DriverStore\\FileRepository\\tabletfilter.inf_amd64_e7d03235d8288d3b\\TabletFilter.cat");
if(!success){ puts("ERROR: C:\\Windows\\System32\\DriverStore\\FileRepository\\tabletfilter.inf_amd64_e7d03235d8288d3b\\TabletFilter.cat.old not found"); somethingWentWrong = true;}
}else
puts ( "File successfully renamed" );
Wow64RevertWow64FsRedirection(OldValue);
}
for(unsigned long tick = GetTickCount() / 1000; tick + 2 > GetTickCount() / 1000;){
}
}
只有 48 行代碼……腳本可以更短嗎?
PS:一段時間后重溫這篇文章,我認為有很多方法可以以不同的方式處理這個問題。 然而,要點仍然存在:如果你想做這樣的事情,你必須以管理員權限運行......並且可能使用循環、列表/向量和一些適當的字符串操作:-P
Windows 需要其中許多驅動程序才能啟動。 如果您確實成功地重命名了它們,那么當您重新啟動時,您的機器會發生不好的事情 - 即您的機器將無法啟動。
作為一般規則,將所有內容留在 C:\\Windows 中,但此建議對於 C:\\Windows\\drivers 目錄的重要性要高十倍。 觸摸此文件夾及其中的任何內容,您都將面臨危險。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.