No announcement yet.

[delete user account] remaining home directory

  • Filter
  • Time
  • Show
Clear All
new posts

  • [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)

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

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

    sec =
    key += sec.to_s do |reg|
    puts reg['ProfileImagePath']

    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 ?

  • #2
    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?


    • #3
      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).


      • #4
        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.


        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


        • #5
          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.


          • #6
            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...


            • #7
              OK, done.