2
1
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
Setlocal
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 :)
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 – 2011-05-16T21:44:20.197
Nope, Windows informs me that the application must be closed forcefully :( – JonnyReeves – 2011-05-17T06:27:32.917
did you find any other solutions? – kluka – 2012-11-05T18:37:26.620