Get logged on windows username

Hi,
I have a tomcat server running my webapps.
And I need a way to retrieve the username of user(client) currently logged on(windows) .
Any help will be great.
Thanks

this is all that you need copy the code and save it as a .jsp file
<%@ page import="sun.misc.BASE64Encoder,java.util.regex.*" %>
<p><h1>Network Windows USERNAME without any login (ie)</h1></p>
<%
String auth = request.getHeader("Authorization");
if (auth == null) {
        response.setStatus(response.SC_UNAUTHORIZED);
        response.setHeader("WWW-Authenticate", "NTLM");
        return;
if (auth.startsWith("NTLM ")) {
        byte[] msg = new sun.misc.BASE64Decoder().decodeBuffer(auth.substring(5));
        int off = 0, length, offset;
        String s;
        if (msg[8] == 1) {
            off = 18;
            byte z = 0;
            byte[] msg1 = {(byte)'N', (byte)'T', (byte)'L', (byte)'M', (byte)'S',
                            (byte)'S', (byte)'P', z,
                            (byte)2, z, z, z, z, z, z, z,
                            (byte)40, z, z, z, (byte)1, (byte)130, z, z,
                            z, (byte)2, (byte)2, (byte)2, z, z, z, z, //
                            z, z, z, z, z, z, z, z};
            response.setStatus(response.SC_UNAUTHORIZED);
            response.setHeader("WWW-Authenticate", "NTLM "
                  + new sun.misc.BASE64Encoder().encodeBuffer(msg1).trim());
            return;
        else if (msg[8] == 3) {
                off = 30;
                length = msg[off+17]*256 + msg[off+16];
                offset = msg[off+19]*256 + msg[off+18];
                s = new String(msg, offset, length);
                //out.println(s + " ");
        else
                return;
        length = msg[off+1]*256 + msg[off];
        offset = msg[off+3]*256 + msg[off+2];
        s = new String(msg, offset, length);
        //out.println(s + " ");
        length = msg[off+9]*256 + msg[off+8];
        offset = msg[off+11]*256 + msg[off+10];
        s = new String(msg, offset, length);
          Pattern pat = Pattern.compile("[a-z,A-Z,0-9]+");
          Matcher mat = pat.matcher(s);
          String s1 = "";
          while(mat.find())
                         System.out.println("Got name: "+mat.group());
                         s1 = s1+mat.group();
          System.out.println("Got name: "+s1);
          if(s.indexOf('.')!=-1)
               System.out.println("dots!!!");
          s.replaceAll("[.]","");
          System.out.println("Got name again: "+s);
        out.println(s);
        out.println("Hello  <span style='position:relative; width:190;"
            + " height:10;filter:glow(Color=#009966,Strength=1)'>");
        out.println(s + "</SPAN>");
          out.println("<br><br><b>"+s+"</b>");
%></BODY>

Similar Messages

  • Logged in windows username cant be searched in LDAP tree on Windows 2000 AD

    That is my active directory of my TEST Windows 2000 server:
    http://img248.imageshack.us/img248/918/adwn6.gif
    On the image yu will find 4 schools with shortcut names called:
    OU=ASR
    OU=EDS
    OU=EKS (EK school for example)
    OU=THS (TH school for example)
    Under every OU="shortcut of schoolname" you will find also the
    OU=Klassen (Klassen = classes in english)
    OU=Lehrer (Lehrer = teacher in english)
    again under every OU="class" and OU="teacher" you will find also the
    pupils and teachers.
    the teacher "verena bit" is located in:
    "CN=verena bit,OU=Lehrer,OU=ASR,DC=Bodensee,DC=DE"
    On the REAL Windows 2000 server used in production i have about 17 schools like OU=ASR or OU=EDS and so on...
    My part aim for the first...:
    With Java code: String Lehrer = System.getProperty("user.name");
    I can retrieve the name of the teacher (Lehrer = teacher) who has logged into the Windows client. The problem is i get for example a String like
    "verenabit" but in the ldap hierarchy all common names are for example like this: cn="verena bit" they have always a " " gap between the forename and the lastname so I can not use the String "verenabit" to search for it in the ldap tree as she would not exist right?
    What i finally want is to find out the OU="shortcut of schoolname" (see above) by searching for the logged in teacher. So when i have OU="shortcut of schoolname" of the teacher i am able to read ONLY the usernames(teachers+pupils) of that specific school and not all teacher+pupils of all 17 schools what would be about 8000 users :-D
    Can someone help me please how can i use the username of the logged in windows user and search him effectively in the ldap tree on my test windows 2000 server.
    Steven you want all my points? ROFL ;-)

    Here's a hint.
    Use a generic ldap tool (for example ldp.exe which is
    included in Windows Server, or whatever your
    favourite ldap browser is, and find the object in the
    Active Directory that corresponds to the user named
    Verna Bit.
    Believe it or not, you will find an attribute which
    has matching value to that returned from
    System.getProperty("user.name");Then you just need to construct the relevant LDAP
    Query Filter.
    It ain't rocket science !
    Good luck.Yes i already use ldp.exe i installed it from the win2k server CD its a great tool :)
    hm your hint is odd or how can i say dont know wether you really understood me, because what you suggested to me is actually what i doubted that it could work. Seems you have more faith??
    The problem is (not sure wether you really understood me...) that when i search the whole Directory having 8000 user, I could search for teachers only which are in OU=Lehrer (Lehrer = teacher) and just go one childnode down but "verena bit" IS NOT "verenabit". I cannot search for the username verenatbit as i wont get any result as it does not exist.

  • How to get the windows username in jsx

    Hello,
    I have a JSX script in "My Documents\Adobe Scripts" to make it trusted script. I have another text file I need to read from JSX. Since the location depends on logged in user, I need to find the windows username. If anyone know how to get the windows username from jsx please reply.
    Thank you very much.
    Regards
    Nima.

    Hey,
    You can get username like this:
    var myUsername = $.getenv('username');
    You could also get My Documents folder like this:
    var myDocFolder = Folder.myDocuments;
    Hope that helps.
    Marijan (tomaxxi)
    http://tomaxxi.com/

  • Get Log on Username in system session ..

    Hi,
    I'm developing a windows service and i need to get log on username but the problem is service is running under system account so it always return
    system as username, is there any way to get log on username thru service which is running under system account ?? I'm using windows 7
    Thanks and regards.

    Since windows services run in Session 0, I don't think it'll show what Wall.E wants.
    On the other hand, I forgot that the current console user can be found on Win32_ComputerSystem as well. I've tested the following code can get console user name on service.
    private string GetConsoleUser()
    string username = String.Empty;
    ManagementScope scope = new ManagementScope("\\\\.\\root\\cimv2");
    ManagementObjectCollection compQuery = new ManagementObjectSearcher(scope, new SelectQuery("select * from Win32_ComputerSystem")).Get();
    foreach (ManagementObject item in compQuery)
    username = Convert.ToString(item["username"]);
    return username;

  • How get windows username

    Hi,
    In my java application I have following code to get windows username-
    *<%*
    String s1 = System.getProperty("user.name");
    out.println("The Username : "+s1+" ");
    String s2 = System.getenv("USERNAME");
    out.println("The Username : "+s2);
    *%>*
    If I log in to my PC and execute it I get correct output for both the statements, But when I execute it on server machine(when I logged in) I get the output as-
    The Username : SYSTEM The Username : null
    I use Apache Tomcat 5.5 to run the jsp on both (PC & server) machines. One small difference is I use eclipse on my PC and I don't use eclipse on server (I think it doesn't matter).
    But when I use the same code inside a java class I get correct output on both (PC & server) machines.
    Can any one solve my problem.
    Thanks in advance,
    Tiijnar

    tiijnar wrote:
    Hi BalusC,
    Thanks for the reply.
    Could you please be more elaborted on this. What I mean is- can you provide me the code for the applet.Just the same code. Use System#getProperty() in an applet. The only difference is that the applet runs at the client machine and the Java web application runs at the server machine. If your problem is rather that you don't know how to use applets, just check the applet tutorial here at sun.com. Google can find it.
    Moreover when I execute jsp on my PC, I execute it on localhost (a server inside my PC). I face the problem when I host my application on my server machine.D'oh. On "localhost" the client and the server are physically on the same machine.

  • How to get windows username printed on each page irrespective of application? we have cm6030f.

    How to get windows username printed on each page irrespective of application? we have HP CM6030F.

    Hi,
    Normally, you will receive a Windows Azure Pass from your local Windows Azure team. Please try to contact your local Windows Azure contact (http://support.microsoft.com/gp/customer-service-phone-numbers?wa=wsignin1.0
    Also, you could see this page
    http://www.windowsazurepass.com/AzureU/AcademicFAQ and apply the free trial azure via (http://www.windowsazurepass.com/AzureU/).
    Q: I am a student. Can I apply for a pass?                     
    A: Windows Azure Educator Grants are only for valid faculty. If your faculty has been awarded a Windows Azure Educator Grant, you will be able to get a pass through him/her for you coursework. If you are interested in learning more about Windows Azure,
    we encourage you to share these Educator Grants with your faculty or sign up for the FREE 3-month trial offer. 
    Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • 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

  • How to get windows username & password

    Hi friends,
    Requirement is to get windows username & password,
    My server is Tomcat4.0,
    My code in login.jsp page is
    <%
    String auth = request.getHeader("Authorization");
    if (auth == null) {
    response.setStatus(response.SC_UNAUTHORIZED);
    response.setHeader("WWW-Authenticate", "NTLM");
    return;
    if (auth.startsWith("NTLM ")) {
    byte[] msg = new sun.misc.BASE64Decoder().decodeBuffer(auth.substring(5));
    int off = 0, length, offset;
    String s;
    if (msg[8] == 1) {
    off = 18;
    byte z = 0;
    byte[] msg1 = {(byte)'N', (byte)'T', (byte)'L', (byte)'M', (byte)'S',
    (byte)'S', (byte)'P', z,
    (byte)2, z, z, z, z, z, z, z,
    (byte)40, z, z, z, (byte)1, (byte)130, z, z,
    z, (byte)2, (byte)2, (byte)2, z, z, z, z, //
    z, z, z, z, z, z, z, z};
    response.setStatus(response.SC_UNAUTHORIZED);
    response.setHeader("WWW-Authenticate", "NTLM "
    + new sun.misc.BASE64Encoder().encodeBuffer(msg1).trim());
    return;
    else if (msg[8] == 3) {
    off = 30;
    length = msg[off+17]*256 + msg[off+16];
    offset = msg[off+19]*256 + msg[off+18];
    s = new String(msg, offset, length);
    //out.println(s + " ");--------------------------> here getting system_name
    else
    return;
    length = msg[off+1]*256 + msg[off];
    offset = msg[off+3]*256 + msg[off+2];
    s = new String(msg, offset, length);
    //out.println(s + " ");
    length = msg[off+9]*256 + msg[off+8];
    offset = msg[off+11]*256 + msg[off+10];
    s = new String(msg, offset, length);
    out.println("Hello <span style='position:relative; width:190;"
    + " height:10;filter:glow(Color=#009966,Strength=1)'>");
    out.println(s + "</SPAN>");----------------------------------->here getting loginname.
    %>
    from this i was able to get systemname & username,How do i get password.
    Is it possible to get password?
    Thanks,
    Satya.

    There's no way to get the password. NTLM uses a two-round challenge-response scheme which never send the password (neither clear nor encrypted) on the wire.
    Why do you need the user's password? Is your service going to access a backend service using the user's credential? If so, you may need to use Kerberos delegation.

  • Can't get past Log-In window--Safe Boot

    I'll try and keep this easy/short: My iMac g-5(first Gen i-sight), when upon startup, the wheel would just spin and then the fans would blow turbo while stuck on the spinning wheel. Was running on Tiger but was able to salvage the h/d and all on it, no damage to it. So we erased all on my iMac and tried booting from disc. No good. Tried starting from another laptop; No good. Then cloned from working Leopard laptop, did basic install and got to the Log-in widow--in Safe Boot mode and cannot get past the Log-in window. I get a dialogue box w/an applications icon that says, " You are unable to log in to the user account "..." at this time. Logging in to the account failed because an error occurred." I hit okay and the dialogue box shakes a frustrating no at me.
    What do I do now?
    Any ideas? Thanx to all.

    Try an Archive and Install now, it will put a fresh copy of the OS but keep, your data and preferences. Cloning from a different system is not a very good idea, you run into the problems you have, and probably other ones as well.
    If the A&I doesn't work, you may have to wipe your drive and perform a clean install of Leopard.

  • Getting Windows Username In A Page

    Hello,
    I am currently developing an application that requires to know the Windows username, these are generic and will be used as a terminal. I was wondering if it is possible to get this information? I know I can use javascript and a active x control but I don't really want to go down that route.
    Our technology stack is:
    Apex 4.2.2.00.11
    Apex Listener 2
    Oracle 10g, 10.2.0.4.0
    Thanks,
    Paul.

    Here's a barebones script that you can call from a script in your form to retrieve the login name of the user:
    // Folder-level JavaScript function
    var getLoginName = app.trustedFunction(
        function () {
            // Get and return the user's login name
            app.beginPriv();
            return identity.loginName;
            app.EndPriv();
    This needs to be included in a JavaScript file that's installed in the correct location. It's just a text file, so you can create/edit it with a text editor, but make sure the extension is ".js". For more information about how to determine where to place the file, see: http://acrobatusers.com/tutorials/2006/folder_level_scripts
    More information on all of this is in the Acrobat JavaScript reference: http://www.adobe.com/devnet/acrobat/javascript.html
    To populate a text field with the login name, do something like:
    // Populate field with loginName
    getField("text1").value = getLoginName();
    Change "text1" with the actual name of the field in your form. You can place this code in a document-level JavaScript so it executes when the form is opened.
    Note that all of this code is the bare minimum, and you may want to expand it to check for errors, etc.

  • New Laptop, windows 8, can not get logged into iTunes.

    Hi
    I have a new laptop with Windows 8. I've installed iTunes but can not get logged onto my account or home sharing etc. I keep getting a pop up message
    "We could not complete your iTunes Store request"
    "The iTunes Store is temporarily unavailable. Please try again later"
    I've already unauthorized my old laptop to make way for the new one so it can't be that.
    My iTunes libary is stored on an external harddrive and even though I chnaged to location folder in the iTunes settings it's still not picking up any of that either.
    Any suggestions before I launch the whole lot out the window??
    Thanks

    Try the following:
    If you see a message that your computer can’t connect to the iTunes Store, click another item (Podcasts, for example) and click iTunes Store again. If it still doesn’t connect, make sure your Internet connection is working—open a web browser and visit a website. If your Internet connection is OK, there may be a problem with the iTunes Store. Try visiting the store again later.
    Make sure your computer’s date, time, and time zone are set correctly.
    Make sure your account information is accurate and that you don’t need to correct a problem with a previous purchase. Enter the iTunes Store, click your account name at the top of the iTunes Store window, and sign in to your account. To verify your account information, click Edit Account Info and Edit Payment Information.
    If you’re having trouble signing in to the store using your AOL account, your AOL account might not work with the iTunes Store in your country. Only U.S. and U.K. customers can sign in using their AOL accounts.
    Make sure the iTunes Store is available in your country. For more information, visit the iTunes website.

  • Get current logged in Windows user name

    Hi
    Is it possible to retrieve the current logged in Windows user name into a text field automatically?
    Thank you in advance for the help.

    Hi,
    This is a security issue and you will need a javascript file in the Acrobat folder. This will contain a trusted function allowing access to the login name.
    Here is a thread that looked at this:
    http://forums.adobe.com/message/2198084#2198084
    However read to the end, because if you are Reader Enabling the form (at least through Acrobat) then you may run into problems.
    Good luck,
    Niall

  • Can't get logged on.

    I can't get logged on. I installed Oracle 10.1.2.0.2 on a Windows machine (obtained from a Course Technology book).
    Issues while installing:
    1) The instructions for the software said I would need to get register and receive a number to use when installing the software. I have the number but never found a place to enter the number. Is this number stopping me from loggin on? If so can I uninstall and start over or enter the number in a file somewhere? I don't see Oracle in my program list in the add/remove programs in the control panel or any uninstall files.
    2) When ask to configure the network, I entered blanks thinking I could configure the network with the "Net Configuration Assistant".
    When I try to configure "Local Net Service Name Connection", I receive this error message:
    Connecting...ORA-12170: TNS:Connect timeout occurred
    The test did not succeed.
    Some of the information you provided may be incorrect.
    Click Back to review the information provided for net service name, or Change Login to change username.
    3) So I tryed to use the default -
    User Name: scott
    Password: tiger
    Host String: <my ip address>
    and
    User Name: scott
    Password: tiger
    Host String: <my service_name>
    (service name and IP obtained from my tnsnames.ora file:
    # tnsnames.ora Network Configuration File: C:\DevSuiteHome_1\network\admin\tnsnames.ora
    # Generated by Oracle configuration tools.
    EXTPROC_CONNECTION_DATA =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = xxx.xxx.x.xxx)(PORT = 1521))
    (CONNECT_DATA =
    (SERVICE_NAME = PLSExtProc)
    I've tried using EXTPROC_CONNECTION_DATA and I tried PLSExtProc as the service name,
    and received this error message in my log file:
    Fatal NI connect error 12170.
    VERSION INFORMATION:
         TNS for 32-bit Windows: Version 10.1.0.4.0 - Production
         Windows NT TCP/IP NT Protocol Adapter for 32-bit Windows: Version 10.1.0.4.0 - Production
    Time: 21-JAN-2008 21:36:31
    Tracing not turned on.
    Tns error struct:
    ns main err code: 12535
    TNS-12535: TNS:operation timed out
    ns secondary err code: 12560
    nt main err code: 505
    TNS-00505: Operation timed out
    nt secondary err code: 60
    nt OS err code: 0
    Client address: <unknown>
    4) The user name and password I am using is the one I set up when I registered the book.
    I've also tried using the registration number as the password.
    I've never used Oracle before. I've tried reading the program help links and Oracle document sites and can't figure this out. Please tell me what I need to do to get this to work.
    Thanks,
    Cindy

    For someone who is new to Oracle, the amount of documentation available can be rather intimidating. I would second Daniel in this respect -- download and install 10g release 2 instead of the version you have. That way you know you are getting an unadulterated copy of Oracle. If you are fairly comfortable installing software, check out the Quick Installation guide for Windows and the Oracle Database 2 Day DBA in the Oracle documentation. They will get you up and running with a usable instance as quickly as possible. Then break out the Concepts Guide. As Tom Kyte has said, the Concepts Guide is probably the least read of all of the Oracle documentation. It's not easy reading but it is definitely worth it. Anyone who has been around Oracle very long has either read it, is reading it, or wishes they had time to read it.
    As far as uninstalling it is concerned, the Oracle installation guide will help you there also. It gives you the proper procedure for uninstalling Oracle which is to use the Oracle installer to deinstall Oracle, not the Add/Remove Programs application in Control Panel. There are also some minor editing steps to make in the Windows registry but nothing too complex. I've done it many times and as long as you follow the steps in the guide, you can't go wrong.
    Tom

  • Applet not getting loaded in Windows Vista's Mozilla Browser

    Hi,
    When I open the URL http://www.operamini.com/demo/ , the applet in that site gets loaded from windows XP and linux, but not from windows vista, for the same firefox version. When I refer the Java console I get the message lissted below.
    c:   clear console window
    f:   finalize objects on finalization queue
    g:   garbage collect
    h:   display this help message
    l:   dump classloader list
    m:   print memory usage
    o:   trigger logging
    p:   reload proxy configuration
    q:   hide console
    r:   reload policy configuration
    s:   dump system and deployment properties
    t:   dump thread list
    v:   dump thread stack
    x:   clear classloader cache
    0-5: set trace level to <n>
    load: class org.microemu.applet.Main not found.
    java.lang.ClassNotFoundException: org.microemu.applet.Main
         at sun.applet.AppletClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadCode(Unknown Source)
         at sun.applet.AppletPanel.createApplet(Unknown Source)
         at sun.plugin.AppletViewer.createApplet(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)What can be the reason? what should be done to overcome this?Is it due to any version incompatibility of Java? I have no idea regarding this.
    Please help
    Rony

    there are other issues as well - in Safari:
    attempt to load resource [/v] using System ClasslLoader from a.Code(Unknown Source)
           me2.o.a(null:-1)
    attempt to load resource [/t] using System ClasslLoader from a.Code(Unknown Source)
           me2.o.a(null:-1)
    attempt to load resource [/t] using System ClasslLoader from a.Code(Unknown Source)
           me2.o.a(null:-1)
    attempt to load resource [/t] using System ClasslLoader from a.Code(Unknown Source)
           me2.o.a(null:-1)
    attempt to load resource [/v] using System ClasslLoader from a.Code(Unknown Source)
           me2.o.a(null:-1)
    attempt to load resource [/v] using System ClasslLoader from a.Code(Unknown Source)
           me2.o.a(null:-1)
    attempt to load resource [/s.png] using System ClasslLoader from a.Code(Unknown Source)
           me2.o.a(null:-1)
    attempt to load resource [/v] using System ClasslLoader from a.Code(Unknown Source)
           me2.o.a(null:-1)
    attempt to load resource [/v] using System ClasslLoader from a.Code(Unknown Source)
           me2.o.a(null:-1)
    attempt to load resource [/v] using System ClasslLoader from a.Code(Unknown Source)
           me2.o.a(null:-1)
    attempt to load resource [/t] using System ClasslLoader from a.Code(Unknown Source)
           me2.o.a(null:-1)
    attempt to load resource [/t] using System ClasslLoader from a.Code(Unknown Source)
           me2.o.a(null:-1)
    attempt to load resource [/t] using System ClasslLoader from a.Code(Unknown Source)
           me2.o.a(null:-1)
    attempt to load resource [/v] using System ClasslLoader from a.Code(Unknown Source)
           me2.o.a(null:-1)
    attempt to load resource [/v] using System ClasslLoader from a.Code(Unknown Source)
           me2.o.a(null:-1)
    attempt to load resource [/v] using System ClasslLoader from a.Code(Unknown Source)
           me2.o.a(null:-1)
    attempt to load resource [/v] using System ClasslLoader from a.Code(Unknown Source)
           me2.o.a(null:-1)
    attempt to load resource [/v] using System ClasslLoader from a.Code(Unknown Source)
           me2.o.a(null:-1)
    attempt to load resource [/v] using System ClasslLoader from a.Code(Unknown Source)
           me2.o.a(null:-1)
    attempt to load resource [/t] using System ClasslLoader from a.Code(Unknown Source)
           me2.o.a(null:-1)
    attempt to load resource [/t] using System ClasslLoader from a.Code(Unknown Source)
           me2.o.a(null:-1)
    attempt to load resource [/t] using System ClasslLoader from a.Code(Unknown Source)
           me2.o.a(null:-1)

  • CryptAcquireContext failing with ERROR_FILE_NOT_FOUND (2L) when user not logged on Windows 8.1

    I am having a hard time migrating a C++ CryptoAPI-based application that currently runs on Windows Server 2008 to Windows 8.1. The scenario is:
    This application is eventually triggered by WatchDog.exe, which in its turn is triggered when the computer is started by Windows' Task Scheduler.
    Task Scheduler uses the following rules to start the WatchDog.exe:
    A Administrator User Account;
    Run Whether user is logged on or not;
    UNCHECKED: Do not store password. The task will only have access to local resources;
    Run with Highest Privileges;
    Configure for Win 8.1;
    Triggered at system startup.
    The server sits there, nobody logged, until in a given scenario WatchDog.exe starts the application. Application log confirms that the owner of the process (GetUserName)
    is the very same user Task Scheduler used to trigger WatchDog.exe.
    It turns out that this application works fine in Windows Server 2008, but in windows 8.1 a call to CryptAcquireContext fails
    with return code ERROR_FILE_NOT_FOUND (2L). The odd thing is that the application will NOT fail if, when started, the user is physically logged
    on the machine, although it was not the user who started the application manually.
    I took a look at the documentation and
    found:
    "The profile of the user is not loaded and cannot be found. This happens when the application impersonates a user, for example, the IUSR_ComputerName account."
    I had never heard of impersonification, so I made a research and found the APIs LogonUser,ImpersonateLoggedOnUser and RevertToSelf.
    I then updated the application in this way:
    HANDLE hToken;
    if (! LogonUser(L"admin", L".", L"XXXXXXXX", LOGON32_LOGON_BATCH, LOGON32_PROVIDER_DEFAULT, &hToken))
    logger->log (_T("Error logging on."));
    else
    logger->log (PMLOG_LEVEL_TRACE, _T("Logged on."));
    if (! ImpersonateLoggedOnUser(hToken))
    logger->log (_T("Error impersonating."));
    else
    logger->log (_T("Impersonated."));
    err = XXXXXXXXX(); // calls function which will execute CryptAcquireContext
    if (! RevertToSelf())
    logger->log (_T("Error reverting."));
    else
    logger->log (_T("Reverted."));
    Excerpt with the call to CryptAcquireContext:
    // Get the handle to the default provider.
    if(! CryptAcquireContext(&hCryptProv, cryptContainerName, MS_ENHANCED_PROV, PROV_RSA_FULL, 0))
    DWORD e = GetLastError();
    _stprintf_s (logMsg, 1000, _T("Error %ld acquiring cryptographic provider."), e);
    cRSALogger->log (logMsg);
    return ERR_CCRYPT_NO_KEY_CONTAINER;
    cRSALogger->log (_T("Cryptographic provider acquired."));
    As the result, I got the log:
    [2015/01/08 20:53:25-TRACE] Logged on.
    [2015/01/08 20:53:25-TRACE] Impersonated.
    [2015/01/08 20:53:26-ERROR] Error 2 acquiring cryptographic provider.
    [2015/01/08 20:53:26-TRACE] Reverted.
    That seems to show that impersonation is working properly, but still I get Error 2 (ERROR_FILE_NOT_FOUND) on CryptAcquireContext.
    Summary:
    On Windows Server 2008, the very same application runs properly even without the calls to LogonUser/Impersonate/Revert.
    On Windows 8.1, the application, with or without the calls to LogonUser/Impersonate/Revert, will only work properly if the user is logged on (which
    is not acceptable).
    Any thoughts where I can run to in order to get this working on windows 8.1?
    Thank in advance,
    Dan

    There are a couple of issues.
    Based on the parameters being used in CryptAcquireContext().  A profile needs to be loaded and your app has to be running as the same user who created the keyset. (which is why it works when a user is logged on Windows 8.1) Also, impersonation
    does not load your user profile, you need to call LoadUserProfile().  It seems like you should be using a machine keyset for your scenario if you want to do this when nobody is logged on.
    Take a look at the following KB article for more information.
    https://support.microsoft.com/kb/238187?wa=wsignin1.0
    thanks
    Frank K [MSFT]

Maybe you are looking for

  • Multiple users in household, how do I simply sign out of an account and not delete the account?

    I just got an iPad and am still figuring out its quirks. One thing that is completely frustrating me is that I am being told that I have to delete accounts instead of simply being able to sign out? I don't get it? For instance the Gmail app lets you

  • I cannot get the file download using 1.6

    Hi, I am using HTMLDB v1.6 and I have followed the example to upload and download files. I was able to get the file upload working but I am getting the page cannot be found error message. I am using a package to implement the page download can I do t

  • View Desktop through S-Video

    I have a Power Mac G5 with an ATI Radeon 9800 video card... wondering how it may be possible to view the desktop with a S-Video output on the card. Also have Mac 10.4.11 Tiger. Thanks.

  • After disabling failover can't configure interfaces

    I had a pair of ASA 5510s in failover and needed to move one so I disabled failover. Now I can't configure any of the interfaces. When I put an IP on an interface and then show interface ip brief, it shows as unassigned. What else do I have to do aft

  • 10.1 AC Remediation View Says No Data Found while Business View Shows Plenty

    We are upgrading to AC 10.1 from 10.0. We configured gateway connection and I am using Chrome browser. Not sure why user risk analysis in remediation view comes back "No Data Found" while in business view there are plenty of risks. Any ideas? -Thanks