Home | History | Annotate | Download | only in win
      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/base_api.h"
     31 #include "base/string16.h"
     32 
     33 struct IPropertyStore;
     34 struct _tagpropertykey;
     35 typedef _tagpropertykey PROPERTYKEY;
     36 
     37 namespace base {
     38 namespace win {
     39 
     40 BASE_API void GetNonClientMetrics(NONCLIENTMETRICS* metrics);
     41 
     42 // Returns the string representing the current user sid.
     43 BASE_API bool GetUserSidString(std::wstring* user_sid);
     44 
     45 // Returns true if the shift key is currently pressed.
     46 BASE_API bool IsShiftPressed();
     47 
     48 // Returns true if the ctrl key is currently pressed.
     49 BASE_API bool IsCtrlPressed();
     50 
     51 // Returns true if the alt key is currently pressed.
     52 BASE_API bool IsAltPressed();
     53 
     54 // Returns false if user account control (UAC) has been disabled with the
     55 // EnableLUA registry flag. Returns true if user account control is enabled.
     56 // NOTE: The EnableLUA registry flag, which is ignored on Windows XP
     57 // machines, might still exist and be set to 0 (UAC disabled), in which case
     58 // this function will return false. You should therefore check this flag only
     59 // if the OS is Vista or later.
     60 BASE_API bool UserAccountControlIsEnabled();
     61 
     62 // Sets the application id in given IPropertyStore. The function is intended
     63 // for tagging application/chromium shortcut, browser window and jump list for
     64 // Win7.
     65 BASE_API bool SetAppIdForPropertyStore(IPropertyStore* property_store,
     66                                        const wchar_t* app_id);
     67 
     68 // Adds the specified |command| using the specified |name| to the AutoRun key.
     69 // |root_key| could be HKCU or HKLM or the root of any user hive.
     70 BASE_API bool AddCommandToAutoRun(HKEY root_key, const string16& name,
     71                                   const string16& command);
     72 // Removes the command specified by |name| from the AutoRun key. |root_key|
     73 // could be HKCU or HKLM or the root of any user hive.
     74 BASE_API bool RemoveCommandFromAutoRun(HKEY root_key, const string16& name);
     75 
     76 // Reads the command specified by |name| from the AutoRun key. |root_key|
     77 // could be HKCU or HKLM or the root of any user hive. Used for unit-tests.
     78 BASE_API bool ReadCommandFromAutoRun(HKEY root_key,
     79                                      const string16& name,
     80                                      string16* command);
     81 }  // namespace win
     82 }  // namespace base
     83 
     84 #endif  // BASE_WIN_WIN_UTIL_H_
     85