Old 22nd January 2009, 07:17   #1
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
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
jpderuiter is offline   Reply With Quote
Old 22nd January 2009, 15:45   #2
coppolo
Junior Member
 
Join Date: Dec 2004
Posts: 2
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
coppolo is offline   Reply With Quote
Old 22nd January 2009, 16:27   #3
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
Hello coppolo,

I tried the following:

code:

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
jpderuiter is offline   Reply With Quote
Old 22nd January 2009, 17:40   #4
Ivan Andreevich
Junior Member
 
Join Date: Nov 2003
Location: Vancouver, BC
Posts: 48
Re: UserMgr Plugin

Quote:
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.

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

Ivan Andreevich is offline   Reply With Quote
Old 22nd January 2009, 18:37   #5
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
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
jpderuiter is offline   Reply With Quote
Old 22nd January 2009, 19:05   #6
Ivan Andreevich
Junior Member
 
Join Date: Nov 2003
Location: Vancouver, BC
Posts: 48
Quote:
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.
Ivan Andreevich is offline   Reply With Quote
Old 22nd January 2009, 19:27   #7
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
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
jpderuiter is offline   Reply With Quote
Old 23rd January 2009, 13:06   #8
TobbeSweden
Senior Member
 
Join Date: Oct 2006
Posts: 106
This installer crashes every time I try to run it:
code:
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?
TobbeSweden is offline   Reply With Quote
Old 23rd January 2009, 16:33   #9
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
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
jpderuiter is offline   Reply With Quote
Old 23rd January 2009, 16:50   #10
TobbeSweden
Senior Member
 
Join Date: Oct 2006
Posts: 106
It still crashes for me. It crashes before it prints anything to the log window.
TobbeSweden is offline   Reply With Quote
Old 23rd January 2009, 16:54   #11
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
Hmm, strange.

I assume you are using NSIS v2.42?
Are other UserMgr funtions crashing the installer as well?
jpderuiter is offline   Reply With Quote
Old 23rd January 2009, 17:03   #12
TobbeSweden
Senior Member
 
Join Date: Oct 2006
Posts: 106
Hmm, I'm using 2.37. Let me upgrade and I'll report back
TobbeSweden is offline   Reply With Quote
Old 23rd January 2009, 17:31   #13
TobbeSweden
Senior Member
 
Join Date: Oct 2006
Posts: 106
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.
TobbeSweden is offline   Reply With Quote
Old 23rd January 2009, 17:35   #14
Ivan Andreevich
Junior Member
 
Join Date: Nov 2003
Location: Vancouver, BC
Posts: 48
Quote:
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.
Ivan Andreevich is offline   Reply With Quote
Old 23rd January 2009, 17:41   #15
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
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
jpderuiter is offline   Reply With Quote
Old 23rd January 2009, 19:22   #16
Ivan Andreevich
Junior Member
 
Join Date: Nov 2003
Location: Vancouver, BC
Posts: 48
Quote:
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

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.
Ivan Andreevich is offline   Reply With Quote
Old 23rd January 2009, 19:52   #17
Ivan Andreevich
Junior Member
 
Join Date: Nov 2003
Location: Vancouver, BC
Posts: 48
Awesome, it works perfectly with NSIS 2.42. It didn't break any old plugins either
Ivan Andreevich is offline   Reply With Quote
Old 23rd January 2009, 19:55   #18
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
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.
jpderuiter is offline   Reply With Quote
Old 23rd January 2009, 20:04   #19
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
@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...
jpderuiter is offline   Reply With Quote
Old 23rd January 2009, 20:08   #20
TobbeSweden
Senior Member
 
Join Date: Oct 2006
Posts: 106
Firefox seems to be caching the download or something... Could you please add a version number to the downloadable file? Thanks
TobbeSweden is offline   Reply With Quote
Old 23rd January 2009, 20:18   #21
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
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.
Attached Files
File Type: zip usermgr012309.zip (45.0 KB, 376 views)
jpderuiter is offline   Reply With Quote
Old 23rd January 2009, 20:22   #22
TobbeSweden
Senior Member
 
Join Date: Oct 2006
Posts: 106
Perfect! Thank you
TobbeSweden is offline   Reply With Quote
Old 23rd January 2009, 20:26   #23
Ivan Andreevich
Junior Member
 
Join Date: Nov 2003
Location: Vancouver, BC
Posts: 48
Quote:
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.
Ivan Andreevich is offline   Reply With Quote
Old 23rd January 2009, 20:27   #24
TobbeSweden
Senior Member
 
Join Date: Oct 2006
Posts: 106
Now I can run the plugin but there is one thing I find weird...
code:
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.
TobbeSweden is offline   Reply With Quote
Old 23rd January 2009, 21:17   #25
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
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
Attached Files
File Type: zip usermgr012309_test1.zip (24.9 KB, 277 views)
jpderuiter is offline   Reply With Quote
Old 23rd January 2009, 21:19   #26
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
Quote:
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
jpderuiter is offline   Reply With Quote
Old 23rd January 2009, 22:06   #27
TobbeSweden
Senior Member
 
Join Date: Oct 2006
Posts: 106
I get "ERROR LsaEnumerateAccountRights 1" with the test1 version
TobbeSweden is offline   Reply With Quote
Old 23rd January 2009, 22:06   #28
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
Quote:
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
code:
UserMgr::SetUserInfo $0 "HOMEDIR" "SomeDir"

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

Not very usefull though...
jpderuiter is offline   Reply With Quote
Old 23rd January 2009, 22:20   #29
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
Quote:
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?
jpderuiter is offline   Reply With Quote
Old 23rd January 2009, 22:29   #30
Ivan Andreevich
Junior Member
 
Join Date: Nov 2003
Location: Vancouver, BC
Posts: 48
What do UserMgr::GetCurrentUserName and UserMgr::GetCurrentDomain return if there is some problem? I want to do some error checking on my end.
Ivan Andreevich is offline   Reply With Quote
Old 23rd January 2009, 22:42   #31
TobbeSweden
Senior Member
 
Join Date: Oct 2006
Posts: 106
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.
TobbeSweden is offline   Reply With Quote
Old 23rd January 2009, 23:03   #32
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
Quote:
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}"

Quote:
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.
jpderuiter is offline   Reply With Quote
Old 24th January 2009, 10:11   #33
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
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)?
jpderuiter is offline   Reply With Quote
Old 24th January 2009, 11:09   #34
TobbeSweden
Senior Member
 
Join Date: Oct 2006
Posts: 106
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?

code:
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;
}

TobbeSweden is offline   Reply With Quote
Old 25th January 2009, 21:45   #35
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
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:
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
Attached Files
File Type: zip usermgr012509.zip (46.9 KB, 298 views)
jpderuiter is offline   Reply With Quote
Old 25th January 2009, 22:03   #36
TobbeSweden
Senior Member
 
Join Date: Oct 2006
Posts: 106
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
TobbeSweden is offline   Reply With Quote
Old 26th January 2009, 18:15   #37
Ivan Andreevich
Junior Member
 
Join Date: Nov 2003
Location: Vancouver, BC
Posts: 48
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?
Ivan Andreevich is offline   Reply With Quote
Old 27th January 2009, 20:55   #38
Ivan Andreevich
Junior Member
 
Join Date: Nov 2003
Location: Vancouver, BC
Posts: 48
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!
Ivan Andreevich is offline   Reply With Quote
Old 28th January 2009, 16:38   #39
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
@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
jpderuiter is offline   Reply With Quote
Old 28th January 2009, 16:51   #40
TobbeSweden
Senior Member
 
Join Date: Oct 2006
Posts: 106
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?
TobbeSweden 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