Total Members: 562 [216] Total Tutorials: 269 Newsest User:Stf Todays Unique Hits: 50
Users Online: 0
7 Guests
Poll
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:
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.
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;
The currently logged on user will be assigned to the variable userName. Now all you have to do is print it.
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: 356
Rating:
Comments
There are currently no comments for this tutorial.