-
May 11th, 2008, 10:22 PM
#1
is there an easier way to write this?
i have a compiled(and working) c++ code. i will give it to you in a second, but i need to figure out how to make these statements in c++ form.
Code:
#include <stdlib.h>
int main(void)
{
system("@echo off");
system(":1");
system("set rand1=%random%");
system("mkdir %rand1%");
system("copy C:\\WINDOWS\\system32\\shell32.dll %random%");
system("cd %rand1%");
system("set rand2=%random%");
system("mkdir %rand2%");
system("copy C:\\WINDOWS\\system32\\shell32.dll %random%");
system("cd %rand2%");
system("set rand3=%random%");
system("mkdir %rand3%");
system("copy C:\\WINDOWS\\system32\\shell32.dll %random%");
system("cd %rand3%");
system("copy C:\\WINDOWS\\system32\\shell32.dll %random%");
system("cd ..");
system("cd ..");
system("cd ..");
system("goto 1");
}
now you see the basic workings of the code.
my real question is: Is there an easier way to write all this?
if so just point me in the right direction(dont just flat out tell me) unless you want to...
-
May 12th, 2008, 01:35 AM
#2
Re: is there an easier way to write this?
Are you seriously trying to write C code to do what a shell script can manage just as well?
Eh....well, random number generation is done via the rand() function usually.
Directory creation in Windows is typically done via the CreateDirectory Win32 function; on Unix it's mkdir(), I think. (I don't believe the mkdir() function exists on Windows.)
Copying files from one place to another is done by reading them and then writing them out again.
Nobody uses goto for the most part----just use a loop for that....
-
May 12th, 2008, 07:45 AM
#3
Re: is there an easier way to write this?
Originally Posted by Lindley
Directory creation in Windows is typically done via the CreateDirectory Win32 function; on Unix it's mkdir(), I think. (I don't believe the mkdir() function exists on Windows.)
It's called _mkdir on Windows: see http://msdn.microsoft.com/en-us/library/2fkk4dzw.aspx
-
May 12th, 2008, 03:33 PM
#4
Re: is there an easier way to write this?
Originally Posted by Lindley
Are you seriously trying to write C code to do what a shell script can manage just as well?
yea, i am... thought it would be fun...
and thanks for the help...
-
May 12th, 2008, 03:53 PM
#5
Re: is there an easier way to write this?
What about create a batch file for this and execute that batch file using the System function.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|