gpt4 book ai didi

c++ - 在 C++ 中使用系统调用 UNRAR.exe

转载 作者:可可西里 更新时间:2023-11-01 10:46:15 25 4
gpt4 key购买 nike

我试图在 VC2010 中运行一个非常简单的控制台应用程序,但我无法使用系统函数成功地将参数传递给 unrar.exe。该应用程序旨在查找我忘记的 RAR 文件的密码。这是主要文件:

#include <iostream>
#include <string>
#include <ctime>
#include <cmath>
#include <direct.h>
#include "Password.h"
#include <windows.h>
using namespace std;


string RARPath = "\"UnRAR.exe\"";
string FP2 = "\"C:\\Program Files\\WINRAR\\RU.rar\"";
string Access = "runas /user:NimaNikvand ";
string Destination = "\"C:\\Tester\\Extracted\"";

int main(int argc, char ** argv)
{

for(int Passlength=2;Passlength<50;Passlength++)
{
Password pass(Passlength);
for(int i=0;i<pow(pass.AlphaBeta.size()*1.0,Passlength);i++)
{
time_t t1 = clock();
pass.IncrementalSweep();
cout<<"Trying Password: "<<pass.GetPass()<<endl;;
string Command =RARPath+" x"+" -p\""+pass.GetPass()+"\" "+FP2+" *.* "+Destination;
cout<<Command<<endl;
_chdir("C:\\Program Files\\WINRAR\\");
int flag = system(Command.c_str());
time_t t2 = clock();
cout<<"SPEED: "<<(CLOCKS_PER_SEC)/(1.0*t2-1.0*t1)<<" PASSWORDS Per Second"<<endl;

}
}
return 0;
}

一切正常,传递对象使用其类定义中的函数不断更新,但是当我运行最终构建时,我在命令中得到以下信息:“文件名、目录名或卷标语法不正确” .是的,我已经在 cmd 中手动尝试了确切的命令格式,它工作得很好。我不打算使用 shellexecute 或花哨的 createprocess API,并且需要将其保持为一个简单的控制台应用程序。

非常感谢您的帮助。

最佳答案

简短回答:从 _chdir() 调用中的目录名称中删除尾部斜杠:

_chdir("C:\\Program Files\\WinRAR");

说明:要找出此类错误,检查 errno 值 (#include) 很有用。值 22 表示无效参数。

关于c++ - 在 C++ 中使用系统调用 UNRAR.exe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24144879/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com