473,462 Members | 1,098 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Information about the current logged user !

Hey guys,

small question. Can I find out if the current logged on use is a local
user or a domain user ?
And please don't use any solution that uses String parsing...

What I need is to get the display name of the current user and the
only way I'm able to do this is using a DLL wrapper :

[DllImport("secur32.dll", CharSet=CharSet.Auto)]
public static extern int GetUserNameEx (int nameFormat,
StringBuilder userName, ref int userNameSize);

But is there no .Net code available ??

Greets
Glenn

Sep 5 '07 #1
3 1913
"Depechie" <gl***************@gmail.comwrote in message
news:11**********************@g4g2000hsf.googlegro ups.com...
Hey guys,

small question. Can I find out if the current logged on use is a local
user or a domain user ?
And please don't use any solution that uses String parsing...

What I need is to get the display name of the current user and the
only way I'm able to do this is using a DLL wrapper :

[DllImport("secur32.dll", CharSet=CharSet.Auto)]
public static extern int GetUserNameEx (int nameFormat,
StringBuilder userName, ref int userNameSize);

But is there no .Net code available ??

Greets
Glenn

Get the MACHINE (System.Environment.MachineName) name and DOMAINNAME
(System.Environment.UserDomainName) from the environment, if both are equal,
you are running in a local logon session, else you are running in a domain
session with DOMAINNAME as the logon domain.

Willy.

Sep 5 '07 #2
On Sep 5, 6:54 pm, "Willy Denoyette [MVP]"
<willy.denoye...@telenet.bewrote:
"Depechie" <glenn.versweyv...@gmail.comwrote in message

news:11**********************@g4g2000hsf.googlegro ups.com...
Hey guys,
small question. Can I find out if the current logged on use is a local
user or a domain user ?
And please don't use any solution that uses String parsing...
What I need is to get the display name of the current user and the
only way I'm able to do this is using a DLL wrapper :
[DllImport("secur32.dll", CharSet=CharSet.Auto)]
public static extern int GetUserNameEx (int nameFormat,
StringBuilder userName, ref int userNameSize);
But is there no .Net code available ??
Greets
Glenn

Get the MACHINE (System.Environment.MachineName) name and DOMAINNAME
(System.Environment.UserDomainName) from the environment, if both are equal,
you are running in a local logon session, else you are running in a domain
session with DOMAINNAME as the logon domain.

Willy.
Hey Brian and Willy,

So there is no function that actually tells me if it is a domain user
or not ?
Because I also saw the difference in DomainName and MachineName, but
that is also String checking.

But ok, if that is the only way to go, then I was on the correct
track !
Weird that .Net doesn't provide this information !! Because Windows
needs it when you start up your pc, so somehow it has to know where
the user is !
Strange....

But thanks for the nice answers

Sep 5 '07 #3
>
So there is no function that actually tells me if it is a domain user
or not ?
Because I also saw the difference in DomainName and MachineName, but
that is also String checking.
Gosh, I thought Willy gave a very elegant solution.

>
But ok, if that is the only way to go, then I was on the correct
track !
Weird that .Net doesn't provide this information !! Because Windows
needs it when you start up your pc, so somehow it has to know where
the user is !
I suspect Windows does something very similar to what Willy describes.

Brian

Sep 5 '07 #4

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

Similar topics

1
by: Rudolf Bargholz | last post by:
Hi, DB2 v7.1 FP3 on Windows 2003 I am trying to acheive the following: create trigger ADD_LHL after insert on MAINTABLE for each row mode db2sql insert into LOGTABLE
1
by: amwi | last post by:
I have tried to find a solution on this problem "everywhere" without any luck. I am writing a service to track the time that the current logged on interactive user is using the computer. Perhaps...
3
by: Bart | last post by:
I want to get the current username (or other information) about the user who is currently logged on in the windows 2000 domain. I thought about user.identity.name, but it returns an empty string....
6
by: John Dalberg | last post by:
I want to automate the process of logging into an intranet. I want to pull out the username of the Windows user logged into the machine running the browser and use the username in my app. How can I...
10
by: madereal | last post by:
Situation: I have a database that has users with different levels of access to the information they are allowed to view. I have addressed this issue by creating a login form that opens on startup....
17
by: Gerrit | last post by:
Hallo, In my application, the user must logon with a username and a password. In all the tables in my database, there is a field user. By saving new or changed records, the username is writed to...
3
by: daokfella | last post by:
I want to be able to store profile information for a user when they sign up for an account...but BEFORE they can log in. Can this be done using any of the built-in profile methods? Here's my...
5
by: Charles May | last post by:
Anyone have a simple concept for the best way to store timeclock information in a database. I currently have my table set up like this with a typical daily entry. tcID empID Type ...
0
by: thephatp | last post by:
Is there any possible way to get the currently logged in (active) user from within a service? I need the service to start at runtime. I need to capture log on / log off / switch user events. I...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.