Solved

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

Posted on 2004-08-11
11
1,660 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
11 Comments
 
LVL 22

Accepted Solution

by:
Mohammed Nasman 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# XML Get Values 4 54
Set custom font WPF 2 26
Pdf not loading 2 41
SQL State HYT00. Timeout expired proplem 8 44
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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

759 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