Reputation: 21
I am trying to run a very simple console application in VC2010, and I cannot successfully pass parameters to unrar.exe using system function. The application is intended to find the password for a RAR file which I have forgotten. Here is the main file:
#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;
}
Everything works fine and the pass object keeps getting updated incrementally using functions in its class definition, however when I run the final build, I get the following in Command: "The filename, directory name, or volume label syntax is incorrect". And Yes I have tried the exact Command format manually in cmd and it works perfectly fine. I don't intend to use shellexecute or a fancy createprocess API and need to keep this a simple console application.
Your help is greatly appreciated.
Upvotes: 2
Views: 924
Reputation: 14467
Short answer: remove the trailing slashes from the directory name in _chdir() call:
_chdir("C:\\Program Files\\WinRAR");
Explanations: To figure out such errors it is useful to inspect the errno
value (#include ). The value 22 indicates invalid parameters.
Upvotes: 0