Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / installer / tools / shortcut_properties.py
blob96a446b7cbbed2749d10bada7bd34f9e37ff8e87
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.
9 """
11 import optparse
12 from pywintypes import IID
13 import sys
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}'),
28 11)
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.
35 if dump_all:
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)
43 def main():
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',
48 default=False)
49 options, args = parser.parse_args()
51 if len(args) != 1:
52 parser.error('incorrect number of arguments')
54 PrintShortcutProperties(args[0], options.dump_all)
57 if __name__ == '__main__':
58 sys.exit(main())