Check whether logged in user has admin previleges

Hi,
Can anyone share c# code that checks whether the logged in user is Farm administrator.
Thanks in advance

Hi 
You can check using below code 
public static bool IsFarmAdmin(string loginName)
            bool isFarmAdmin = false;
            SPSecurity.RunWithElevatedPrivileges(delegate()
                SPGroup adminGroup = SPAdministrationWebApplication.Local.Sites[0].AllWebs[0].SiteGroups[“Farm Administrators”];
                foreach (SPUser user in adminGroup.Users)
                    if (user.LoginName == loginName)
                        isFarmAdmin = true;
                        break;
            return isFarmAdmin;
below is reference for the same
https://social.msdn.microsoft.com/Forums/office/en-US/1fa3287a-c732-4924-b75d-fec493446389/checking-if-a-given-user-is-farm-administrator?forum=sharepointdevelopmentlegacy
or this
Some possibly easier ways would be the following:
bool isSiteAdmin = SPContext.Current.Web.UserIsSiteAdmin;
isSiteAdmin = SPContext.Current.Site.UserIsSiteAdminInSystem;
bool isFarmAdmin = SPFarm.Local.CurrentUserIsAdministrator();
https://social.msdn.microsoft.com/Forums/office/en-US/9ecf128b-a2b9-4669-b86c-aaaba19ff97d/how-to-determine-if-a-user-is-site-collection-or-farm-admin-in-the-webpart-c-code?forum=sharepointdevelopment
Regards, Rajendra Singh If a post answers your question, please click Mark As Answer on that ost and Vote as Helpful http://sharepointundefind.wordpress.com/

Similar Messages

  • Active Directory: user has admin rights when logs in for the first time

    I have an Xserve server running OS X server 10.5.8 and trying to host _open and active directory_ for both Mac and PC machines. The open directory works fine but what happens on the active directory side is that, when a user logs in from a windows machine he/she can access all the other users folders. In other words, he/she almost has *admin rights*. Is this normal or there is some settings that I can look into to fix this?
    Details: The first time user logs in, his only effect on the server is the password change. What this means is that his changes dont get uploaded to the server. It is only the second time the user logs in from ANOTHER computer that the server starts saving the his profile. Also, after the second login the user doesnt have admin rights anymore.
    Thanks,
    MR

    If you've just changed your login password in Recovery mode, follow these instructions. Otherwise, see below.
    At some point, you may have reset your keychain to default in Keychain Access. That action would have caused your login keychain to be renamed.
    Back up all data before proceeding.
    In Keychain Access, delete the login keychain from the keychain list. Choose Delete References when prompted, not Delete References & Files.
    Triple-click anywhere in the line below on this page to select it, then copy the text to the Clipboard by pressing the key combination command-C:
    ~/Library/Keychains
    In the Finder, select
              Go ▹ Go to Folder...
    from the menu bar, paste into the box that opens (command-V), and press return. A folder will open. Rename the file "login.keychain" in that folder to something like "login-old.keychain". Rename the file "login_renamed_1.keychain" to "login.keychain". You can then close the folder.
    Back in Keychain Access, select 
              File ▹ Add Keychain...
    from the menu bar. Add back the file now named "login.keychain". If any of your needed keychain items are missing from it, also add back the file you named "login-old.keychain". I suggest you transfer any needed items from that keychain to the login keychain, then delete it. The transfers are made by drag-and-drop in Keychain Access. You'll need to enter your password for each item transferred.

  • Log to check as to which user has accessed which report?

    Hi,
    I am using BOBJ for report creation and SAP BI for datawarehousing.
    The user can access these reports using the iviews created in the portal. Due to some performance testing requirements we need to check which user accessed which report and if he has drilled down to a particular level in a report, then there should be a means to know that as well.
    BO offers a few standard activity reports to check which user has done which activity. However the details of drill down etc. cannot be checked using that. Please help as to how can we check that too.
    Best Regards,
    Neha

    Hi,
    See [Business Objects|/community [original link is broken]; and [Crystal Reports|/community [original link is broken]; forums for this topic.
    -Paul

  • How do can I have the form fill in a check box if the user has entered text in a textbox?

    I have a form that is submitting an xml data file that is picked up by MS Word and used to populate a document. However, there's a 'Miscellaneous' field where the user can type in addtional information that would not drop easily into the Word document (exceptions, items not on the drop down lists, etc.). I'd like to test to see if that Miscellaneous field has infomation in it and if it does, to set a invisible checkbox to "1" so that I can insert a text message in the Word document that there's additional information in the .pdf form that will have to be addressed manually in the Word document.
    I've tried
    if(Misc.rawValue !== "")
    otherinfo.rawValue = 1;
    but while it doesn't generate a Javascript error, it doesn't set the value either, and I haven't found any function that checks for whether a field is empty. I'm sure there's got to be a way to do this, but I'm stumped. Any help greatly appreciated!
    Bill

    It appears you are using LiveCycle Designer, so you will have to use the syntax of FormCalc or LiveCycle Designer JavaScript.
    For FormCalc:
    if(HasValue(Misc)) then
    otherinfo = 1
    else
    otherinfo = 0
    endif
    For JavaScript
    if(HasValue(Misc.rawValue))
    otherinfo.rawValue = 1;
    else
    otherinfo.rawValue = 0;
    I added code to clear the check box if the user clears the field.

  • Webdynpro - Check if a portal user has a user in R/3 Backend

    Hi Experts,
    i have following problem, and maybe some of you can help me out with an idea or (much better) a solution:
    Our Company is running an Enterprise Portal on NW2004s (SPS 18). Currently i am developing a Java WebDynpro Application for the portal called Transactionstarter. Withhin this application a portal user can simply add a backend System (R/3), a transaction and a Description. This information will be stored in a xml file in userhome in KM. When the user clicks the description, SAP WinGui will open with the transaction he defined before. We use SSO for opening the transaction if the user has a backend user. If not, the loginscreen of the backend will appear.
    All this works fine.
    Now we have the requirement for an automated system check.
    The portal user can run an initial system check. This system check should check all configured backend systems if the portal user has a user in R/3 backend.
    But how can i check if my portal user exists in backend?
    I cannot use JCO because we have a lot of Systems (more than 300 all together) and i don´t want to create a destination for every system. Or did i misunderstood something with JCO?
    Does anyone of you have a solution, how i can check every system, if the portal user has also a backend user?
    Thanks in advance.
    Regards
    Pascal

    Hi Pascal,
    with JCO you can use also the method JCO.createClient:
    public static JCO.Client createClient(java.lang.String client,
                                          java.lang.String user,
                                          java.lang.String passwd,
                                          java.lang.String lang,
                                          java.lang.String mshost,
                                          java.lang.String r3name,
                                          java.lang.String group)
    Creates an instance of a client connection to a remote SAP system (with load balancing)
    Parameters:
    client - SAP logon client
    user - SAP logon user
    passwd - SAP logon password
    lang - SAP logon language
    mshost - Host name of the message server
    r3name - Name of the SAP system
    group - Name of the group of application servers
    Returns:
    the newly created client
    for connections to other systems. So you can avoid to create destinations
    Regards
    Matteo
    Edited by: Matteo Fusi on Apr 1, 2009 11:33 AM

  • Is there a way to check whether an Excel file has a header or not?

    Hi!
    I'm currently using POI Utility to read and write Excel files.
    You normally use the HasHeaderRow = true / false to specify whether the file has a header or not.
    Now, let's say I have a program that needs to read Excel files from a directory, some have headers, some don't.
    Is there a way to know dynamically whether a header has been defined or not?
    Then, for those having headers, the flag will be set as true, while for those which don't have any header, the flag will be set as false.
    E.g.
    <!--- Create an instance of the POIUtility.cfc. --->
        <cfset objPOI = CreateObject(
            "component",
            "POIUtility"
            ).Init()
            />
    <!--- Set directory --->
    <cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "newDir">
    <!--- Check whether the directory exists. --->
    <cfif DirectoryExists(variables.currentDirectory)>
         <!--- Read files from the specified directory --->
         <cfdirectory action="list" directory="#variables.currentDirectory#" type="file" filter="*.xls" name="qDirectory">
         <!--- Check if the directory has any Excel file --->
         <cfif variables.qDirectory.recordcount gt 0>
              <!--- Loop query --->
         <cfloop query="variables.qDirectory">
                   <!--- Check if header is present in each of the file --->
                        IF headerExists THEN
                             headerFlag = true
                        ELSE
                             headerFlag = false
                        END IF
                   <!--- Read Excel File --->
                <cfset objSheet = objPOI.ReadExcel(FilePath = #variables.qDirectory.name#, HasHeaderRow = #variables.headerFlag#, SheetIndex = 0) />
              </cfloop>
         </cfif>
    </cfif>
    Any help would be most welcome.
    Thanks and regards,
    Yogesh Mahadnac  

    Hi cfSearching,
    Many thanks for your reply! I really do appreciate!
    However, I've still got 1 more question for you.
    At the moment, I'm using POI and sometimes cfx_Excel2Query to read Excel files.
    In both cases, you have to specify whether the first row is a header.
    How would you read the Excel file to check whether the 1st row is the header?
    I've tried using cffile, but I get all sorts of "garbage"
            <cffile action="read" file="#variables.filename#" variable="xlsResult">
            <cfloop index="i" list="#variables.xlsResult#" delimiters="#chr(13)#&#chr(10)#">
                <cfif variables.i eq 1>
                    <cfoutput>
                        Test 1st Row: #trim(replacenocase(listgetat(variables.i,1,","),'"',"","All"))#
                    </cfoutput>
                </cfif>
            </cfloop>
    I get the following output:
    ÐÏ à¡± á����.... etc etc
    I'd be very much grateful if you could please advise on the latter at your earliest convenience.
    Thanks and best regards,
    Yogesh Mahadnac

  • Caml query to check current logged in user - SharePoint designer

    Hi,
    I need to create a caml query in SharePoint designer to satisfy the below conditions.
    If the logged in user (current user) is a member of a specific group. e.g. Group Name = ISS Owners, ID=5
    (OR)
    If the logged in user (current user) exists in assigned to field. e.g. Field Name = Assigned To
    Reference to the below link is not working for my solutions.
    Membership Element (Query)
    CAML Query – Membership attribute
    Kindly help in resolving caml query issue.
    Anandhan.S Remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.

    The second condition is pretty straightforward
    <Eq>
    <FieldRef Name="AssignedTo"/>
    <Value Type="Integer">
    <UserID />
    </Value>
    </Eq>
    but I don't think you can do the former. The <Membership> condition can only be applied to a <FieldRef>, not a generic <Value> argument.
    But what would be the purpose of the first condition in the first place? It's invariant, not related to specific list items. Or is the requirement to return all items if the user is a member of a group (Administrators?), but only assigned-To items if not:
    If so, is there some way you can refactor the check for the former condition into some higher level logic? 

  • Use Powershell to check whether and AD user exists

    We're trying to clean up roaming profile folders, and as part of the task I need to check whether the user actually exists in AD.  I have tried 3 different methods and so far none of them work.
    Either the empty result of the search doesn't equal $null (e.g. If ($objUser -eq $null) resolves to false) or Powershell crashes (like when I try to run that If statement).  So is there an AD User equivalent to Test-Path?
    RF

    I should add, if you want to use PowerShell filter syntax, you can use:
    $Name
    = "jsmith"
    $User = Get-ADUser
    -Filter {sAMAccountName
    -eq $Name}
    If ($User
    -eq $Null) {"User does not exist in AD"}
    Else {"User found in AD"}
    And if you only have PowerShell V1, you can use the following:
    $Name =
    "jsmith"
    $Searcher =
    [ADSISearcher]"(sAMAccountName=$Name)"
    $Results =
    $Searcher.FindOne()
    If ($Results
    -eq $Null) {"Users does not exist in AD"}
    Else {"User found in AD"}
    In all cases I assume you are checking the "pre-Windows 2000 logon" name, not the Common Name (the value of the cn attribute, which does not uniquely identify the object in AD).
    Richard Mueller - MVP Directory Services

  • How to check whether java.sql.Connection has been dropped or not

    Hi,
    How can i check whether the connection is dropped from the database or not by using java.sql.Connection API.
    Thanks

    There's a few ways to check Connections, each with a different use:
    (1) conn.isOpen()
    (2) conn == null
    (3) the last one is a little more involved and adds some overhead. You can run SELECT 1 FROM dual; (Oracle) or SELECT 1 (MSSQL) and check for exceptions.
    The only way to check a connection, as far as I know, is to use it. That said, there must be a better way???

  • User is not present any sharepoint group,But user has permissions to all subsites(almost user has admin permissions)

    I am having sharepoint site.one of the user is not present in any sharepoint group and also not present in site collection administrators but user has all the permissions in the site.Some members who are in the owner group(full control) also
    does not have permissions to add new users to some groups but the user who is not present in any group has permission to add new users also.How this user is able to access?.But user is present in people and groups

    HI
    First find out from where user getting permission.
    Hi 
    You can use get-spuser for the same.
    Listing All the SharePoint Groups to Which a User Belongs
    To list all the SharePoint groups to which a user belongs, you first need to find that user's SPUser object:
    $user = Get-SPUser -Web http://server/sites/yoursite |
      Where {$_.LoginName -LIKE "*|DOMAIN\SAMC"}
    Once you have this object, you can scan all the site collections in the farm and find all the groups to which the user belongs:
    Get-SPSite -Limit All |
      Select -ExpandProperty RootWeb |
      Select -ExpandProperty SiteUsers |
      Where { $user.UserLogin -EQ $_.LoginName } |
      Select -ExpandProperty Groups |
      Select Name, {$_.ParentWeb.Url}
    below link refer the same.
    http://sharepointpromag.com/sharepoint-2013/exploring-sharepoint-users-groups-and-security-using-powershell
    Hope this help you to find out user group
    Regards, Rajendra Singh If a post answers your question, please click Mark As Answer on that ost and Vote as Helpful http://sharepointundefind.wordpress.com/

  • When logging in user has two copies of network shares get mounted.

    Sorry if this is posted in the wrong place. I did a search but couldn't find my exact issue.
    I have a Leopard 10.5.8 20" iMac. When the user logs in they have 3 network shares on an X-serve that get mounted automatically. The issue is that two copies of the drives are mounted, when restarting. I went into the login items and unchecked the network drives, but they still auto mount.
    I hit ctrl+k and they aren't listed in the connect to server dialogue.
    I ejected the mapping to the server itself, and they still came back.
    Anyone have any idea why two copies of the network shares would mount?
    This only affects this user. I thought about creating a new account, and moving the data to the new account. I guess I will do that if I have to.
    Thanks for your help.

    +"which file itunes is referencing to get the music. whether it's referencing the file that is in my general music folder, or whether it is getting it from my itunes folder. I want to delete the extra one."+
    If you start with an original song file outside the iTunes Music folder, and you add the song to your iTunes library while the "Copy..." option is checked, then iTunes makes a copy of the file in your iTunes Music folder, and that is the copy it references. Once copied, iTunes no longer needs the original file, so you can delete it if you have no other need for it.
    If you are ever in doubt which copy of the song iTunes is referencing, you can right-click the iTunes library entry and choose "Show in Finder."
    If you have always had "Copy..." checked, and if you have never moved your iTunes Music folder and have never manually moved anything, then iTunes has everything it needs in the iTunes Music folder and you can delete the others. But obviously, be careful.

  • Checking if a user has a role (FGAC)

    Hi!
    I am implementing Fine Grained Access Control on a table and in my policy function I do not want to restrict the amount of result data on a select if the current user has a certain role (otherwise I want to).
    My idea was to check USER_ROLE_PRIVS/ROLE_ROLE_PRIVS for the role, but the stored procedure runs with definer-rights, so that won't help.
    Running the procedure with invoker-rights won't help either, since not the current user is the invoker of the policy function but the DB system (user sys?).
    And finally, the definer of the policy function does not have DBA privs, so I can't select the DBA_* views to check if the current user has the role.
    Is there another way to check if the current user that is known inside the policy function by the USER variable has a certain role?
    Thanks for your help!
    Marcus

    Hi Frank,
    thanks for your answer!
    Frank Kulash wrote:
    Policy functions are run by the user who queries or tries to do DML on the table.I don't see that this is happening. Here's my test case:CREATE OR REPLACE FUNCTION CU_is_member_of
    (v_role IN VARCHAR2) RETURN NUMBER
    AUTHID CURRENT_USER
    is
    v_res VARCHAR2(255);
    begin
    SELECT COUNT(*)
    INTO v_res
    FROM
    (SELECT GRANTED_ROLE FROM USER_ROLE_PRIVS
    UNION
    select GRANTED_ROLE from role_role_privs)
    WHERE UPPER(GRANTED_ROLE)=UPPER(v_role);
    RETURN to_number(v_res);
    end;
    CREATE OR REPLACE FUNCTION POLIFUNC_PARTTYPES_WRITE
    (p_schemaname IN varchar2, p_tablename IN varchar2)
    RETURN VARCHAR2
    IS
    BEGIN
    IF USER=p_schemaname
    THEN RETURN '';
    ELSE
    BEGIN
    if SYSWM_TOOL.CU_is_member_of('#ACT#WMT_MANAGE_PARTTYPES')=1
    THEN RETURN ''; -- *****
    ELSE
    BEGIN
    RETURN '1=0';
    END;
    end if;
    end;
    END IF;
    END;
    CALL SYS.DBMS_RLS.ADD_POLICY('SYSWM_TOOL', 'TBL_PARTTYPES', 'POL_PARTTYPES', 'SYSWM_TOOL', 'POLIFUNC_PARTTYPES_WRITE', 'select'); --TODO: SELECT-&gt;UPDATE,INSERT,DELETE
    If the policy function is run by the user who queries, then I would expect that a user who has the role querying table TBL_PARTTYPES would see all entries since he would run into the line marked with *****.
    SQL&gt; select SYSWM_TOOL.CU_is_member_of('#ACT#WMT_MANAGE_PARTTYPES') FROM DUAL;
    SYSWM_TOOL.CU_IS_MEMBER_OF('#ACT#WMT_MANAGE_PARTTYPES')
    1
    SQL&gt; SELECT COUNT(*)
    2 FROM
    3 (SELECT GRANTED_ROLE FROM USER_ROLE_PRIVS
    4 UNION
    5 select GRANTED_ROLE from role_role_privs)
    6 WHERE UPPER(GRANTED_ROLE)=UPPER('#ACT#WMT_MANAGE_PARTTYPES');
    COUNT(*)
    1
    So, the current user has the role and the stored function CU_IS_MEMBER_OF works correctly. However:
    SQL&gt; select count(*) from syswm_tool.tbl_parttypes;
    COUNT(*)
    0
    What am I missing here?
    Marcus

  • How to check whether the system has eclipse environment: urgent

    Hi gurus
    can you please tell me how to check whether my crm system has eclipse envirionment.
    Thanks
    shashi

    There is no way to check whether a system is used productively or not, I believe what you mean is checking a client is productive or not in an ABAP-stack based system. Remember although a SAP ABAP system is identified by a SID but from a business perspective the system is recognized by a client, as it is a unique business identity.
    Thus, to check whether the client is productive or not in txn SCC4 check the role of the client, it will show you the correct status. The data of SCC4 is stored in table T000, you can also opt to check that.
    - Regards, Dibya

  • How to determine if a user has access to an item

    Without using the WWSEC_API, i need to find out if a user (not the logged in user) has the right privileges to view an item (url).
    Has anyone identified what tables are involved in determining if a user has access to view an item ?

    Create a vo with the following SQL passing userid as bind value:
    SELECT C.USER_NAME,
    B.RESPONSIBILITY_NAME,
    A.START_DATE,
    A.END_DATE
    FROM APPS.FND_USER_RESP_GROUPS_DIRECT A,
    APPS.FND_RESPONSIBILITY_TL B,
    APPS.FND_USER C
    WHERE C.USER_ID = A.USER_ID
    AND C.USER_NAME= :1
    AND B.RESPONSIBILITY_ID = A.RESPONSIBILITY_ID
    You will have the list of all the responsibilities of a user.
    Kristofer

  • How to check whether the vendor invoice was reversed (MR8M & FB08)

    hi,
    need to check whether the vendor invoice has been reversed. Posting of the vendor invoice as well as its reversal may happen in FI (e.g. FB60 - FB08) and MM (MIRO - MR8M).  have developed a custom function based on the values of the fields: stblg, stjah,... (for fb08) and rebzg, rebzj,rebzz (for mr8m) and trans type but not sure this is the right way.
    Is there a bapi (e.g. similar to BAPI_ACC_INVOICE_REV_CHECK) , sap function or at least a report to as a sample. Any help appreciated.
    Thank you,
    victor

    Viktor, We have always used the table fields values you have listed to determine if the invoice has been reversed or cancelled...

Maybe you are looking for