Archive: UserMgr Plugin


UserMgr Plugin
  Hello Ivan,

I uploaded a new version of the plugin, which has a new Function "GetCurrentDomain".

http://nsis.sourceforge.net/UserMgr_plug-in

This function will return the domainname you are currently logged in to (in your case "mshome").

Best regards,
jpderuiter

P.S.: this is a follow up of the "New Plugin" thread on this forum:
http://forums.winamp.com/showthread....postid=2477038


Environmental variables changed creating a new user
  Hi all,

After I created a new user, I make some shortcuts in the start menù, but I find those shortcuts in the "newuser" menù, not in the current user menù. (but I want them in the current user menù!)
It seems like UserMgr pluging changed the environmental variable when creating the user.

Any suggestions?

Many thanks,
Luca

This is my nsis code:

UserMgr::CreateAccountEx "newuser" "password" "-" "-" "-" "UF_PASSWD_CANT_CHANGE|UF_DONT_EXPIRE_PASSWD"
Pop $0
${If} $0 != "OK"
Quit
${EndIf}

UserMgr::AddToGroup ${AEPUSER} "Users"
Pop $0
${If} $0 != "OK"
Quit
${EndIf}

UserMgr::BuiltAccountEnv ${AEPUSER} ${AEPPWD}
Pop $0
${If} $0 != "OK"
Quit
${EndIf}

CreateDirectory "$SMPROGRAMS\myapp"
CreateShortCut "$SMPROGRAMS\myapp\myapp.lnk" "$INSTDIR\myapp.exe" "" "$INSTDIR\myapp.exe" 0


Hello coppolo,

I tried the following:


SetShellVarContext current

MessageBox MB_OK "$SMPROGRAMS"

UserMgr::CreateAccountEx "myuserA" "mypassword" "" "" "" "UF_PASSWD_NOTREQD|UF_DONT_EXPIRE_PASSWD"
Pop $0

UserMgr::BuiltAccountEnv "myuserA" "mypassword"
Pop $0

MessageBox MB_OK "$SMPROGRAMS"

UserMgr::DeleteAccount "myuserA"
Pop $0

MessageBox MB_OK "$SMPROGRAMS"


All 3 Messageboxes show the Startmenu programs folder of the current user, not the new created user.

But as soon as I comment the first messagebox out, the other 2 Messageboxes both show the Startmenu programs folder of the new created user!

I'm not sure what is causing this, but as far as I can see the UserMgr plugin does not change the environmental variable at all.

Anyone else?

Regards,
jpderuiter

Re: UserMgr Plugin
 

Originally posted by jpderuiter
[B]Hello Ivan,

I uploaded a new version of the plugin, which has a new Function "GetCurrentDomain".

http://nsis.sourceforge.net/UserMgr_plug-in

This function will return the domainname you are currently logged in to (in your case "mshome").
Thanks, this is exactly what I need. Unfortunately, when I call this new function the installer just crashes.

I have an actual domain here, not a workgroup. Not sure if this would affect anything. I tested it on 2 different domains and 2 different machines and the behavior is the same.

Exception Information
Code: 0xc0000005 Flags: 0x00000000
Record 0x00...00 Address: 0x00...05c

Hello Ivan,

unfortunately I'm in a workgroup, and it was working correctly for me.

But a used another combination of API's to get the domainname, and I uploaded it to the wiki.

Can you try if it works now?

Best regards,
Jan Pieter


Originally posted by jpderuiter
Hello Ivan,

unfortunately I'm in a workgroup, and it was working correctly for me.

But a used another combination of API's to get the domainname, and I uploaded it to the wiki.

Can you try if it works now?

Best regards,
Jan Pieter
The result is pretty much the same. I have to complete some other work, but I want to come back to this.

Can you create a pdb file and upload it somewhere so I can debug? It's a pain to build the project myself since I am running different Visual Studio version, and don't have libc.

Hello Ivan,

I'm sorry to hear that, and that I'm unable to help now.

I sent you a private message with a link to the Debug version, incl the pdb.
I also altered the GetCurrentDomain again, so maybe it's working now.

Best regards,
Jan Pieter


This installer crashes every time I try to run it:

Name "UsrMgrTest"
OutFile "UsrMgrTest.exe"
ShowInstDetails show
Page instfiles

Section "" ;No components page, name is not important
UserMgr::HasPrivilege "Tobbe" "SeInteractiveLogonRight "
Pop $0
DetailPrint ">$0<"
SectionEnd

Am I doing something wrong here?

Hello all,

I uploaded a new version of the plugin with a bugfix for the crashing installer.

@Tobbe:
I tried your script, and it's not crashing anymore, but it wasn't crashing before on the HasPrivilege call, only when exiting the installer.

@Ivan:
I tried the GetCurrentDomain function at work, and it's returning the domain properly.

@coppolo:
Your problem isn't solved yet.
A workaround could be creating the shortcuts before calling BuiltAccountEnv, or storing the $SMPROGRAMS string in another variable.

Best regards,
jpderuiter


It still crashes for me. It crashes before it prints anything to the log window.


Hmm, strange.

I assume you are using NSIS v2.42?
Are other UserMgr funtions crashing the installer as well?


Hmm, I'm using 2.37. Let me upgrade and I'll report back


So I upgraded to 2.42 and now I get different results :)

With the latest version of UserMgr I get this:
Invalid command: UserMgr::HasPrivilege
Invalid command: UserMgr::GetCurrentUserName

UserMgr::GetUserInfo "Tobbe" "HOMEDIR" doesn't give me the Invalid command error, but it only returns an empty string.

My installer does not crash however :)

With the old version I don't get any Invalid command errors, but "HasPrivilege" returns ERROR LsaEnumerateAccountRights and GetUserInfo only returns an empty string. GetCurrentUserName does however correctly return "Tobbe"

EDIT: With the old version I get the behavior you describe with the installer crashing when closing it.


Originally posted by jpderuiter
Hmm, strange.

I assume you are using NSIS v2.42?
Are other UserMgr funtions crashing the installer as well?
I am getting a crash from calling any function now - tried a few. I am on NSIS 2.41 but can't upgrade for now.

Well, I have used the new NSIS Plugin API coming with NSIS v2.42, so I think that's the reason why it's crashing.
So you should upgrade to 2.42 to make the plugin work.

For the time being you can use the older plugin version dated 22:06, 1 February 2008:
http://nsis.sourceforge.net/File:UserMgr.zip


Originally posted by jpderuiter
Well, I have used the new NSIS Plugin API coming with NSIS v2.42, so I think that's the reason why it's crashing.
So you should upgrade to 2.42 to make the plugin work.

For the time being you can use the older plugin version dated 22:06, 1 February 2008:
http://nsis.sourceforge.net/File:UserMgr.zip
Ok, that makes sense :D

You should make a note in BOLD letters on the wiki page that this version is for 2.42+ only. Also include a link to older versions as well there :)

I'll give 2.42 a shot. I just hope it doesn't break the old plugins I am using.

Awesome, it works perfectly with NSIS 2.42. It didn't break any old plugins either :)


Ivan,

The way I see it is that you should always have to use the newest version.
And well, I haven't noticed any plugin didn't work with v2.42.
v2.42 is supposed to be backwards compatible with pre-v2.42 plugins.


@Ivan:
Ah, you already found out ;-)

@Tobbe:
Sorry, I missed your last post.
Did you place the UserMgr plugin in the Plugins directory again after upgrading to v2.42.
Since the installer removes all plugin...


Firefox seems to be caching the download or something... Could you please add a version number to the downloadable file? Thanks


Well, that's not how the NSIS wiki page works, or I'll have to make a new file page for each new version.

But I'll attach the plugin with this post.


Perfect! Thank you :)


Originally posted by jpderuiter
Ivan,

The way I see it is that you should always have to use the newest version.
And well, I haven't noticed any plugin didn't work with v2.42.
v2.42 is supposed to be backwards compatible with pre-v2.42 plugins.
I would still make a note of the minimum required version of NSIS, because 99% of the plugins don't require 2.42 yet. Someone might not even realize 2.42 is out or they might be too lazy to upgrade if they feel the changelog doesn't affect them. ;)

Now I can run the plugin but there is one thing I find weird...

Name "UsrMgrTest"
OutFile "UsrMgrTest.exe"
ShowInstDetails show
Page instfiles

Section ""
UserMgr::GetCurrentUserName
Pop $0
DetailPrint ">$0<"
UserMgr::GetUserInfo $0 "HOMEDIR"
Pop $1
DetailPrint ">$1<"
UserMgr::HasPrivilege $0 "SeInteractiveLogonRight"
Pop $2
DetailPrint ">$2<"
SectionEnd

$1 is just an empty string when I run that. And $2 is "ERROR LsaEnumerateAccountRights". $0 does contain my username.

OK, I'm not sure why the HOMEDIR is an empty string, I'll try to look into that.

Can you do the same with the attached test plugin, and tell me what the error message on the HasPrivilege function.
(It will give an error code as well now)

Regards,
Jan Pieter


Originally posted by Ivan Andreevich
I would still make a note of the minimum required version of NSIS, because 99% of the plugins don't require 2.42 yet. Someone might not even realize 2.42 is out or they might be too lazy to upgrade if they feel the changelog doesn't affect them. ;)
Done

I get "ERROR LsaEnumerateAccountRights 1" with the test1 version


Originally posted by jpderuiter
OK, I'm not sure why the HOMEDIR is an empty string, I'll try to look into that.
Hmm, appearantly the HOMEDIR is actually an empty string by default.
At least the one used for the NetUserGetInfo API does.
When you set a value using
UserMgr::SetUserInfo $0 "HOMEDIR" "SomeDir"

you will get this directory back when using GetUserInfo...

Not very usefull though...

Originally posted by TobbeSweden
I get "ERROR LsaEnumerateAccountRights 1" with the test1 version
Hmm, that means "The requested operation was unsuccessful."...

Would it be possible that the user does not have any rights?

Does this happen on each user on your system?

What do UserMgr::GetCurrentUserName and UserMgr::GetCurrentDomain return if there is some problem? I want to do some error checking on my end.


The user I'm testing with is myself. And I'm an administrator... I tried with the admin account and got the same error. It does work with the guest account though. It returns TRUE.


Originally posted by Ivan Andreevich
What do UserMgr::GetCurrentUserName and UserMgr::GetCurrentDomain return if there is some problem? I want to do some error checking on my end.
They both return "ERROR {errorcode}"

Originally posted by TobbeSweden
The user I'm testing with is myself. And I'm an administrator... I tried with the admin account and got the same error. It does work with the guest account though. It returns TRUE.
I tried the same, and I don't get an error for both users.

Tobbe,

have you tried the following code:
http://nsis.sourceforge.net/Enumerate_User_Privileges

Is the same error code returned (the error code in $R8)?


No, $R8 is -1073741772

I have been researching this, and it seems as if I should get an error, and that script gives me that error (in $R9).

I can't compile the source code for the plugin, but could you please make the following changes and post a build?

NTSTATUS nts; // This should be declared up at the top
nts = LsaEnumerateAccountRights(my_policy_handle, user_sid, (LSA_UNICODE_STRING **) &lucPrivilege, &count);
if (nts != STATUS_SUCCESS)
{
DWORD e;
if (lucPrivilege != NULL)LsaFreeMemory(&lucPrivilege);
LsaClose(my_policy_handle);
e = LsaNtStatusToWinError(nts);
if (e == 2)
{
pushstring("ERROR LsaEnumerateAccountRights - User only has inherited rights");
}
else
{
pushstring("ERROR LsaEnumerateAccountRights");
}
return;
}

Hello Tobbe

I uploaded a new version which return the errorcode for LsaEnumerateAccountRights (either the System errorcode if available, else the NTSTATUS errorcode).

I used the following code:


if (ntStatus = LsaEnumerateAccountRights(my_policy_handle, user_sid, (LSA_UNICODE_STRING **) &lucPrivilege, &count) != STATUS_SUCCESS)
{
if (lucPrivilege != NULL)LsaFreeMemory(&lucPrivilege);
LsaClose(my_policy_handle);
dwError = LsaNtStatusToWinError(ntStatus);
if(dwError == ERROR_FILE_NOT_FOUND)
{// No privileges found for the user
sprintf(tempbuf,"FALSE");
}
else if(dwError == ERROR_MR_MID_NOT_FOUND)
{// System errorcode not found for ntStatus
sprintf(tempbuf,"ERROR LsaEnumerateAccountRights n%d", ntStatus);
}
else
{
sprintf(tempbuf,"ERROR LsaEnumerateAccountRights w%d", dwError);
}
pushstring(tempbuf);
return;
}


(Attached newest version to this post)

Regards,
jpderuiter

For some reason your code returns "ERROR LsaEnumerateAccountRights n1"

http://nsis.sourceforge.net/Enumerate_User_Privileges returns FILE_NOT_FOUND

I believe the correct return value in my case is FILE_NOT_FOUND


I have a feature request. How about a function that checks whether the specified Username (password too, if needed) has access rights to go to a specified path. Is that feasible, or is this outside the scope of this plug-in?


Cancel that. My studio has been closed down and we've all been fired today.

But thanks so much for the hard work you put in with this plug-in!


@Tobbe:
I'm sorry, but I'm not able to solve the HasPrivilege problem.
The function LsaEnumerateAccountRights returns 1 on every error, and I can't find a solution for it.
So I'm afraid you'll have to use the Macro mentioned before as a workaround.

@Ivan:
I'm really sorry to hear that.
I hope you will find yourself a new job soon.
About your feature request: I think it's a usefull feature so I'm thinking about adding it anyway as soon as I have the time for it.

Regards,
Jan Pieter


I compiled and ran this code: http://win32.mvps.org/lsa/lsa_lear.cpp

It uses LsaEnumerateAccountRights and I got the "FILE_NOT_FOUND" error. Maybe you can work off of that?