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

Author Topic: help with the "RD" command in a .bat  (Read 8232 times)

0 Members and 1 Guest are viewing this topic.

rej38675

    Topic Starter


    Rookie

    help with the "RD" command in a .bat
    « on: February 20, 2008, 10:49:22 AM »
    I work at a school and every time a student logs on a PC it creates a profile folder in C:\Documents and Settings.  I would like to run a script to delete them all.  Eventually there are hundreds of profile folders taking up 4 or more GB of space.  If I leave the path as above it will try to delete Administrator, and All Users, then get an error.  Can I delete everything in a directory except certain path names, or are there any other idea's for me to try???

    gpl



      Apprentice
    • Thanked: 27
      Re: help with the "RD" command in a .bat
      « Reply #1 on: February 20, 2008, 11:41:23 AM »
      That would be relatively simple, heres an outline
      Assuming you are in C:\Documents and Settings

      Code: [Select]
      :: iterate through each directory in the directory
      For /D %%a in (*.*) do call :KillUser %%a
      Goto :EOF

      :KillUser
      :: %1 holds the name of a folder

      :: skip wanted profiles
      If "%1"=="Administrator" GoTo :EOF
      If "%1"=="All Users" GoTo :EOF

      :: etc for all profiles you want to keep

      :: now remove the profile
      RD /S /Q "%1"

      Sorry but there is a bit more to do on this, I dont have time to investigate further
      Make sure you check it on a machine where it doesnt matter if you break it!!

      It might be that by removing a folder from the list it gets confused, in which case, output the folder list to a file, then use another loop to read the file and delete the profiles from there.

      Graham

      Dias de verano

      • Guest
      Re: help with the "RD" command in a .bat
      « Reply #2 on: February 20, 2008, 11:43:56 AM »
      gpl, this is what I was going to post...

      Right. You work in a school. OK. Like we believe you, but what if you're a student planning a prank? (You would not be the first one on here!)


      rej38675

        Topic Starter


        Rookie

        Re: help with the "RD" command in a .bat
        « Reply #3 on: February 20, 2008, 01:14:58 PM »
        Dias de verano- Why would you even waist your time in the forums on this site when it is meant to ask these kind of questons.  Do you get on every  post and say "no your not legit....To bad... not gonna help you".?????


        Every PC whether your at a school, a business, or at home you still have "C:\Documents and Settings" with profiles in it.  I'm not asking how you hack a server... I'm simply asking for pointers about a RD script in a MS Dos forum.

        Dias de verano

        • Guest
        Re: help with the "RD" command in a .bat
        « Reply #4 on: February 20, 2008, 03:16:56 PM »
        You sure spell bad for someone who "works in a school", and you show the sort of attitude you expect from a 14 year old.

        SOAP



          Beginner

          Re: help with the "RD" command in a .bat
          « Reply #5 on: February 20, 2008, 04:18:13 PM »
          This doesn't look like a question a hacker might ask, more like how to put something in a start up folder.

          rej38675

            Topic Starter


            Rookie

            Re: help with the "RD" command in a .bat
            « Reply #6 on: February 21, 2008, 10:01:21 AM »
            I'm not an English teacher... I'm in the tech department.  Sorry for any spelling errors.  I'm not trying to have an attitude of any sort.  I'm simply trying to get this figured out to make my job easier.  So far I have to two ideas, which I'm not really happy with either.

            Idea #1

            @echo off
            title HS list- local users
            rd /s /q "c:\Documents and Settings\user1"
            rd /s /q "c:\Documents and Settings\user2"
            rd /s /q "c:\Documents and Settings\user3"
            rd /s /q "c:\Documents and Settings\user4"
            pause
            exit

            This would work, but it just isn't practical.  Our district is very small but still have around 1,150 students.  I can copy paste very quickly and would just have to delete Seniors and add 6Th graders every year.  Also We have PCs ranging form Dell GX280's all the way down to Dell GX150's, which perform the long task way to slow because it is checking for every student even though the average PC only has between 2 and 3 hundred profiles.

            Idea #2

            @echo off
            md "C:\Move_Here"
            pause
            rd /s /q "C:\Move_Here"
            pause
            exit

            This idea is slightly more practical.  Basically you run the script it creates the "move_Here" folder.  You would then have to manually move all the user folders to it.  Moving isn't all that slow compared to copying.  Then it removes the "Move_Here" folder.  Leaving my couple of folders that I need to keep.  The biggest problem with this is having to manually move them witch I'm trying to reduce my interaction time with the script.

            I should also add we used to just highlight the profiles we wanted to get rid of, then hit delete.  Then we would have to empty the recycle bin which took an additional 10 minutes.

            As you can see I have some scripting knowledge, but it's not  advanced as I'd like.  Also know that if I didn't have admin privileges, and I ran a script of this sort, it wouldn't let me delete them.  It would say access denied.  Once again, thanks for any help I get.

            davie1982

            • Guest
            Re: help with the "RD" command in a .bat
            « Reply #7 on: February 21, 2008, 10:27:44 AM »
            It might be better to use VBScript to do that.

            Here's one i found by googling...

            http://www.wisesoft.co.uk/Scripts/display_script.aspx?id=14

            I personally recommend vbscript over batch files for this kind of procedure.  It's more healthy.

            GuruGary



              Adviser
              Re: help with the "RD" command in a .bat
              « Reply #8 on: February 21, 2008, 08:18:32 PM »
              You should look at gpl's idea / code.  It looks like it should be pretty efficient and work pretty well.

              Or try this:
              Code: [Select]
              @echo off
              setlocal enabledelayedexpansion
              for /f "delims=" %%a in ('dir "C:\Documents and Settings" /ad-h /b') do (
                set deluser=%%a
                if "%%a"=="Administrator" set deluser=
                if "%%a"=="All Users" set deluser=
                if not "!deluser!"=="" echo rd "%%a" /q /s)
              That should delete everybody except "Administrator", "All Users" and any hidden profiles which are probably system profiles.

              gregflowers



                Rookie

                Thanked: 3
                Re: help with the "RD" command in a .bat
                « Reply #9 on: February 22, 2008, 01:57:33 PM »
                Use delprof /Q /C:\\<REMOTECOMPUTERNAME>

                This tool is part of the WindowsServer2003-AdministrationToolsPack.exe, or you can download delprof.exe from the Microsoft web site