Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Port this VB-code to C#: set usr = getobject("winnt://" + domainName + "/" + samAccountName); usr.dialinprivilege = true;

Posted on 2004-08-11
11
Medium Priority
?
1,680 Views
Last Modified: 2008-02-26
Short question:
I need to port this VB-code to C#:

set usr = getobject("winnt://" + domainName + "/" + samAccountName);
usr.dialinprivilege = true;

The reason for needing to to this is found here:
http://support.microsoft.com/?kbid=252398
0
Comment
Question by:pcpaasche
  • 4
  • 2
11 Comments
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 1000 total points
ID: 11771399
try

Object obj = System.Runtime.InteropServices.Marshal.GetActiveObject("winnt://domainname/username")
0
 
LVL 3

Expert Comment

by:sohilm
ID: 11777405
are you trying this on an nt4 domain or windows 2000 domain?

0
 

Author Comment

by:pcpaasche
ID: 11778378
I'm trying to this on a Windows 2003 domain.

I am also trying to run the code below which is a VB-script (.vbs-file). The tree first lines works fine, while line 4 makes the script throw an errormessage with the text: "This function is not supported on this system". In other words, I'm able to set the password but the attribute 'dialinprivilege'  does not seem to be available.

dim objUser
Set objUser = GetObject ("WinNT://VGS/perpaasc2")
objUser.SetPassword "perper"
objUser.dialinprivilege = TRUE
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 3

Assisted Solution

by:sohilm
sohilm earned 1000 total points
ID: 11778481
ok. Then try this. Change DomainName to the domain you want and username to the username you want. Make sure your domain name is your active directory domain name. EX: microsoft.com
Have fun.

                  string DomainName = "microsoft.com"; //Change this to correct domain name
        string UserName = "bgates"; //change this to correct user.
        string[] props = {};
        System.DirectoryServices.DirectoryEntry DE = new System.DirectoryServices.DirectoryEntry("LDAP://" + DomainName);
        System.DirectoryServices.DirectorySearcher DS = new System.DirectoryServices.DirectorySearcher(DE,"(&(objectClass=user)(sAMAccountName=" + UserName + "))",props,System.DirectoryServices.SearchScope.Subtree);
        foreach(System.DirectoryServices.SearchResult sr in DS.FindAll())
        {
            System.DirectoryServices.DirectoryEntry user = sr.GetDirectoryEntry();
            user.Properties["msNPAllowDialin"].Value = true;
            user.CommitChanges();
        }
0
 

Author Comment

by:pcpaasche
ID: 11780874
Setting "msNPAllowDialin" through LDAP causes the need to also set the "dialinprivilege". Take a look at the text in this link to see why:
http://support.microsoft.com/?kbid=252398

"dialinprivilege" is only available through WinNt and not through LDAP. I haven't seen any way to write this code using c#, but setting "dialinprivilege" through a VBS-script will work fine for me. Any ideas?
0
 

Author Comment

by:pcpaasche
ID: 12042148
After having done a lot of research on this case, including thourogh investigations by Microsoft support, I have concluded that the problem is not possible to solve. However using a work around that sets the "Allow dialin" property on all the users through a GUI tool solves the problem for us for now.

Thanks for your efforts anyway.
0
 

Author Comment

by:pcpaasche
ID: 12245896
I am afraid that noone was able to answer my question correctly. Maybe not so strange all the way that there is probably no solution to the question. For the record it would be wrong to accept any of the answers, but the contributors should be awarded for their efforts. I suggest giving sohilm 400 points and mnasman 100 point. How do I do that (or will TheLearnedOne do it for me)?
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question