For Form:
The below attached code will help you to Retrieve the Logged in User Details.

Code Brief Explanation:
1) The Javascript code will send the session ID to an ASPX Page.
2) The ASPX page will get the User Detail using 'obj_loggedinuser' and bind it to an XML.
3) The Javascript will Parse the XML and will get the Data.

For Workflow:
In workflow Custom script(Pre-script,Post-script...) itself we can get the user details.

Code:
The code will be auto-generated in the workflow custom script.

Examples:

To get Loggedin User Name:
document.forms["employeedetails"].elements["emp_name"].value=document.currentworkitem.forms["participant"].items["0"].elements["fullname"].value

To get Loggedin User Role:
document.forms["employeedetails"].elements["emp_name"].value=document.currentworkitem.forms["participant"].items["0"].elements["role"].value