Skip to content

Commit

Permalink
Merge pull request #25298 from twangboy/fix_25275
Browse files Browse the repository at this point in the history
Continue if profile not found
  • Loading branch information
twangboy committed Jul 9, 2015
2 parents 0a7ec11 + 0e29607 commit fb717d3
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions salt/modules/win_useradd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
Module for managing Windows Users
:depends:
- os
- pywintypes
- win32api
- win32net
Expand All @@ -25,7 +24,6 @@
log = logging.getLogger(__name__)

try:
import os
import pywintypes
import win32api
import win32net
Expand Down Expand Up @@ -298,22 +296,14 @@ def delete(name,

# Remove the User Profile directory
if purge:
# If the profile is not defined, get the profile from the registry
if user_info['profile'] == '':
profiles_dir = __salt__['reg.read_key'](hkey='HKEY_LOCAL_MACHINE',
path='SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList',
key='ProfilesDirectory')
profiles_dir = profiles_dir.replace('%SystemDrive%', os.environ['SystemDrive'])
user_info['profile'] = r'{0}\{1}'.format(profiles_dir, name)

# Make sure the profile exists before deleting it
# Otherwise this will throw an error
if os.path.exists(user_info['profile']):
try:
sid = getUserSid(name)
try:
win32profile.DeleteProfile(sid)
except pywintypes.error as exc:
(number, context, message) = exc
win32profile.DeleteProfile(sid)
except pywintypes.error as exc:
(number, context, message) = exc
if number == 2: # Profile Folder Not Found
pass
else:
log.error('Failed to remove profile for {0}'.format(name))
log.error('nbr: {0}'.format(number))
log.error('ctx: {0}'.format(context))
Expand Down

0 comments on commit fb717d3

Please sign in to comment.