iTunes warning message on quit due to scripting


Wrote the following in PowersHell as a quick iTunes demonstration:

$iTunes = New-Object -ComObject iTunes.Application
$LibrarySource = $iTunes.LibrarySource
foreach ($PList in $LibrarySource.Playlists)
  write-host $

This works well and pulls back a list of playlist names. However on trying to close iTunes a warning appears

One or more applications are using the iTunes scripting interface. Are you sure you want to quit?

Obviously I can just ignore the message and press [Quit] or just wait the 20 seconds or so, but is there a clean way to tell iTunes that I've finished working with it?

Itunes 7.7.1, Windows XP


Here is one thing that I did on my a Powershell script that adds podcasts to iTunes. I use Juice on a server to download all the podcasts that I listen to. The script uses .Net methods to release the COM objects. When I wrote my iTunes script I had read a couple of articles that stated you should release your COM objects using .NET.


I also run my scripts the majority of time from a shortcut, not from the powershell prompt.

Based on your comments, I did some testing and I determined that I would get the message when running against iTunes, if I ran my script in a way that leaves powershell running. iTunes seems to keep track of that. Running the script in a manner that exits it's process after running, eliminated the message.

One method of running your script from powershell, is to prefix your script with powershell.

powershell .\scriptname.ps1

The above command will launch your script and then exit the process that was used to run it, but still leaving you at the powershell prompt.

By : bruceatk

You should be able to set $itunes to $null. Alternatively, $itunes should have a quit method you can call. $itunes.quit()

You could loop the groups like i did in this answer:

After reading some more, the easiest thing would be to use the System.DirectoryServices.AccountManagement namespace. Here is how it can be used:


public static bool IsUserInGroup(string username, string groupname, ContextType type)
    PrincipalContext context = new PrincipalContext(type);

    UserPrincipal user = UserPrincipal.FindByIdentity(
    GroupPrincipal group = GroupPrincipal.FindByIdentity(
        context, groupname);

    return user.IsMemberOf(group);
By : Espo

This video can help you solving your question :)
By: admin