Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Need help with a .cmd file, pretty please!  (Read 4396 times)

0 Members and 1 Guest are viewing this topic.

zonnk

    Topic Starter


    Starter

    • Experience: Beginner
    • OS: Unknown
    Need help with a .cmd file, pretty please!
    « on: April 04, 2013, 08:27:34 PM »
    To save petty details, here is what I am currently using
    Keep in mind the listed code works perfectly on its own when I edit the file with a specific directory.

    Quote
    -Fileremover.cmd-

    takeown /f "whatever directory I want" /r /d y
    icacls "whatever directory I want" /grant administrators:F /t
    call cleanit.cmd

    Quote
    -cleanit.cmd-

    rd /s /q "whatever directory I want"

    I am trying to figure out a way to either
    A: have the cmd promt me to input the directory to execute the takeown, or
    B:use a bat/cmd file to replace a designated directory with a directory specified on the command prompt window inside a created copy or a cmd file.

    so for example,
    COPY C:\test.txt test2.txt
    COPY C:\cleanit.cmd cleanit2.cmd
    then have it replace "whatever directory I want" with something I enter into the cmd prompt

    afterwards of course have them run then get deleted through some means, which I can do. It is just the input I am having trouble with, I searched high and low as well as tried a few switches and different lines.

    I would be happy to even learn some scripting if needed. I just want this to be successful. Thank you for reading and your responses :)
    If this does not make sense I am more than happy to try and clarify.

    Squashman



      Specialist
    • Thanked: 134
    • Experience: Experienced
    • OS: Other
    Re: Need help with a .cmd file, pretty please!
    « Reply #1 on: April 04, 2013, 08:38:15 PM »
    Code: [Select]
    set /p fpath=Enter in the full path to a directory:
    takeown /f "%fpath%" /r /d y

    zonnk

      Topic Starter


      Starter

      • Experience: Beginner
      • OS: Unknown
      Re: Need help with a .cmd file, pretty please!
      « Reply #2 on: April 04, 2013, 08:55:35 PM »
      Thanks Squashman, that actually did the trick, sadly I guess i'll have to input it twice, once for the remover and once for the cleanit.
      Either way fantastic job! I greatly appreciate it.

      Squashman



        Specialist
      • Thanked: 134
      • Experience: Experienced
      • OS: Other
      Re: Need help with a .cmd file, pretty please!
      « Reply #3 on: April 04, 2013, 09:04:30 PM »
      Why do you have the CleanIt as a separate batch file?  Why not have all the code in one batch file?

      And no you would not have to do it twice.  You can pass command line arguments to a batch when you start a batch file or call a batch file.

      Code: [Select]
      call cleanit.cmd "%fpath%"
      Code: [Select]
      rd /s /q "%~1"
      With such simple and basic code I would just combine these two batch files into one.


      zonnk

        Topic Starter


        Starter

        • Experience: Beginner
        • OS: Unknown
        Re: Need help with a .cmd file, pretty please!
        « Reply #4 on: April 04, 2013, 09:16:24 PM »
        I was thinking about that actually, I have only starting delving into DOS (Specifically 5.0), and cmd promt so im still in my infancy. I actually figured out I didn't have to re specify it, which did make me happy!
        either way it's a decent makeshift virus remover (or at least for what I was trying to get rid of) just wanted to make it more user friendly.

        I think I will take your advice though and combine them!

        zonnk

          Topic Starter


          Starter

          • Experience: Beginner
          • OS: Unknown
          Re: Need help with a .cmd file, pretty please!
          « Reply #5 on: April 04, 2013, 09:55:36 PM »
          So I ended up keeping it in two separate files but thanks to you, this is my end result.

          Quote
          Fileremover.cmd

          set /p fpath=Enter in the full path to a directory:
          takeown /f "%fpath%" /r /d y
          pause
          icacls "%fpath%" /grant administrators:F /t
          pause
          call cleanit.cmd

          Quote
          cleanit.cmd

          rd /s /q "%fpath%"
          pause
          @ECHO OFF

          :choice
          set /P c=If file is still present, would you like to try a GOOGLE search?[Y/N]?
          if /I "%c%" EQU "Y" goto :somewhere
          if /I "%c%" EQU "N" goto :somewhere_else
          goto :choice


          :somewhere

          echo "Opening up www.google.com"
          start www.google.com
          echo "Hope you find a way to remove your piece of data!"
          pause
          exit

          :somewhere_else

          echo "Huzzah! You win, you awesome person you ;)"
          pause
          exit

          Thanks again Squashman.