Solved

Need to parse a string domain name and domain user.

Posted on 2008-06-12
10
406 Views
Last Modified: 2013-12-17
Need to parse this string into two strings

System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString()      

="CWB\\mxcupryk"      

sDomain = ?
sUser = ?
0
Comment
Question by:mathieu_cupryk
  • 4
  • 3
  • 3
10 Comments
 
LVL 9

Expert Comment

by:Rob Siklos
ID: 21770090

string fullname = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();

string[] parts = fullname.Split(new string[] {@"\\"}, StringSplitOptions.None);
 

string sDomain = parts[0];

string sUser parts[1];

Open in new window

0
 
LVL 21

Expert Comment

by:naspinski
ID: 21770143
this will work (notice that I have to use double \\ for each one as '\' is the escape character in c#.

 I just thought of a cleaner way too, will post it in a second
string parseThis = "=\"CWB\\\\mxcupryk\"";

string[] split = parseThis.Substring(3, parseThis.Length - 3).Substring(0, parseThis.Length - 4).Split(new string[] { "\\\\" }, StringSplitOptions.RemoveEmptyEntries);

string sDomain = split[0];

string sUser = split[1];

Open in new window

0
 
LVL 21

Expert Comment

by:naspinski
ID: 21770166
better approach
string[] split = parseThis.Split(new string[] { "\\\\", "\"","=" }, StringSplitOptions.RemoveEmptyEntries);

string sDomain = split[0];

string sUser = split[1];

Open in new window

0
 

Author Comment

by:mathieu_cupryk
ID: 21770179
sDomain  = CWB\mxcupryk?
sUser  bombs {"Index was outside the bounds of the array."}
0
 

Author Comment

by:mathieu_cupryk
ID: 21770222
nasp

sDomain = "CWB\\mxcupryk"
sUser  bombs {"Index was outside the bounds of the array."}

should be CWB

and sUser = mxcupryk
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 9

Expert Comment

by:Rob Siklos
ID: 21770237
string fullname = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
string[] parts = fullname.Split('\\');
 
string sDomain = parts[0];
string sUser parts[1];
0
 
LVL 21

Expert Comment

by:naspinski
ID: 21770260
If I run the following, I get this exact output:

parsing: ="CWB\\mxcupryk"
sDomain=CWB
sUser=mxcupryk
string parseThis = "=\"CWB\\\\mxcupryk\"";

string[] split = parseThis.Split(new string[] { "\\\\", "\"","=" }, StringSplitOptions.RemoveEmptyEntries);

string sDomain = split[0];

string sUser = split[1];

//added for testing

Response.Write("parsing: " + parseThis + "<br />sDomain=" + sDomain + "<br />sUser=" + sUser);

Open in new window

0
 
LVL 21

Expert Comment

by:naspinski
ID: 21770290
or possibly change to this as the double / wont make a difference
string[] split = parseThis.Split(new string[] { "\\", "\"","=" }, StringSplitOptions.RemoveEmptyEntries);

string sDomain = split[0];

string sUser = split[1];

Open in new window

0
 
LVL 9

Accepted Solution

by:
Rob Siklos earned 500 total points
ID: 21770345
it looks like the value of the full name is CWB\mxcupryk (no =, no quotes).

In such a case, use this:
string fullname = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();

string[] parts = fullname.Split('\\');

 

string sDomain = parts[0];

string sUser parts[1];

Open in new window

0
 

Author Comment

by:mathieu_cupryk
ID: 21770401
great job rob

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

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

9 Experts available now in Live!

Get 1:1 Help Now