Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On My Windows 7 machine I have two user accounts, one Admin account for myself and one regular account for my wife. Both of us use iTunes to manage our separate music libraries and Apple devices.

When my wife tries to launch iTunes she is often confronted with the error message:

You cannot open the application "iTunes" because another user has it open. Ask the other user to quit the application, then try again.

As she does not know my password she currently has no way of opening iTunes which results in much frustration and I fear is not good for my marriage long term.

I have tried a couple of solutions; the first was to attempt to log my user off via a bash script; I came up with the following:

for /f "tokens=1,2" %%i IN ('quser ^| find /i "jonny"') DO logoff %%j

This works just fine from my own account, but when I try and invoke it under my wife's profile I am informed that

Could not log off Session #2, Error Code 5.

Haha, and what would you know, as I was writing up this problem on SuperUser I just had a thought and modified the script to include a runas /savecred in there; and what do you know it worked!

So, for those of you who want to log off an administrator in order to launch iTunes, here's the Batch Script you need - note that the first time you run it, you will be prompted for your password; subsequent invocations will not prompt.

@echo off

set USERNAME="the_username_to_logoff"
set ADMIN_USER="an_admin_account"

for /f "tokens=1,2" %%i IN ('quser ^| find /i %USERNAME%') DO set SESSION_ID=%%j
runas /savecred /user:%ADMIN_USER% "logoff %SESSION_ID%"

If anyone has a better solution, please do post it as I'm still not 100% happy with my profile being logged off just incase I have any unsaved work.

And here we go, after a bit more googling it's possible to make use of TASKKILL to terminate the iTunes.exe process:

runas /savecred /user:%ADMIN_USER% "taskkill /f /im 'itunes.exe'"

However this is still not 100% ideal as you have to forcefully terminate the iTunes process which results in iTunes complaining that it suffered an unclean shutdown the next time I fire it up.

Shame Apple couldn't have just written iTunes to allow multiple instances on the same machine, eh :)

share|improve this question
iTunes is proof Apple doesn't care about its customers. Well, other than it have them. If you remove the /F from Taskkill, does it not shutdown nicely? – uSlackr May 16 '11 at 21:44
Nope, Windows informs me that the application must be closed forcefully :( – JonnyReeves May 17 '11 at 6:27
did you find any other solutions? – klyonrad Nov 5 '12 at 18:37

You must log in to answer this question.

Browse other questions tagged .