I need to detect if the current user is system account. With SPServices i can find user login name:

var thisUserName = $().SPServices.SPGetCurrentUser({
                        fieldName: "Title",
                        debug: false


But with system account logged in, this JS function gives the login name of the real user so i cannot define that the user is system account.

  • I'm not sure why this wouldn't work as well as any of the other posts below. Weren't you getting the system account name? – Marc D Anderson Feb 7 '13 at 4:25
  • No the code block in my question post does not give system account, it only gives the login name of the real user. – ozdogan Feb 7 '13 at 7:14
  • That's exactly what the get_currentUser() functions below will give, so I'm not sure what you mean. – Marc D Anderson Feb 7 '13 at 12:17

You can achieve required functionality using sharepoint javascript object model, try following code:

SP.SOD.executeOrDelayUntilScriptLoaded(runMyCode, "SP.js");
function runMyCode() {
    var ctx = new SP.ClientContext.get_current();
    var web = ctx.get_web();
    var user = web.get_currentUser();
        function () {
                    //success function
            if(user.get_loginName() == "SHAREPOINT\\system"){
                alert(String.format("This is system account - {0}", user.get_loginName()));
            } else {
                alert(String.format("This is normal user - {0}", user.get_loginName()));
        function (data) {
            //notify the failure

By this code you should able to get the "system\account" user:

   context = new SP.ClientContext.get_current();
   web = context.get_web();
   var currentUser = web.get_currentUser();

I don't know how the SPServices library works, but if you need the user name/login to be displayed as "System Account" you can try this:

var context = new SP.ClientContext.get_current();
var web = context.get_web();
theUser = web.get_currentUser();


After that theUser.get_title() should report "System Account", while theUser.get_loginName() should display "SHAREPOINT\system" (Note: I have left out the call back code for executeQueryAsync)

Can this be enough for you?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.