win_util.h revision dc0f95d653279beabeb9817299e2902918ba123e
1// Copyright (c) 2011 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.
4
5// =============================================================================
6// PLEASE READ
7//
8// In general, you should not be adding stuff to this file.
9//
10// - If your thing is only used in one place, just put it in a reasonable
11//   location in or near that one place. It's nice you want people to be able
12//   to re-use your function, but realistically, if it hasn't been necessary
13//   before after so many years of development, it's probably not going to be
14//   used in other places in the future unless you know of them now.
15//
16// - If your thing is used by multiple callers and is UI-related, it should
17//   probably be in app/win/ instead. Try to put it in the most specific file
18//   possible (avoiding the *_util files when practical).
19//
20// =============================================================================
21
22#ifndef BASE_WIN_WIN_UTIL_H_
23#define BASE_WIN_WIN_UTIL_H_
24#pragma once
25
26#include <windows.h>
27
28#include <string>
29
30#include "base/string16.h"
31
32struct IPropertyStore;
33struct _tagpropertykey;
34typedef _tagpropertykey PROPERTYKEY;
35
36namespace base {
37namespace win {
38
39void GetNonClientMetrics(NONCLIENTMETRICS* metrics);
40
41// Returns the string representing the current user sid.
42bool GetUserSidString(std::wstring* user_sid);
43
44// Returns true if the shift key is currently pressed.
45bool IsShiftPressed();
46
47// Returns true if the ctrl key is currently pressed.
48bool IsCtrlPressed();
49
50// Returns true if the alt key is currently pressed.
51bool IsAltPressed();
52
53// Returns false if user account control (UAC) has been disabled with the
54// EnableLUA registry flag. Returns true if user account control is enabled.
55// NOTE: The EnableLUA registry flag, which is ignored on Windows XP
56// machines, might still exist and be set to 0 (UAC disabled), in which case
57// this function will return false. You should therefore check this flag only
58// if the OS is Vista or later.
59bool UserAccountControlIsEnabled();
60
61// Sets the application id in given IPropertyStore. The function is intended
62// for tagging application/chromium shortcut, browser window and jump list for
63// Win7.
64bool SetAppIdForPropertyStore(IPropertyStore* property_store,
65                              const wchar_t* app_id);
66
67// Adds the specified |command| using the specified |name| to the AutoRun key.
68// |root_key| could be HKCU or HKLM or the root of any user hive.
69bool AddCommandToAutoRun(HKEY root_key, const string16& name,
70                         const string16& command);
71// Removes the command specified by |name| from the AutoRun key. |root_key|
72// could be HKCU or HKLM or the root of any user hive.
73bool RemoveCommandFromAutoRun(HKEY root_key, const string16& name);
74
75// Reads the command specified by |name| from the AutoRun key. |root_key|
76// could be HKCU or HKLM or the root of any user hive. Used for unit-tests.
77bool ReadCommandFromAutoRun(HKEY root_key,
78                            const string16& name,
79                            string16* command);
80}  // namespace win
81}  // namespace base
82
83#endif  // BASE_WIN_WIN_UTIL_H_
84