none
Delete Local Profiles Using WMI

    Question

  • I have created a simple batch script which i hope to use in order to delete local profiles on a particular system. Every time i run this script, it will delete a few profiles successfully and then it will stop at a profile and will give the error "The directory is not empty.". How can i force my script to delete non-empty profiles? Here is the script that i have created in batch: wmic path win32_userprofile where (special!="true" and loaded!="true") delete

    Thanks in advance for the help,

    Devon

    Tuesday, November 20, 2012 10:54 PM

Answers

  • I am certain that this is not a virus and blame miss-communication for your conjecture. You have even stated in a previous thread that WMI was the preferred alternative to delprof in a Windows 7\Server 2008 environment. In that thread however, you were utilizing powershell. I would like to know if this is achievable within batch. 

    In a batch use WMIC which is the command line utility for WMI.

    WMIC class Win32_UserProfile

    I will leave it to you as an exercise to learn how to use the command line since it is easier for you than PowerShell.  The above will show you how to query a class at the command line.

    DelProf, DelProf2 and most other WMI to remove profiles.  Probably the only way that the page file could be corrupted by this is if the disk is bad.

    Of course you could just be wrong about that which is more likely.

    Too often, when things go wrong, we tend to blame it on things that play to our superstitions.  There is really no way that deleting a profile can corrupt a page file.  It is more likely (remember Occam's Razor?) that the disk is damaged and needs to be fixed.  I have seen this kind of thing happen when a RootKit is active because it is trying to move things around and stay hidden.

    Try to approach things from  a less complicated direction. Do more fundamental research.  You will find that things are not that difficult.

    Good luck.


    ¯\_(ツ)_/¯

    Friday, November 30, 2012 4:54 AM

All replies

  • Do you have a particular reason for using WMIC (which is hard to apply at the best of times!) to delete profile folders instead of the "rd /s /q ..." and "net user xxx /del" commands?
    Tuesday, November 20, 2012 11:46 PM
  • I wanted to use WMIC so that i may go through all user profiles that are not special and are not currently active on the system. 
    Tuesday, November 20, 2012 11:59 PM
  • I have created a simple batch script which i hope to use in order to delete local profiles on a particular system. Every time i run this script, it will delete a few profiles successfully and then it will stop at a profile and will give the error "The directory is not empty.". How can i force my script to delete non-empty profiles? Here is the script that i have created in batch: wmic path win32_userprofile where (special!="true" and loaded!="true") delete

    Thanks in advance for the help,

    Devon

    The profiles are corrupted.  They need to be fixed firtrst.

    Someetimes DELProf will work better. (DELPROF /?) follow instructions.


    ¯\_(ツ)_/¯

    Wednesday, November 21, 2012 12:01 AM
  • The purpose of this script was to replace our current procedure which was using delprof to delete profiles. Delprof has a bad habit in our environment of deleting\corrupting the page file after it has successfully completed which causes the first user that logs into that system to receive an error message pertaining to the rebuilding of the page file and requiring the system to restart. It also does not seem to fully remove all of the profile folders. 
    Wednesday, November 21, 2012 12:11 AM
  • If you are on a Domain, then there is a domain based GPO setting under Computer configuration Delete user profiles older than a specified number of days.

    So this will simply delete local profiles > nn days without needing a script. So you can auto cleanout profiles from people that have not logged in in 5, 30, 90 days etc. The GPO/local policy indicates this is only be available from Vista / Windows 7 onwards.

    Note: this can be used in local policy as well. GPEdit.msc is your friend.

    Note2: I don't think you can get the profiles back easily, I would suggest being VERY sure before you implement this as a domain setting, making sure you target just this one troublesome machine your refer to.


    EDIT: If you are wanting to target specific Profiles however you will still need to use your scripts.
    • Edited by PaulJM69 Wednesday, November 21, 2012 2:41 AM
    Wednesday, November 21, 2012 2:38 AM
  • For our environment, i will need to use a script and not a GPO to accomplish what i need done. There is no need to recover the deleted profiles as they are pulled down from our servers. Is there a method through power shell using WMI to accomplish what im trying to do? Im trying to delete all profiles on a local system except for special profiles and loaded profiles. 
    Wednesday, November 21, 2012 2:58 AM
  • The purpose of this script was to replace our current procedure which was using delprof to delete profiles. Delprof has a bad habit in our environment of deleting\corrupting the page file after it has successfully completed which causes the first user that logs into that system to receive an error message pertaining to the rebuilding of the page file and requiring the system to restart. It also does not seem to fully remove all of the profile folders. 

    This statement indicates that you havbe a corrupted image or an infected system.  Ther eis no reason for delprof to do this as it uses exactly the same API as the WMI deleteprofile uses.  They are no different.

    You need to fix your systems then any of these methods will work.

    I recommend calling MS support for assistance with troubleshooting this issue since no method currently acceptable seems to work for you.


    ¯\_(ツ)_/¯

    Wednesday, November 21, 2012 4:18 AM
  • I am certain that this is not a virus and blame miss-communication for your conjecture. You have even stated in a previous thread that WMI was the preferred alternative to delprof in a Windows 7\Server 2008 environment. In that thread however, you were utilizing powershell. I would like to know if this is achievable within batch. 
    Friday, November 30, 2012 4:26 AM
  • I am certain that this is not a virus and blame miss-communication for your conjecture. You have even stated in a previous thread that WMI was the preferred alternative to delprof in a Windows 7\Server 2008 environment. In that thread however, you were utilizing powershell. I would like to know if this is achievable within batch. 

    In a batch use WMIC which is the command line utility for WMI.

    WMIC class Win32_UserProfile

    I will leave it to you as an exercise to learn how to use the command line since it is easier for you than PowerShell.  The above will show you how to query a class at the command line.

    DelProf, DelProf2 and most other WMI to remove profiles.  Probably the only way that the page file could be corrupted by this is if the disk is bad.

    Of course you could just be wrong about that which is more likely.

    Too often, when things go wrong, we tend to blame it on things that play to our superstitions.  There is really no way that deleting a profile can corrupt a page file.  It is more likely (remember Occam's Razor?) that the disk is damaged and needs to be fixed.  I have seen this kind of thing happen when a RootKit is active because it is trying to move things around and stay hidden.

    Try to approach things from  a less complicated direction. Do more fundamental research.  You will find that things are not that difficult.

    Good luck.


    ¯\_(ツ)_/¯

    Friday, November 30, 2012 4:54 AM
  • Do you have a particular reason for using WMIC (which is hard to apply at the best of times!) to delete profile folders instead of the "rd /s /q ..." and "net user xxx /del" commands?

    Can you teach us how we can use both of these codes?

    For example I want to delete c:XXX  folder/subfolder and in its all files for 192.168.192.xxx(IP) remote pc.


    www.google.com/+SerdarUZUN/About

    Wednesday, June 04, 2014 11:00 AM
  • Thread answered. Please start a new thread.

    ¯\_(ツ)_/¯

    Wednesday, June 04, 2014 1:10 PM
  • My question is about the thread! although it's answered...

    There is already a thread, so starting a new thread is wasting time as for me


    \_(ツ)_/ twitter.com/serdaruzun

    Wednesday, June 04, 2014 1:14 PM
  • Please read the forum rules.  Your question will not be answered here.


    ¯\_(ツ)_/¯

    Wednesday, June 04, 2014 1:29 PM