
On Windows Vista, 2008, 2008 R2 and 7, changing the configuration of the winrm service will fail with an "Access is denied" error if the User Account Control remote restrictions are enabled. The solution to this issue is to temporarily disable the User Account Control remote restrictions. https://support.microsoft.com/kb/951016 Co-Authored-By: Robert Tingirica <rtingirica@cloudbasesolutions.com> Closes-Bug: #1379854 Change-Id: I07b61b94900d39ad0aee544e26ee37bbc94bf7b9
42 lines
1.7 KiB
Python
42 lines
1.7 KiB
Python
# Copyright 2014 Cloudbase Solutions Srl
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
from six.moves import winreg
|
|
|
|
|
|
class WindowsSecurityUtils(object):
|
|
_SYSTEM_POLICIES_KEY = ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\"
|
|
"Policies\\System")
|
|
_LATFP_VALUE_NAME = "LocalAccountTokenFilterPolicy"
|
|
|
|
# https://support.microsoft.com/kb/951016
|
|
def set_uac_remote_restrictions(self, enable=True):
|
|
with winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE,
|
|
self._SYSTEM_POLICIES_KEY) as key_name:
|
|
winreg.SetValueEx(key_name, self._LATFP_VALUE_NAME, 0,
|
|
winreg.REG_DWORD, int(not enable))
|
|
|
|
def get_uac_remote_restrictions(self):
|
|
try:
|
|
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
|
|
self._SYSTEM_POLICIES_KEY) as key:
|
|
(value, regtype) = winreg.QueryValueEx(key,
|
|
self._LATFP_VALUE_NAME)
|
|
return not bool(value)
|
|
except WindowsError as e:
|
|
if e.errno == 0x2:
|
|
return True
|
|
else:
|
|
raise
|