How to get logged in user name from windows service c#

i use the below code to get logged in user name.
private string GetLoggedInUser()
string userName = "";
if (System.Security.Principal.WindowsIdentity.GetCurrent() != null)
userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
return userName;
just do not understand why it is not giving a logged in user name rather it is return data in this format
NT AUTHORITY\SYSTEM but i want to get user name.
i try to run my service as Local Service and local system account but in every case i am getting this string
NT AUTHORITY\SYSTEM instead of logged in user name.
so please guide me what to change in code. thanks

System is the account the service is running under.
There can be none or many interactive users be logged in. What if none or multiple are logged in? Which one are you referring to then?
Armin

Similar Messages

  • How to get Logged-in user detail from solution Manager.

    Hi to all,
             How can i get details of a user who is logged in into SAP Solution Manager through my webDynpro application. I need to read some values from SAP Solution Manager. How could i do it?? Shall i need to call RFCs??
    If anybody have idea please reply.
    If anybody has some code please send it.
    Points will be rewarded.
    Thanks in advance.

    Pankaj,
    Here is the code to get the logged in user in Web Dynpro.
         //Get the current logged user information
         IWDClientUser user = WDClientUser.getLoggedInClientUser();
         IUser usr = user.getSAPUser();
    String userId = usr.getUniqueName();
    Regards,
    Anand

  • How to retrieve the all user name from system domain(including login user)?

    Hi, I am trying to get the system domain all users name. But I unable to get the all user name except domain login user name. I used the below code. What I want to do to get the all user name from system domain. Kindly any one help me.
    Properties envVars = new Properties();
    Runtime r = Runtime.getRuntime();
    String OS = System.getProperty("os.name").toLowerCase();
         if ((OS.indexOf("nt") > -1) || (OS.indexOf("windows 2000") > -1 ) || (OS.indexOf("windows xp") > -1) )
              p = r.exec( "cmd.exe /c set" );
         BufferedReader br = new BufferedReader ( new InputStreamReader( p.getInputStream() ) );
         String line;
         while( (line = br.readLine()) != null )
              int idx = line.indexOf( '=' );
              String key = line.substring( 0, idx );
              String value = line.substring( idx+1 );
              envVars.setProperty( key, value );
         String domainDNSName = envVars.getProperty("USERDNSDOMAIN");
         String userName = envVars.getProperty("USERNAME");
         System.out.println("\n\n\n DOMAIN NAME == "+domainDNSName +" USERNAME == "+userName);
    Thanks & Regards
    Palani

    Thanks kajbj,
    I don't know, How many users in domain. I neet to get all the user names from my domain. User like A, B,C,D, E,F. I need to get this users name.
    public class Env {
         public static void main(String[] args) {
              System.out.println("USERDOMAIN: " + System.getenv("USERDOMAIN"));
              System.out.println("USERNAME: " + System.getenv("USERNAME"));
    Here , I am getting the login user name only. So i needs all user name. How to retrive or get this.
    Regards
    Palani

  • How can I transfer two user names from an iMac to a new macbook?

    How can I transfer two user names from an iMac to a new macbook?
    got a new laptop and need to transfer two usernames to it, complete with all documents help?

    Assuming you haven't already set up a user, the easiest way is to use the Setup Assistant during first boot of the new Mac, with the two Macs connected by firewire.
    You'll be prompted to migrate from a choice of sources - choose "from another Mac", select the catagories of data you want to transfer and follow the instructions.
    More info here, in Pondini's FAQ; http://pondini.org/OSX/SetupAsst.html

  • How to get list of file names from a directory?

    How to get list of file names from a directory?
    Please help

    In addition, this:
    String filename = files;Should be this:
    String filename = files;
    That's just because he didn't use the "code" tags, so [ i ] made everything following it become italicized.                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to get customer number and name from the SD document

    Hi All,
    Can you please let me know how to get Customer Number and Name from the SD Document?
    Thanks a lot....
    Anil

    Hi,
    It will be displayed in the SD (BIlling document) itself,  you clikc on the VF03. The customer name and number will also appear in the SO document also Tcode VA03
    regards,
    radhika
    Edited by: kolipara radhika on Jul 10, 2009 5:32 AM

  • How to get the Portal Page name from PLSQL?

    Can anyone tell me how to get the portal page name from my dynamic page using plsql?
    Apparently you can get the page id and work it out from there, but my calls to get the page id are not returning any values anyway.
    My code for attempting to get the page id is below.
    <oracle>
    declare
    v_pageid varchar2(30);
    begin
    v_pageid := wwpro_api_parameters.get_value('_pageid', '/pls/portal30');
    htp.print('Page is '|| v_pageid);
    end;
    </oracle>
    Ideally I'd actually just like to get the page name. Is there a straightforward way to do this?
    Thanks in advance!
    Sarah

    Few clarifications -
    1. wwpro_api_parameters cannot be used to get default portal
    page parameters such as '_pageid', '_dad', '_schema' etc.,
    2. Page information can be obtained through any components which
    are available in that particular page. For example, in case of
    dynamic page, we need to publish it as a portlet and add it to the
    page. This process creates necessary packages in the DB, but we
    will not have access to the portlet methods.
    So, I would prefer creating a simple DB provider & portlet and access
    page title from its show method as follows -
    //Declare local variable l_page_id, l_page_title as varchar2
    select page_id into l_page_id from wwpob_portlet_instance$ where
    portlet_id = p_portlet_record.portlet_id and
    provider_id = p_portlet_record.provider_id;
    select name into l_page_title from wwpob_page$ where id=l_page_id;
    More information on DB provider can be found at
    http://portalstudio.oracle.com/pls/ops/docs/FOLDER/COMMUNITY/PDK/articles/understanding.database.providers.html
    Secondly, usage of wwpro_api_parameters.get_value method is
    incorrect. This method expects two arguments -
    <ul>
    <li><b>p_name : </b> The name of the parameter to be returned.</li>
    <li><b>p_reference_path : </b> An unique identifier for a portlet instance on the current page.</li>
    </ul>
    p_reference_path would be something like 99_SNOOP_PORTLET_76535103 and not some type of path as its name suggests.
    The following code fragment fetches all parameters available
    for a portlet.
    Note : Copy this code into 'show' method of your portlet.
    //Declare l_names, l_values as owa.vc_arr
    * Retreive all of the names of parameters for this portlet
    l_names := wwpro_api_parameters.get_names(
    p_reference_path=>p_portlet_record.reference_path);
    * Retreive all of the values of parameters for this portlet
    l_values := wwpro_api_parameters.get_values(p_names=>l_names,
    p_reference_path=>p_portlet_record.reference_path);
    //Loop through these arrays to get parameter information
    htp.p('<center><table BORDER COLS=2 WIDTH="90%" >');
    htp.p('<tr ALIGN=LEFT VALIGN=TOP>');
    htp.tableData(wwui_api_portlet.portlet_heading('Name',1));
    htp.tableData(wwui_api_portlet.portlet_heading('Value',1));
    htp.tableRowClose;
    if l_names.count = 0 then
    htp.p('<tr ALIGN=LEFT VALIGN=TOP>');
    htp.p('<td COLSPAN="2">'
    ||wwui_api_portlet.portlet_text(
    'No portlet parameters were passed on the URL.',1)
    ||'</td>');
    htp.tableRowClose;
    else
    for i in 1..l_names.count loop
    htp.p('<tr ALIGN=LEFT VALIGN=TOP>');
    htp.tableData(l_names(i));
    htp.tableData(l_values(i));
    htp.tableRowClose;
    end loop;
    end if;
    htp.p('</table></center>');
    Hope it helps...
    -aMJAD.

  • Get logged in users name for email notification

    Hi all,
    I am using LC Update 1 with email notifications. In the notification email I would like to write:
    Hi "logged in users name"
    You have got a task in your to do-list...
    The thing is that I can not get the id of the user because the email is sent before he/she completes any step in the process. So I guess I need to look up the user in the same way as the notification-function makes the lookup... How is this done?
    Can you help me here?
    Sincerely
    Kim

    You can use a parameter for the user ID:
    http://livedocs.adobe.com/livecycle/8.2/wb_help/001330.html
    scott

  • How to get the actual font name from a font file?

    Hi
    I have only the font Path I have to get the font name from that path. Any idea how to get the actual font name?
    Thanks,

    I would ask you these questions:
    Why do you need to do this?  What are you ultimately trying to accomplish?
    Are you really asking about the InDesign SDK?
    Do you really need to get the "name" of a font from an arbitrary file?  Or do you want information about a font installed on the system?  If so, what OS?
    Do you need to be able to handle any font format?
    Which font "name" do you mean?
    What language do you want the name in?
    (1) It's not clear what you're trying to accomplish.  A bit more information about your ultimate goal would be helpful.
    (2) This question is not at all specific to the InDesign SDK.  Are you really trying to do something in the context of an InDesign plug-in?  If so, you probably want to look at IID_IFONTFAMILY and the IFontFamily::GetFamilyName function.
    (3) If you are asking more generally, Windows and Mac both have system API calls to get this information, although those tend to deal with installed system fonts, not with arbitrary font files per se.
    Also, you can parse the name table from a True Type or Open Type font without using any system APIs; as True Type and Open Type are well-documented standards.  I would start by reading these:
    The Naming Table
    Font Names Table
    (4) Although there are other standards, such as Type 1 (PostScript) fonts, and True Type Collection files and other formats, especially on Mac.
    (5) Also, when you start down this road, you will quickly realize that your seemingly simple question is actually ambiguous, and that the answer is kind of complicated, because a font can have many names (a family name, a full font name, a style name, a PostScript name, etc.).
    (6) And not only does a font have multiple names, it can have each of those names in multiple languages and encodings.
    Any clarification would make this a better question.

  • How to get the failover partner name from C++ client

    Hi All,
    I have configured the mirroring session for my application.
    I want to modify the connection string with failover partner name.
    Could any one please let me to know how to get the failover partner instance from C++ client dynamically.
    Thanks,
    Prasad.

    Are you looking for this?
    http://www.connectionstrings.com/sql-server-2012/
    http://stackoverflow.com/questions/25534972/auto-failover-multiple-connections-to-mirror-database-when-principal-goes-down

  • How to get Driver and url names from a connection pool

    Hi,
    How to get the DriverName and URL from an existing pool, If I know the name of
    connection pool ? Is it possible to know the name of related pool , if I know
    the name of datasource?
    Thx
    Manish

    hi
    there are 2 ways:
    url must be: jdbc:weblogic:pool[:connectionPoolID]
    or
    jdbc:weblogic:jts[:connectionPoolID] (if you want to use jts with your JDBC connection.)
    see http://e-docs.bea.com/wls/docs60//javadocs/weblogic/jdbc/pool/Driver.html
    However, I think it is safer to configure and use DataSource to get connection.
    Nicolas
    "kumar" <[email protected]> wrote:
    >
    Hi,
    How to get the DriverName and URL from an existing pool, If I know the name
    of
    connection pool ? Is it possible to know the name of related pool , if I
    know
    the name of datasource?
    Thx
    Manish

  • How to know the all user name from system/system login

    hi all,
    i want to know the all user names from system login who are the existing user like
    regards
    srinivas

    Hello,
    Using DBA_USERS will give more details
    select * from dba_users;Regards

  • How to get the target file name from an URL?

    Hi there,
    I am trying to download data from an URL and save the content in a file that have the same name as the file on the server. In some way, what I want to do is pretty similar to what you can do when you do a right click on a link in Internet Explorer (or any other web browser) and choose "save target as".
    If the URL is a direct link to the file (for example: http://java.sun.com/images/e8_java_logo_red.jpg ), I do not have any problem:
    URL url = new URL("http://java.sun.com/images/e8_java_logo_red.jpg");
    System.out.println("Opening connection to " + url + "...");
    // Copy resource to local file                   
    InputStream is = url.openStream();
    FileOutputStream fos=null;
    String fileName = null;
    StringTokenizer st=new StringTokenizer(url.getFile(), "/");
    while (st.hasMoreTokens())
                    fileName=st.nextToken();
    System.out.println("The file name will be: " + fileName);
    File localFile= new File(System.getProperty("user.dir"), fileName);
    fos = new FileOutputStream(localFile);
    try {
        byte[] buf = new byte[1024];
        int i = 0;
        while ((i = is.read(buf)) != -1) {
            fos.write(buf, 0, i);
    } catch (Throwable e) {
        e.printStackTrace();
    } finally {
        if (is != null)
            is.close();
        if (fos != null)
            fos.close();
    }Everything is fine, the file name I get is "e8_java_logo_red.jpg", which is what I expect to get.
    However, if the URL is an indirect link to the file (for example: http://javadl.sun.com/webapps/download/AutoDL?BundleId=37719 , which link to a file named JavaSetup6u18-rv.exe ), the similar code return AutoDL?BundleId=37719 as file name, when I would like to have JavaSetup6u18-rv.exe .
    URL url = new URL("http://javadl.sun.com/webapps/download/AutoDL?BundleId=37719");
    System.out.println("Opening connection to " + url + "...");
    // Copy resource to local file                   
    InputStream is = url.openStream();
    FileOutputStream fos=null;
    String fileName = null;
    StringTokenizer st=new StringTokenizer(url.getFile(), "/");
    while (st.hasMoreTokens())
                    fileName=st.nextToken();
    System.out.println("The file name will be: " + fileName);
    File localFile= new File(System.getProperty("user.dir"), fileName);
    fos = new FileOutputStream(localFile);
    try {
        byte[] buf = new byte[1024];
        int i = 0;
        while ((i = is.read(buf)) != -1) {
            fos.write(buf, 0, i);
    } catch (Throwable e) {
        e.printStackTrace();
    } finally {
        if (is != null)
            is.close();
        if (fos != null)
            fos.close();
    }Do you know how I can do that.
    Thanks for your help
    // JB
    Edited by: jb-from-sydney on Feb 9, 2010 10:37 PM

    Thanks for your answer.
    By following your idea, I found out that one of the header ( content-disposition ) can contain the name to be used if the file is downloaded. Here is the full code that allow you to download locally a file on the Internet:
          * Download locally a file from a given URL.
          * @param url - the url.
          * @param destinationFolder - The destination folder.
          * @return the file
          * @throws IOException Signals that an I/O exception has occurred.
         public static final File downloadFile(URL url, File destinationFolder) throws IOException {
              URLConnection urlC = url.openConnection();
              InputStream is = urlC.getInputStream();
              FileOutputStream fos = null;
              String fileName = getFileName(urlC);
              destinationFolder.mkdirs();
              File localFile = new File(destinationFolder, fileName);
              fos = new FileOutputStream(localFile);
              try {
                   byte[] buf = new byte[1024];
                   int i = 0;
                   while ((i = is.read(buf)) != -1) {
                        fos.write(buf, 0, i);
              } finally {
                   if (is != null)
                        is.close();
                   if (fos != null)
                        fos.close();
              return localFile;
          * Returns the file name associated to an url connection.<br />
          * The result is not a path but just a file name.
          * @param urlC - the url connection
          * @return the file name
          * @throws IOException Signals that an I/O exception has occurred.
         private static final String getFileName(URLConnection urlC) throws IOException {
              String fileName = null;
              String contentDisposition = urlC.getHeaderField("content-disposition");
              if (contentDisposition != null) {
                   fileName = extractFileNameFromContentDisposition(contentDisposition);
              // if the file name cannot be extracted from the content-disposition
              // header, using the url.getFilename() method
              if (fileName == null) {
                   StringTokenizer st = new StringTokenizer(urlC.getURL().getFile(), "/");
                   while (st.hasMoreTokens())
                        fileName = st.nextToken();
              return fileName;
          * Extract the file name from the content disposition header.
          * <p>
          * See <a
          * href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html">http:
          * //www.w3.org/Protocols/rfc2616/rfc2616-sec19.html</a> for detailled
          * information regarding the headers in HTML.
          * @param contentDisposition - the content-disposition header. Cannot be
          *            <code>null>/code>.
          * @return the file name, or <code>null</code> if the content-disposition
          *         header does not contain the filename attribute.
         private static final String extractFileNameFromContentDisposition(
                   String contentDisposition) {
              String[] attributes = contentDisposition.split(";");
              for (String a : attributes) {
                   if (a.toLowerCase().contains("filename")) {
                        // The attribute is the file name. The filename is between
                        // quotes.
                        return a.substring(a.indexOf('\"') + 1, a.lastIndexOf('\"'));
              // not found
              return null;
         }

  • How to get the current user name in Provider hosted app using appOnlyAccessToken

    Hi, 
    Please help me, how to get the HostWeb UserName in Provider Hosted App
    i have Provider hosted App, and Anonymous Authentication is enabled on AppWeb, using appOnlyAccessToken
    Below code does not return current user who Log in in hostweb, it is returning
    SharePoint App (app@sharepoint)
    Web web = clientContext.Web;
    clientContext.Load(web);
    clientContext.ExecuteQuery();
    clientContext.Load(web.CurrentUser);
    clientContext.ExecuteQuery();
    clientContext.Web.CurrentUser.LoginName;
    Below code gives a blank name when Anonymous Authentication is enabled, if Anonymous Authentication is disabled
    app prompts for credentials 
    HttpContext.Current.User.Identity.Name
    Thanks
    Ram

    Hi,
    Since you are using a provider Hosted app if you want to get the current logged in name than do not use AppOnlyAccessToken else use AccessToken which is App + user Context AccessToken.
    then 
    Web web = clientContext.Web;
    clientContext.Load(web);
    clientContext.ExecuteQuery();
    clientContext.Load(web.CurrentUser);
    clientContext.ExecuteQuery();
    clientContext.Web.CurrentUser.LoginName;will return proper user Name.
    HttpContext.Current.User.Identity.Name will never return the user as this object is related to IIS server of your App Server not sharepoint.you should set this as Anonymous in case of provider hosted app.you can download the below sample which uses the AccessToken which has user name in it.https://code.msdn.microsoft.com/Working-provider-hosted-8fdf2d95
    Whenever you see a reply and if you think is helpful,Vote As Helpful! And whenever you see a reply being an answer to the question of the thread, click Mark As Answer

  • How to get logged-in user/group information in WebLogic Portal 10.3.2

    Hi bros.
    I have a codesnipet to get information about user who actually logged in weblogic portal:
    import javax.security.auth.Subject;
    import javax.security.auth.login.LoginException;
    import com.bea.p13n.security.Authentication;
    import com.bea.portal.tools.security.user.*;
    public class UGMSummary {
         private static final String username = "weblogic";
         private static final String password = "webl0gic";
         public UGMSummary(){
         public void test(){
              try {
                   Subject tmp = Authentication.authenticate(username, password);
                   //PolicyItem pi = new PolicyItem();
                   //System.out.println("######## " + Authentication.getCurrentSubject().toString());
                   UserIDBuilder builder = new UserIDBuilder();
                   UserID uid = builder.createResourceID();
                   System.out.println("######## Admin ? " + Authentication.isAdministrator(tmp));
                   System.out.println("######## Anonymous ? " + Authentication.isAnonymous(tmp));
                   System.out.println(" ######## " + uid.getUserName());
              } catch (LoginException e) {
                   System.out.println(e.getMessage());
                   //e.printStackTrace();
    }Some println commands above are used to mark in console. I can ensure that there is an user (admin) logged in weblogic system by executing command: Authentication.isAdministrator(tmp);
    Output of codesnipet above is:
    ######## Admin ? true
    ######## Anonymous ? false
    ######## nullMy problem is impossible to use UserID object to get username of weblogic user. Output of command: uid.getUsername() is: null
    Somebody tell me why my code doesn't work though it can authenticate an user.
    Thank in advance.
    ps:
    Some Javadoc for UserID can be found here:
    http://download.oracle.com/docs/cd/E15919_01/wlp.1032/e14255/index.html
    http://download.oracle.com/docs/cd/E15919_01/wlp.1032/e14255/index.html

    Hi, Kevin.
    I'm glad to see your response again. I found some interesting information from your recommendation link. At this time, I know that impossible to get users/groups information by using DelegatedAtnProxyManagerControlFacade (ref: http://download.oracle.com/docs/cd/E15919_01/wlp.1032/e14255/com/bea/portal/tools/ugm/controls/DelegatedAtnProxyManagerControlFacade.html) interface.
    But, I dont know how to get an instance of an object that implemented this interface. My friend give me a codesnipet that shown the way to get a DelegatedAtnProxyManagerControlFacade by using this codesnipet in a GlobalController:
          try
            DelegatedAtnProxyManagerControlFacade delegatedAtnProxyManager = (DelegatedAtnProxyManagerControlFacade)getControl(DelegatedAtnProxyManagerControlFacade.class);
          catch (PolicyRefException e)
            reportPolicyRefException(e);
          catch (OperationNotSupportedException e)
            reportOperationNotSupportedException(e);
          }But I dont know what global.GlobalController actually is ?
    I've asked Google for information but I got nothing. Do you know any documentation that describes about this controller ?
    Thanks, regards !
    Doubt_Man.

Maybe you are looking for

  • Stops responding when signing in to ebay and stops internet explorer also until computer powered back on from shut down

    when asked to sign back in to my ebay firefox stopped resonding and when i closed it down and tried to reopen firefox it does nothing so i tried explorer and it also would not open.i tried a restart and it was the same.i shut down and they worked aga

  • Issues while  Importing /Mapping hierarchy/taxonomy

    Hi All, We have  multiple level hiererchies with different companies under the same banner.. When we try to map multiple level hierarchies  in import manager to Taxonomy table ..We first map the Class to remote key and then clone Class(which has all

  • Sending smartform as PDF attachment through email

    Hi, I have used the FM SO_NEW_DOCUMENT_ATT_SEND_API1 to send the smartform as PDF attachment through email.In SOST transaction I can see that the mail has been sent to the reciepient,but the mail is not going to the mail box.What would be the reason

  • GR Report

    Dear Gurus, i am new to this network,pls tell me the t.code for gr report with vendor name display.

  • Problem installing Powershell 4.0 in Windows 7

    I am having troubles installing Powershell 4.0 in my Windows 7 Pro system. I downloaded WMF 4.0 and it installed without any error message. When starting PS it still shows 2.0. I tried to start the powershell with -version 4 but it is telling me the