Solved

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

Posted on 2004-08-11
11
1,649 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:
mnasman earned 250 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Assisted Solution

by:sohilm
sohilm earned 250 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Email Body 4 47
How do I get the unique ID after insert? 87 92
Pass through dll 2 38
Check my code out(2) 1 35
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now