Get current logged on user - RMB Scripting
You appear not to have an account with us, Click HERE to register an account...
RMB Scripting
Navigation
  Home
  Contact
  FAQ
  Forum
  Topsites
  Members
  Affiliates
  Arcade <-- New!
  IoxHost
Downloads
  Templates
  Scripts
  Fonts
  Image Sets
  Software
  Other
 
Tutorials
  .htaccess
  Photoshop
  C/C++
  CSS
  Macromedia Flash
  MySQL
  PHP
  PHP - User System
  HTML
  Javascript
  Macintosh
  Macromedia Fireworks
  Visual Basic
  Visual C#
  Windows
  Python
  Other
 
Latest Tutorials
Get the date of every ...
If...Else on one line ...
Drop Calendar Function
Single VS Double
Understanding Variables
Latest Comments
Simple Comment System
Simple Comment System
Simple Comment System
Simple Comment System
Private Message System
Stats
Total Members: 585 [231]
Total Tutorials: 276
Newsest User: zaithstery
Todays Unique Hits: 71
Users Online: 0
 
9 Guests
Poll
Should we change our name?
Hmmmm, Yes!!
Maybe
Depends on what to
NO!
Main Content
Tutorial: Get current logged on user By ShadowMage
This very simple tutorial will show you how to get the currently logged on user. This should be cross-platform meaning it should work on *nix systems, and on windows systems.

So, here we go!

First off create a new script and at the top add the following line:
   
CODE:
import os


This will import the os library, which gives us access to the root operating system commands.
Note: I don't mean manage applications, but you might be able to. I haven't really messed around with it that much.

Hit enter then place the following import line.
   
CODE:
import sys


This will import the system library which will help us with getting the platform.

With our two libraries loaded you can now start the code!

The following will get the logged on user;
   
CODE:
if sys.platform == 'win32': #Windows platform
userName = os.getenv('USERNAME')
else: #other platforms such as Linux or Mac
userName = os.getenv('USER')


The currently logged on user will be assigned to the variable userName. Now all you have to do is print it.
   
CODE:
print userName


And there you have it! A simple script to get the currently logged on username.

Note: The python files must end with a blank line or you will get an error.
Difficulty: Easy
Views: 600
Rating:
Comments
There are currently no comments for this tutorial.
Notice:
Remember to post long codes on our pastbin! - (http://rmb.pastebin.com/)
Add Comment
You must be logged in to post a comment.
Good Morning Guest
Username: 
Password: 
Remember Username
Links
RMB Arcade
$2.50 Resellers
Free Domains
Free Games
Affiliates