473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.IndexOfAny(slash.ToCharArray());
string machineName = winUserName.Substring(0, pos);
string userName = winUserName.Substring(pos + 1, winUserName.Length -
pos - 1);

// Use WMI to get the SID of the user
string p = String.Format("ROOT\\CIMV2:Win32_UserAccount.Domai n=
\"{0}\",Name=\"{1}\"", machineName, userName);
ManagementPath path = new ManagementPath(p);
System.Management.ManagementObject account = new
ManagementObject(path);
sid = account["SID"] as string;
account.Dispose();
Any ideas or suggestion will be greatly appreciated.

Thanks,
Victor Grippi

Apr 12 '07 #1
1 4424
"VictorG" <gr**************@yahoo.comwrote in message
news:11**********************@o5g2000hsb.googlegro ups.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.IndexOfAny(slash.ToCharArray());
string machineName = winUserName.Substring(0, pos);
string userName = winUserName.Substring(pos + 1, winUserName.Length -
pos - 1);

// Use WMI to get the SID of the user
string p = String.Format("ROOT\\CIMV2:Win32_UserAccount.Domai n=
\"{0}\",Name=\"{1}\"", machineName, userName);
ManagementPath path = new ManagementPath(p);
System.Management.ManagementObject account = new
ManagementObject(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
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...
4
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
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...
0
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...
6
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
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...
2
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...
0
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
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:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.