1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 """Dumps a Windows shortcut's property bag to stdout.
7 This is required to confirm correctness of properties that aren't readily
8 available in Windows UI.
12 from pywintypes
import IID
14 from win32com
.propsys
import propsys
15 from win32com
.propsys
import pscon
18 def PrintShortcutProperties(shortcut_path
, dump_all
):
19 properties
= propsys
.SHGetPropertyStoreFromParsingName(shortcut_path
)
21 print 'Known properties (--dump-all for more):'
23 app_id
= properties
.GetValue(pscon
.PKEY_AppUserModel_ID
).GetValue()
24 print '\tAppUserModelId => "%s"' % app_id
26 # Hard code PKEY_AppUserModel_IsDualMode as pscon doesn't support it.
27 PKEY_AppUserModel_IsDualMode
= (IID('{9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3}'),
29 dual_mode
= properties
.GetValue(PKEY_AppUserModel_IsDualMode
).GetValue()
30 print '\tDual Mode => "%s"' % dual_mode
32 # Dump all other properties with their raw ID if requested, add them above
33 # over time as we explicitly care about more properties, see propkey.h or
34 # pscon.py for a reference of existing PKEYs' meaning.
36 print '\nOther properties:'
37 for i
in range(0, properties
.GetCount()):
38 property_key
= properties
.GetAt(i
)
39 property_value
= properties
.GetValue(property_key
).GetValue()
40 print '\t%s => "%s"' % (property_key
, property_value
)
44 usage
= 'usage: %prog [options] "C:\\Path\\To\\My Shortcut.lnk"'
45 parser
= optparse
.OptionParser(usage
,
46 description
="Dumps a shortcut's properties.")
47 parser
.add_option('-a', '--dump-all', action
='store_true', dest
='dump_all',
49 options
, args
= parser
.parse_args()
52 parser
.error('incorrect number of arguments')
54 PrintShortcutProperties(args
[0], options
.dump_all
)
57 if __name__
== '__main__':