Old 2nd September 2009, 09:45   #1
ginglese
Junior Member
 
Join Date: Jul 2006
Posts: 42
[delete user account] remaining home directory

Hi all,

During my install I'm creating a user account (postgres). Then When uninstalling I'm using the UserMgr plugin to delete a user account.
User account is correctly deleted but the user home directory remain and the next time i install the software i have a new home directoy named postgres.%computer name%.001 ...

I made a lot of search on the web to find a way do delete this remaining directory and ended with the only solution that is to retrieve the user home directory thanks to the ProfileImagePath registry keys.

But to do so I need to retreive first the user profil SID, then go to the registry and look to ProfileImagePath keys.

here is an exemple made with win32 c# (i guess)
code:

require 'win32/security'
require 'win32/registry'

key = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\"
usr = 'some_user'

sec = Win32::Security::SID.open(usr)
key += sec.to_s

Win32::Registry::HKEY_LOCAL_MACHINE.open(key) do |reg|
puts reg['ProfileImagePath']
end



to do the same with C++ win32 code i need to use LookupAccountName then convert SID to string ...

do you have better solution ? or is nsis providing something for that ?
ginglese is offline   Reply With Quote
Old 2nd September 2009, 12:16   #2
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
Well, can't you just get the home directory with the UserMgr plugin (UserMgr::GetUserInfo) before deleting the account, then delete the account, and then delete the Home directory you just got before?
jpderuiter is offline   Reply With Quote
Old 2nd September 2009, 12:30   #3
ginglese
Junior Member
 
Join Date: Jul 2006
Posts: 42
Hi,
Thanks for the tip but the Home directory from UserMgr plugin is always empty (you can look at a user account with the administrator tools, you have access to the home directory field).
ginglese is offline   Reply With Quote
Old 2nd September 2009, 12:57   #4
ginglese
Junior Member
 
Join Date: Jul 2006
Posts: 42
Hello everybody,

I think I found a way (replace "pilgrim" and "postgres" by your server name and user account name):

-LookupAccountNameW retrieves SID from user name
-ConvertSidToStringSid converts SID to something like "S-1-5-21-1801674531-*********-**********-***"
-Then retrieve "ProfileImagePath" from HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList + string SID
-End by expending registry values.

code:

System::Call '*(&w${NSIS_MAX_STRLEN})i.R8'
System::Call 'advapi32::LookupAccountNameW(w "pilgrim",w "postgres",i R8,*i ${NSIS_MAX_STRLEN}, w .R1, *i ${NSIS_MAX_STRLEN}, *i .r0)i .r1'
System::Call 'advapi32::ConvertSidToStringSid(i R8,*t .R1)i .r0'

ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$R1" "ProfileImagePath"
ExpandEnvStrings $0 $0

ginglese is offline   Reply With Quote
Old 2nd September 2009, 14:25   #5
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
When the Home directory from UserMgr is empty, it means that it's location has never been modified, and thus it is the default location.
But I'm not sure right now how to get this default location...

I can add a GetUserSID function to UserMgr to simplify your solution, but I guess it's not really needed right now.
jpderuiter is offline   Reply With Quote
Old 2nd September 2009, 14:39   #6
ginglese
Junior Member
 
Join Date: Jul 2006
Posts: 42
It would be great to have it in UserMgr plugin.
You may also want to add GetUserStringSID.

Someone may also need the reverse function GetUserNameFromSID...
ginglese is offline   Reply With Quote
Old 2nd September 2009, 18:31   #7
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
OK, done.
jpderuiter is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump