?
Solved

File is in use by another process - How can I find what is using / locking it?

Posted on 2004-11-17
58
Medium Priority
?
50,911 Views
Last Modified: 2011-08-18
I am trying to delete a bunch of files (a profile folder, actually), but they are in use.  "Cannot delete ntuser.dat: It is being used by another person or program.  Close any programs that might be using the file and try again."  [OK]

And if I try and edit / open NTUSER.dat in notepad, "The process cannot access the file because it is being used by another process."

I am NOT logged into this current user, and the files should NOT be in use.  If you would like to know more information I can elaborate.  I need to know what is using these files, and how I can close those processes and/or services so these files get deleted when they are supposed to.

This is replacing another question that I've had open in this TA for the past 2 days, but received no comments.

Thanks in advance,
~ Jonny
0
Comment
Question by:jonnyz0109
  • 32
  • 10
  • 6
  • +5
57 Comments
 
LVL 65

Expert Comment

by:SheharyaarSaahil
ID: 12604461
Hello jonnyz0109 =)

Use this tool >> http://www.sysinternals.com/ntw2k/freeware/procexp.shtml
0
 
LVL 65

Expert Comment

by:SheharyaarSaahil
ID: 12604468
You may also try this method,

Delete A File That Is Seemingly "Undeletable"
http://www.theeldergeek.com/delete_undeletable_file.htm
0
 
LVL 41

Expert Comment

by:stevenlewis
ID: 12604481
try this utility to see what has it locked
http://www.dr-hoiby.com/WhoLockMe/
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 4

Author Comment

by:jonnyz0109
ID: 12604488
Hey Shehar  :o)   You are quick

I will check these out and get right back to you.
0
 
LVL 65

Expert Comment

by:SheharyaarSaahil
ID: 12604507
sure no problem,,, the most possible doubt is that Explorer has locked those files and using the theeldergreek method, you should be able to delete those undeleteable files :)
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12604556
It's in use by explorer...
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12604566
>>using the theeldergreek method, you should be able to delete those undeleteable files

Gonna check it out now.
0
 
LVL 65

Expert Comment

by:SheharyaarSaahil
ID: 12604578
hmmmmmm ok :)
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12604599
Closing explorer and reopening did not unlock the file.  But let me clean this up and replicate the problem cleanly... I've been trying all sorts of things and testing and haven't restarted in a while.
0
 
LVL 65

Expert Comment

by:SheharyaarSaahil
ID: 12604621
hey are you trying to delete them in safemode na ??
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12604769
No... I guess a little background is in order.  We use Novell to delete the local roaming profile from the workstation hard drive after the user's profile is loaded up to the server.  Novell starts to delete the profile but hits the locked files and gives up.  Now I'm left with no profiles registered in windows, but a partial profile folder in the Docs and Settings area.  Now the next time the student logs in, Windows sees the folder and decides it can' overwrite a profile folder, so it adds ".000" to the end... and basically that just starts screwing things up.

I just replicated the problem cleanly and closing explorer did not help.  I even tried deleting the file from a command prompt while explorer was not running, and it still reported being in use.  I'll run the above utility again and see if I can find somethine else using the file...

~ Jonny
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12604853
The root of "system" - using:

C:\Documents and Settings\8averykevin\ntuser.dat
C:\Documents and Settings\8averykevin\NTUSER.DAT.LOG

Can I close this thread/process without screwing my windows session over?  My goal is to allow the student to log off without having to restart in order to restore functionality...
0
 
LVL 41

Expert Comment

by:stevenlewis
ID: 12604934
I'm pretty sure you will be "screwing my windows session over", but give it a shot
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12605101
hehe yeh I think I just made Windows have a heart attack  :o)

So now the question is why is it in use by "System" and how can I fix that?  Do services run under this single process/handle?  Is it possible that a service is not closing properly?  Not putting things back the way they should?  There is an autocad service, I haven't narrowed it down to this service running or not, because when autocad is launched there are plenty of different proceses that run...

Just kind of thinking out loud here.  Any ideas guys?
0
 
LVL 41

Expert Comment

by:stevenlewis
ID: 12605233
here's an idea, create a batch file to delete these files
and then see
AutoExNT Service allows you to start a batch file, Autoexnt.bat, at boot time without having to log onto the computer on which it will run.

http://www.dynawell.com/support/ResKit/win2k.asp
then when the student logs on, the folder(s) should be gone
0
 
LVL 65

Expert Comment

by:SheharyaarSaahil
ID: 12605272
hmmmmmm novell... i have never used it, so dont have any idea that if you cannot use safemode or safemode with command prompt for deleting the profile files present on the hard drive.... mostly when we cannot delete the files in GUI interface, we use safemode with command prompt to delete the files from the hard drive as in command prompt there is no possibility of background process or services :)
0
 
LVL 41

Expert Comment

by:stevenlewis
ID: 12605300
You are trying this on a test machine (I hope)
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12605318
of course.... that's what makes this so difficult to solve.... which is why I've posted it here!  :o)
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12605481
New question:  I have a service set to go as a specific user.  I have entered the password and everything, and it says "The account .\user has been granted the Log On As A Service right." I can then start and stop the service successfully.  But as soon as I log out and back in, it is not authenticated anymore.  The error that comes up now when I try to start the service is: Could not start the Run Autocad Licensing service on Local Computer.  Error 1069: The service did not start due to a logon failure."  If I retype in the password and try to start the service again, it works.  Why isn't it keeping the authentication information?
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12605490
Yes it's one machine in an Autocad lab that I've designated as my test machine.  If I kill it I can just blow another clean image onto it  :o)
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12605571
>> here's an idea, create a batch file to delete these files
and then see
AutoExNT Service allows you to start a batch file, Autoexnt.bat, at boot time without having to log onto the computer on which it will run.

We thought about that, but the problem is that if the user logs out after being the first to run autocad, his profile folder is now locked and partially there.  If he restarts and we have this batch file run on startup, then yes it can get rid of those extra files lying around.  But if the student just logs out, and the next period happens to come back and logs back in, the files will still be locked, and unable to be deleted.

Requiring a student to restart the computer would be a solution... we found that if we restart instead of logging out the files are not locked.  this is our "last resort" solution though... much rather would be able to have the students be able to log in and out without any problems.
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12605904
OK Forget everything up to this point.  Take a look at this.

Autocad uses a licensing service, which runs when autocad runs, and it doesn't do a good job of cleaning up.  Here is my problem now:

If I am logged into the computer (doesn't matter which user, I'm using Administrator as the example), and I start the service, and stop the service manually, it screws around with that Administrator profile - which is great, because now any other user can log in, log out, the service seems to work correctly with their profiles.  The service is set to run under the Local System account.

I created a batch file to run at system startup:
    echo off
    net start "Run Autocad Licensing"
    net stop "Run Autocad Licensing"

Now, i'm assuming, because I wasn't physically logged into any profiles, it didn't lock anything up.  The next time I ran the service in a user account, the files were locked and again not deleted.

So my question is: what is the difference between running this service as Local System while I am logged in as Administrator, as opposed to running the same service from the same batch file before anyone has logged in?

~ Jonny
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12605908
500 Points...
0
 
LVL 41

Expert Comment

by:stevenlewis
ID: 12605967
>> what is the difference between running this service as Local System while I am logged in as Administrator, as opposed to running the same service from the same batch file before anyone has logged in
this is just a guess, but I think it may have to do with some services starting when a user logs on
0
 
LVL 41

Expert Comment

by:stevenlewis
ID: 12605978
BTW, the points don't mean much, so don't worry about them
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12606413
Hoping that 500 points may attract more to look into the problem and for you guys to keep at it!

>> this is just a guess, but I think it may have to do with some services starting when a user logs on

OK, well that batch file ran automatically as soon as the system started up, before I logged in as any users.  Is there anywhere I can see that the service started and stopped appropriately?  Like a log or something?
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12606430
What I'm saying is the service SHOULD have started and stopped before anyone logged in, controlled by that batch file (which DID run, according to the Scheduled Tasks area).  But is there a way of knowing for sure that the service DID in fact start successfully, then stop again?

~ Jonny
0
 
LVL 41

Expert Comment

by:stevenlewis
ID: 12606463
in the services msc, you can set a program to run if the service fails to start
so have it run a program, and let the "program" create a batch file
you can do this for first, second and subsequent failures
0
 
LVL 7

Expert Comment

by:tymes
ID: 12608642
So your problem is that this service runs as the user and so the users' settings are in use?  

First, you might create a new account that you don't need to move or delete or whatever (perhaps a local account) and run the service as that (edit the service and have it run as the local administrator).

You might also stop the service when people log on and stop it when they log off (or even when they start the program that needs the service and stop it when the program ends).  

This is autocad licensing so look into setting up a network service and move it off the desktops, you might have to pay more but perhaps you can run the licensed program on more desktops (even in remote locations that are still attached to the network).

You can add the following to the Script to debug.  The script may be running as an account that doesn't have permissions to start and stop services so you can run the script later as the same user.  
ECHO Restarting Service as %username%  >>C:\debug-acadl-logfile.txt

I also quickly considered adjusting the script so it used RUNAS /user:admin "net stop.." or you might actually need to use PSEXEC from wininternals to use a runas with a password in a script file.
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12609526
Tymes... so many of these suggestions have gone through my head, some I have played with, others I did not know where to start.  If you could please continue watching this thread, I will be picking up again first thing in the morning (sigh...) and will start checking these things out.

About creating the log file: I spent roughly 45 minutes just searching for that.  I can't believe it is that simple and googling didn't find anything.  I am very interested to see if those services did indeed start.  The batch file ran, but I dont think I have any way of seeing if the services failed or not.. so I figured maybe I can work on making a log.  Either that or would it be in the event viewer?  Forgot about that until just now...

Until tomorrow, have a good evening guys.

~ Jonny
0
 
LVL 7

Expert Comment

by:tymes
ID: 12610819
to also append the status of the service to the log file add a

SC QUERY "Run Autocad Licensing" >>C:\debug-acadl-logfile.txt

looking at this example you'll see my spooler is running (so I have to go catch it)
SC QUERY spooler

SERVICE_NAME: spooler
        TYPE               : 110  WIN32_OWN_PROCESS (interactive)
        STATE              : 4  RUNNING
                                (STOPPABLE,NOT_PAUSABLE,ACCEPTS_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0

0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12615123
How can I write custom text to this log, so I can follow the entire process all the way through?

For instance I'd like to see in the log...
Batch Started
Starting Service
[Query Service]
Stopping Service
[Query Service]
Batch Ending

Also, how are is it to get timestamps?

Thanks for your help.  I'm in the lab working on this now so hopefully I will figure some things out.

~ Jonny
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12615221
"looking at this example you'll see my spooler is running (so I have to go catch it)"
heh heh heh...
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12615847
Also, any way to write all the output to a file.... like if I have echo on, everything that comes through would be saved to the log file?
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12616087
OK I'm back to having the batch file run at system startup.  Sometimes it starts, sometimes it doesnt.  The first time I tested, it started, worked, had the 3 entries in the log (i'll post my batch code below), and the problem was actually solved.  Figured I should restart and log in directly as a student, but this time when I logged back in as administrator, I saw that the event had "failed to start."  Why?  Where can I see why it is failing?  Does it matter who I log in as?  Shouldn't it run the event (and the batch file) as the person whose credentials I entered (I used administrator account) even if no one logs in???

Batch file:

echo off
sc query "Run Autocad Licensing" >>C:\acad.log
net start "Run Autocad Licensing"
sc query "Run Autocad Licensing" >>C:\acad.log
net stop "Run Autocad Licensing"
sc query "Run Autocad Licensing" >>C:\acad.log
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12616105
It failed to start which means the batch file didn't even run... so forget about the batch file not working... it's not even running every time I start up.  What am I doing wrong?  Should I run the batch file as an automatic service on system startup?  (I have instsrv and srvany)
0
 
LVL 7

Expert Comment

by:tymes
ID: 12617271
So how did you set this system startup batfile to run?  In the Program start folder?  Right click on the shortcut and change the permissions to RUN AS the administrator (remember to restrict the write/modify permissons on the batfile that you run as an administrator).  Or did you make it a scheduled event that starts when the computer starts or when the person logs on?  Make it a scheduled task might help you.

Adding "ECHO %TIME% %USERNAME% >> C:\acad.log" would tell you who the script was running as.
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12617629
I have it scheduled to run as a scheduled task at system startup... the first time it worked and ran, the second time the task "failed to start..."

I'll try doing some logging with that information.
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12618701
It seems like this stupid service is just plain poorly written.

As I said, if I start and stop the service manually in the ./user profile, then it will lock up just that profile, leaving other users to turn on and off the service as needed, without locking their profiles.

What I ended up doing in place of scheduled events was to link my batch file into a new Automatic Service, running itself as the ./user account (which has administrative rights).  It ran, and I did figure out how to log everything, so I see that everything ran properly.  I logged in as a student, ran autocad (thus starting this service) and then logged back out, only to find that the studen't profile was locked... again!

Autocad is of no help, as they claim it is a problem with our setup, as opposed to with their service.  I am completely out of ideas.  This question is worth 500 points, because I really have no further ideas.

Something to keep in mind: *logging out* after using autocad for the first time since booting the computer keeps some files in the user's profile open, thus locking it.  Bypassing log out and directly *restarting or shutting down* after using autocad for the first time since booting the computer releases those files, and our Novell does its job completely, bringing the roaming profile up to the server, and then deleting the profile and its files from the local system.

I am about to tell the students to just restart every time they want to log off... this is such a mess :(

PLEASE, if you have any ideas at all, let me know.

~ Jonny
0
 
LVL 41

Expert Comment

by:stevenlewis
ID: 12620339
>> have it scheduled to run as a scheduled task at system startup... the first time it worked and ran, the second time the task "failed to start
the second time, was that aafter a restart or a log off?
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12620587
After a restart.  And I'm not using that anymore, since I seemingly couldn't get it to remember the 'user' account's password... guess it has a bad memory.  If you look above, you will see that I made the batch file run as an automatic service, and the service is running under the 'user' account.

Does that clear it up?

Thanks
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12657101
This is still unsolved.  Autodesk is of no help, nor did posting on the user forums on their site help.  I have posted a new question to see if I can get a workaround - restart the computers and delete the access profile folders once a week, night, whatever we need to do.  The question can be found here: http://www.experts-exchange.com/Operating_Systems/WinXP/Q_21217614.html.

If you don't mind, I am going to leave this question open for a while.  It is an issue that ultimately needs to be solved.  If after a week or two we can't find anything, I will ask that the question be PAQ'd and give out some points for those that at least got me closer to the solution.  Does this sound fair?

Thanks,
Jonny
0
 
LVL 41

Expert Comment

by:stevenlewis
ID: 12657266
Sounds good to me Jonny, I'm out of ideas :-(
0
 
LVL 7

Expert Comment

by:tymes
ID: 12658671
If this value is enabled After a user logs off from an interactive session, the locally cached version of the roaming User Profile is deleted.

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon
DeleteRoamingCache REG_DWORD 0=Off or value is removed; 1= On.


To do something manually, use DELPROF.EXE in the windows resource Kit.  You can have it delete profiles that haven't been used in a specific number of days...

DELPROF.EXE /q /i /d:5
quite, ignore errors, profiles 5 days old.
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12658993
Checking it out...
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12659123
Didn't work :(  Worth a shot though.  The problem here is that Novell is removing the roaming profiles already, this isn't technically a roaming profile "cache"... For instance if I pick any given computer in this particular lab, there are a bunch of profile folders left over in C:\documents and settings, all from users launching autocad after a restart.  But, if I go into Users and Groups under Comp Management, or even under Profile Information under System preferences, only the 2 local users show up (Administrator and User).  This is because Novell successfully removes the profile from windows, but while trying to remove the user's files, when it hits the locked file, it just gives up on deleting the rest of that profile folder.  Now I'm left with a non-user profile folder (like, it's not bound to any users... it's as if you had just created a new folder in Documents and Settings and stuck a bunch of files in there), and the next time that user logs in, Windows creates a new folder and calls it username.000.

Just typing that gave me an idea.  By default, windows will not overwrite profile folders in Docs and Settings.  For instance, let's say I have a new user named "Joe" but have not logged him in yet, and I go create a folder called "joe" in C:\Documents and Settings.  Now when I log him in for the first time, Windows will not overwrite the folder that is already there, nor will it just incorporate whatever is in that folder into the profile... instead it makes a new folder called "joe.000" (I have also seen username.computername or username.windows, but windows seems to favor the .000 in our case).  Can I somehow tell windows to just use the folder that is already there?  So even if I already have "joe" in there it just overwrites the old files with those from the profile.

~ Jonny
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12813654
Tymes,

How might I do two things if an IF statement comes out to meet the conditions?

If [condition] [command 1] [command 2]

Looking for logging puposes so I know which directories are being deleted.  It's nice to know that the script is running when it's supposed to, but I just want to be able to go into my log and see that a bunch of folders were deleted too.

Thanks
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12899503
Well guys I am going to ask that this question be paq'd and points refunded.  The issue was definately with the Autocad service, and Autodesk is not willing to admit that.  Our solution was to get rid of any lingering profiles every time the computer starts up.  See my other question which has since been closed for more information: ttp://www.experts-exchange.com/Operating_Systems/WinXP/Q_21217614.html

I Plan on giving out points to those who did help over here.  I just don't think I should accept anything as an "answer" in this question as apparently there is none, or that Autodesk just threw that service out there without full testing.

Thanks again for everyone's help.

~ Jonny
0
 
LVL 41

Expert Comment

by:stevenlewis
ID: 12900108
Cool by me :-)
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12912066
Closed, 500 points refunded.

modulo
Community Support Moderator
Experts Exchange
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12912657
Tymes & Steven - please post in the following question so I can give you some points for helping out here.  Thanks again!
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12912661
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 12936594
Still waiting for Tymes...
0
 

Expert Comment

by:hpelgato
ID: 13128078
well, if those web pages doesn't work, just star on "safe mode", restar ur system, so when boot press f8 on keyboard several times until the screen shoes boot screen, then select "safe mode"... when windows stars, try to delete the files u need selectin' those files and press "SHIFT+SUPR"... that's all! good luck

HP
0
 

Expert Comment

by:colinuk
ID: 13138699
Download Moveon boot.

http://www.gibinsoft.net/gipoutils/fileutil/rightview.htm

30 day trial, just locate the file/s reboot files gone.

colin.
0
 
LVL 7

Expert Comment

by:tymes
ID: 13180602
in regards to your question pertain to IF statements in bat file sy
if "%var%"=="2" (
  rem do this stuff
) else (
  rem do other stuff
)

so
if 1==1 (echo yes) else (echo no)
will say yes
if 1==2 (echo yes) else (echo no)
will say no

Rather than deleting files, you might try renaming them and deleting them a iteration later.
del %userprofile%\*.former         && rem del files from a while back.
ren %userprofile%\*.* *.former   && rem rename existing files that may be in use
sometimes you can't delete inuse files but you can rename them.
0
 

Expert Comment

by:joykennedyh
ID: 26211534
I WAS successful in deleting NTUSER.dat -- Windows XP Professional w/SP3.  I started the PC in safe mode, logged in as administrator, and deleted the entire directory for the users that had the NTUSER.dat file.  I had tried MOST of the suggestions posted, and logging in as Administrator in SAFE MODE was the ONLY SOLUTION to get rid of the UNRULY NTUSER.dat file.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are 2 things you must have in order to connect to the internet behind a router, The "Gateway IP" of the router, which is usually something like 192.168.xxx.1, I've seen routers with default values of: 192.168.0.1, 192.168.1.1, 192.168.11.1, …
cPanel is a Unix based web hosting control panel that provides a graphical interface and automation tools designed to simplify the process of hosting a web site. cPanel utilizes a 3 tier structure that provides functionality for administrators, rese…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question