473,662 Members | 2,536 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cannot obtain account SID using C#/WMI

Hello,

The below C# code works fine in obtaining the windows user's account
SID when the user is local to the machine. It throws a "Not Found"
exception when trying top obtain the SID for a user who is on a
domain, but logged in locally. Specifically, for a corporate domain -
the user logs into the local desktop and has a local profile - not a
roaming profile.

The below code is implemented in an NT service for the purpose of
allowing the service to access the user's registry hive under "current
user". Since the service runs under the SYSTEM account the current
user mapping is for the default SYSTEM account. We impersonate the
logged in windows user and then simulate the current user mapping by
using the SID and accessing the HKEY_USER hive (basically the same as
accessing the current user hive). This works fine for windows users
who are named: machineName/userName but not for CORPORATE/userName.

Is this SID available through WMI? Is there a different string I need
to query for it? Could there be security settings on this corporate
account? I am running under the SYTSTEM account so I should have full
privileges?
Here is the code:

string slash = @"\";
int pos = winUserName.Ind exOfAny(slash.T oCharArray());
string machineName = winUserName.Sub string(0, pos);
string userName = winUserName.Sub string(pos + 1, winUserName.Len gth -
pos - 1);

// Use WMI to get the SID of the user
string p = String.Format(" ROOT\\CIMV2:Win 32_UserAccount. Domain=
\"{0}\",Name=\" {1}\"", machineName, userName);
ManagementPath path = new ManagementPath( p);
System.Manageme nt.ManagementOb ject account = new
ManagementObjec t(path);
sid = account["SID"] as string;
account.Dispose ();
Any ideas or suggestion will be greatly appreciated.

Thanks,
Victor Grippi

Apr 12 '07 #1
1 4440
"VictorG" <gr************ **@yahoo.comwro te in message
news:11******** **************@ o5g2000hsb.goog legroups.com...
Hello,

The below C# code works fine in obtaining the windows user's account
SID when the user is local to the machine. It throws a "Not Found"
exception when trying top obtain the SID for a user who is on a
domain, but logged in locally. Specifically, for a corporate domain -
the user logs into the local desktop and has a local profile - not a
roaming profile.

The below code is implemented in an NT service for the purpose of
allowing the service to access the user's registry hive under "current
user". Since the service runs under the SYSTEM account the current
user mapping is for the default SYSTEM account. We impersonate the
logged in windows user and then simulate the current user mapping by
using the SID and accessing the HKEY_USER hive (basically the same as
accessing the current user hive). This works fine for windows users
who are named: machineName/userName but not for CORPORATE/userName.

Is this SID available through WMI? Is there a different string I need
to query for it? Could there be security settings on this corporate
account? I am running under the SYTSTEM account so I should have full
privileges?
Here is the code:

string slash = @"\";
int pos = winUserName.Ind exOfAny(slash.T oCharArray());
string machineName = winUserName.Sub string(0, pos);
string userName = winUserName.Sub string(pos + 1, winUserName.Len gth -
pos - 1);

// Use WMI to get the SID of the user
string p = String.Format(" ROOT\\CIMV2:Win 32_UserAccount. Domain=
\"{0}\",Name=\" {1}\"", machineName, userName);
ManagementPath path = new ManagementPath( p);
System.Manageme nt.ManagementOb ject account = new
ManagementObjec t(path);
sid = account["SID"] as string;
account.Dispose ();
Any ideas or suggestion will be greatly appreciated.

Thanks,
Victor Grippi

The domain account SID's aren't stored on the local machine, they are stored on the DC, so
will have to connect to DC of the users logon domain to obtain his SID.

Willy.

Apr 12 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
14198
by: Yiu | last post by:
upgent help i want to start IE explorer using C# i try many code such as below: ProcessStartInfo startInfo = new ProcessStartInfo("IEXPLORE.EXE"); Process.Start(startInfo); or Process process = new Process(); process.StartInfo.FileName = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE";
4
1444
by: Tony Cheng | last post by:
I want to know which account will be used when File.Exists are called in ASP.NET ? Thx
5
3882
by: Dominiek | last post by:
Hi, I have a strange problem. during the developement of my program, while progressively writing more and more code, the callstack of my program gets deeper and deeper (7 levels). Then, all of a sudden, when calling a Sub with 2 parameters, a Hashtable(19 items) and a ArrayList(9 items), the value of these variables is gone, the debugger reports the value as {length=error: cannot obtain value}.
0
1675
by: cgraham | last post by:
Hi, I have just upgraded our terminal server to Win 2003 Enterprise Ed on a new Dell server from an older model running Win 2003 Standard Ed. The DB2 client we are using is 7.1, Fixpak 14 and all connections are testing successfully to our database. Both the local administrator and domain administrator have NO issues running any application connecting to the database, but no local user (whether they are a power user or not) can execute...
6
7461
by: Programador | last post by:
I'm getting this error when running this program: Cannot calculate rate using the arguments provided Module Module1 Sub Main() Rate(360, -694.44444444444446, 244274.69178082192) End Sub
0
1105
by: Anil | last post by:
Folks, Here is the code I use in c# to enable an account. Everywhere I looked it said this is the code, but it always gives me "Unspecified error" on execution.Error happen when I am trying to assign updated value back to the userflags property. static void EnableUser(string strUser, string strDomain) { int ADS_UF_ACCOUNTDISABLE = 0x0002;
2
5338
by: Keith | last post by:
I am trying to connect to a DB2 database using "iSeries Access ODBC Driver" from Crystal Reports. I am able to report on tables and queries but not stored procedures. I get the following error after I select the procedure and enter the parameter. Query Engine Error: '42000: Statement violates access rule: Connection is set to read only.' The ODBC driver is setup with a connection type Read/Write (all SQL statements allowed) and Naming...
0
991
by: =?Utf-8?B?LnBhdWwu?= | last post by:
does anyone know how i can set up an outlook express 6 account using vb.net?
2
1891
by: newphpcoder | last post by:
I change my database from mysql to mssql, so I need to change the connection code in my php. I’m not familiar about the codes using mssql. Now cannot connect to my database. I used the following: php 5.1.4 IIS 6.0 Microsoft SQL Server 2005 Express Edition SQL Server Management Studio Express Here is my code: <?php //session_start();
0
8857
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8764
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7367
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5654
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1752
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.