Solved

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

Posted on 2004-08-11
11
1,655 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 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 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