473,841 Members | 1,675 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem in getting windows username

14 New Member
Hi,

To get windows username Im using the following code.
Expand|Select|Wrap|Line Numbers
  1. public class GetWindowUsername {
  2. public String getUser() {
  3. String userName = System.getProperty("user.name");
  4. System.out.println("Window's Username: "+userName);
  5. return userName;
  6. }
  7. }
  8.  
  9. public class TestUserName {
  10. public static void main(String args[]) {
  11. GetWindowUsername g = new GetWindowUsername();
  12. String s = g.getUser();
  13. System.out.println("UserName : "+s);
  14. }
  15. }
  16.  
If I execute the above java class I get the windows username correct.

But when I use it in jsp like-
Expand|Select|Wrap|Line Numbers
  1. <% 
  2. String s = System.getProperty("user.name");
  3. out.println("Windows Username : "+s);
  4. %>
  5.  
I get the ouput as-
" Windows Username : SYSTEM "

I tried to call the "getUser()" in jsp using an object of "GetWindowUsern ame"
but even after that I got same output.

Im running the above jsp using Apache Tomcat 5.0 on my server machine.

When I run the same code on my local system using eclipse & Apache Tomcat v5.5, I get the output correct.

Can anyone solve my problem.

Thanks in advance
Tiijnar
Dec 19 '08 #1
8 12565
JosAH
11,448 Recognized Expert MVP
Does System.getenv(" USERNAME") help?

kind regards,

Jos

ps. I deleted your other identical thread.
Dec 19 '08 #2
tiijnar
14 New Member
Hi JosAH,

Thank you for the solution but I still face the problem.

I have used System.getenv(" USERNAME") on my server which uses Tomcat 5.0 to run jsp, but I got the username as NULL.

Does my problem depends on the usage of Tomcat 5.0, because when I use same code in a jsp which is run using Tomcat 5.5 I get correct result.

Can I have another solution for my problem..

Thanks in advance
Tiijnar
Dec 22 '08 #3
JosAH
11,448 Recognized Expert MVP
@tiijnar
I'd blame version 5.0 for that; I just tested it on version 6.0.18 and there were no problems there either, i.e. I just got a valid user name back.

kind regards,

Jos
Dec 22 '08 #4
tiijnar
14 New Member
Hi JosAH,

I have installed Tomcat 5.5 on my server and run the same jsp. Even then Im getting same old output. i.e
If I use System.getPrope rty("user.name" ) ---> SYSTEM
If I use System.getenv(" username") ---> null

My problem is not solved yet.

Can you provide me a new solution.

Regards,
Tiijnar
Dec 23 '08 #5
JosAH
11,448 Recognized Expert MVP
It's USERNAME in capital letters although I don't think that matters much on a Windows box.

kind regards,

Jos
Dec 23 '08 #6
tiijnar
14 New Member
Hi,

In my java application I have following code to get windows username-

<%
String s1 = System.getPrope rty("user.name" );
out.println("Th e Username : "s1" ");
String s2 = System.getenv(" USERNAME");
out.println("Th e Username : "+s2);
%>

If I log in to my PC and execute it I get correct output for both the statements, But when I execute it on server machine(when I logged in) I get the output as-

The Username : SYSTEM The Username : null

I use Apache Tomcat 5.5 to run the jsp on both (PC & server) machines. One small difference is I use eclipse on my PC and I don't use eclipse on server (I think it doesn't matter).

But when I use the same code inside a java class I get correct output on both (PC & server) machines.

Can any one solve my problem.

Thanks in advance,
Tiijnar
Dec 24 '08 #7
Dököll
2,364 Recognized Expert Top Contributor
Greetings tiijnar!

Just guessing, but if you are intending to get credentials of a user on a Windows domain, you'll need to use LDAP. If this is the case, please continue to search here, if nothing, try Sun Microsystems for added input.

I would tell you but it is so involved. Rest assured however, Sun has a generic code you can use;-)

Hope this is what you needed...

Good luck!

Dököll
Dec 24 '08 #8
JosAH
11,448 Recognized Expert MVP
@OP: I've merged your identical threads; there was (and is) no need to start two separate threads for one single question. If needed you can bump your thread (by posting a small reply to it yourself).

kind regards,

Jos
Dec 24 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

9
2651
by: Bartosz Wegrzyn | last post by:
I need help with sessions. I createt set of web site for nav with authorization. first I go into main.php which looks like this: <?php //common functions include_once '../login/common.php'; global $LOGINDIR;
2
1791
by: Graeme Coutts | last post by:
Developed a web application which adopts a custom security model which displays a login page and requests a username/password combination. The username works in a mixed-mode of usernames matched with the windows login name and some extra accounts (similar to SQL mixed-mode security). Web application is executed both in the corporate intranet and externally on the web. Getting user complaints about having to login to the web application when...
2
2112
by: Linda | last post by:
I'm getting the following error when trying to debug a asp.net program. I have domain user rights and belong to the local "Debugger Users" and "VS Developers" groups. I do NOT have administrator privileges on this machine. It will work if I do have administrator rights, But this is something we don't want to have to do. Any Ideas? "Error while trying to run project:
4
2210
by: Grind Boy | last post by:
Hi, I'm writing this off the top of my head as I don't have the exact information to hand. We are attempting to set up a secure internet site using ASP.NET on IIS5. We are having some authentication problems early on in the project. The plan is to have 1 ASP.NET (IIS) forms application serving user requests and another ASP.NET (IIS) webservice interfacing to the database.
13
39311
by: Steve Enzer | last post by:
How can I get the login name of the user currently logged into Windows as a string? Thanks, Steve Enzer
1
7472
by: ranju | last post by:
I am trying to spawn a process (say an exe file) with different user crendentials than that of the current user. 1) Called LogonUserEx() to logon the user and recieve a handle to the token that represents the logged-on user. 2) Called ImpersonateLoggedOnUSer() to let the calling thread impersonate the security context of logged on user. 3) Used CreateEnvironmentBlock() to get lpEnv
8
16695
by: Bruno Barros | last post by:
Hey there. I'm currently working on an intranet, and would like to know how I can get the windows usernames of the visitors. You can get their IP with $_SERVER; But what about their Windows Username? Is there any way of doing so? Through the Intranet?
6
2122
NawazAhmed
by: NawazAhmed | last post by:
Hi, I was trying to get local system's username in my code behind. I tried every almost possible way. Here is the scenario: My project is web based and I don't have a login screen....I need to get the local system's username when some user opens the website.... I tried. environment.Username environ("username") System.Windows.Forms.SystemInformation.UserName system.Security.Principal.WindowsIdentity.GetCurrent.Name
7
10212
by: cmrchs | last post by:
Hi, In Windows Vista: where does asp.net write its cookies? I use HttpCookie objCookie = new HttpCookie("nameCookie"); in Win2000 (and later) they used to be in C:\Documents and Settings\Administrator\Cookies but not anymore
0
9865
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10609
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...
1
10667
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10303
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9446
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...
1
7848
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7025
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();...
1
4498
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
4082
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.