View Single Post
Old 02-25-2008   #6 (permalink)
Jeff


 
 

Re: deleting files that meet specific criteria

On Feb 25, 5:46 pm, Jeff <jeff.hill...@xxxxxx> wrote:
Quote:

> Boomer,
>
> I found an SDK that might help you with what you want to do:
>
> Windows Media Format 11 SDKhttp://msdn2.microsoft.com/en-us/library/aa387410(VS.85).aspx
>
> This SDK lets you query all kinds of DRM information for a file, and
> the SDK comes with a whole bunch of useful sample code. It doesn't
> look like any of it is easily accessible from .NET (no TLBs or COM
> servers), so you may have to write a small Win32 console application
> to query what you want, and then call it from your PowerShell script.
>
> I hope this helps.
>
> Jeff
>
> Jeff wrote:
Quote:

> > On Feb 25, 1:00 pm, Boomer <Boo...@xxxxxx> wrote:
Quote:

> > > Hi all,
>
Quote:
Quote:

> > > My intent is use PS to search through my digital music library and remove
> > > all DRM files for which I no longer have rights.
>
Quote:
Quote:

> > > I used to subscribe to the URGE music store, and have a bunch of files
> > > tagged with "protected content" under the License Property Set. This
> > > "license" tab can be viewed as a tab along side the general, the security,
> > > and the summary tabs, if one clicks on the file's property.
>
Quote:
Quote:

> > > For the life of me, I cannot find anything that describes how to show/list
> > > the presence of the "license" tab. TypeName: System.IO.FileInfo ... I can
> > > retreive info about the file with the memberType Property ... Nothing out of
> > > the ordinary is listed for memberType when I enter the following command on a
> > > file in question:
>
Quote:
Quote:

> > > > gci | gm
>
Quote:
Quote:

> > > I figured it would the easiest to do it in PS, but it didn't turn out to be
> > > such a good assumption.
>
Quote:
Quote:

> > > Your assistance is greatly appreciated.
>
Quote:

> > Boomer,
>
Quote:

> > I looked around at what was available through Windows Media player,
> > and the best I could come up with is this little script that tells you
> > if a file has DRM protection or not:
>
Quote:

> > # Get-Protected.ps1
> > param( [string] $wmaFile )
>
Quote:

> > if ( Test-Path $wmaFile )
> > {
> > $wmplayer = New-Object -ComObject "WMPlayer.OCX"
>
Quote:

> > $media = $wmplayer.newMedia( $wmaFile )
>
Quote:

> > [bool]::Parse( $media.getItemInfo( "Is_Protected" ) )
> > }
> > # Get-Protected.ps1
>
Quote:

> > If you want much more information that that, it looks like you might
> > need to get a license from Microsoft for a DRM SDK of some kind:
> >http://msdn2.microsoft.com/en-us/win.../bb190309.aspx
>
Quote:

> > These licenses are necessary if you are creating an application to
> > manage licenses or something like that, so it seems like they
> > shouldn't be necessary if all you want to do is query the
> > information. If you do find anything, please post back here; I would
> > certainly be interested.
>
Quote:

> > Jeff
Boomer,

In case this is the route you decide to take, here is a small console
application that determines if playback is allowed for a DRM-protected
file:

#include <atlbase.h>
#include <TCHAR.H>
#include "wmsdk.h"

int _tmain( int argc, wchar_t *argv[] )
{
if ( SUCCEEDED( CoInitialize( NULL ) ) )
{
int nCount = MultiByteToWideChar(
CP_ACP, 0, (LPCSTR)argv[ 1 ], -1, NULL, 0 );

wchar_t *pwszFileName = new wchar_t[ nCount ];

MultiByteToWideChar(
CP_ACP, 0, (LPCSTR)argv[ 1 ], -1, pwszFileName, nCount );

// check to see if the file is protected with DRM
BOOL bProtected;

HRESULT hr = WMIsContentProtected(
pwszFileName, &bProtected );

if ( SUCCEEDED( hr ) )
{
// if the file isn't protected with DRM,
// we don't need to continue
if ( !bProtected )
{
wprintf( L"Playback Allowed: True\n" );
}
else
{
// create a meta data editor
CComPtr<IWMMetadataEditor> spEditor;
hr = WMCreateEditor( &spEditor );

// open the media file
if ( SUCCEEDED( hr ) )
{
hr = spEditor->Open( pwszFileName );
}

// QI for the DRM editor
CComQIPtr<IWMDRMEditor> spDRMEditor( spEditor );
WMT_ATTR_DATATYPE wmtAttribute;
BYTE playbackAllowed[ 4 ];
WORD wLength;

if ( SUCCEEDED( hr ) && spDRMEditor )
{
// get the 'playback allowed' property value
hr = spDRMEditor->GetDRMProperty(
g_wszWMDRM_ActionAllowed_Playback,
&wmtAttribute, playbackAllowed,
&wLength );

if ( SUCCEEDED( hr ) )
{
wprintf( L"Playback Allowed: %s\n",
( (BOOL)*playbackAllowed ? L"True"
: L"False" ) );
}
}
}
}

CoUninitialize();
}

return 0;
}

This should be enough to determine if you want to keep a file or not.

Good luck.

Jeff
My System SpecsSystem Spec