none
Whats the Temp path used by windows service when ran under system account RRS feed

  • Question

  • I m running my Windows service under system account on the Vista 32 bit machine.
    I am facing the issue related to the temp path.
    It is using a temp path as :"C:\Windows\system32\config\systemprofile\AppData\Local\Temp"
    While the TEMP and TMP environment variables are defined as
    C:\Windows\TEMP.

    How can I point the TEMP path of Windows service to the one which is defined in the TEMP environment variable?

    In case of Windows 2000/2003/XP service (under SYSTEM running under)uses the TEMP path defined in env variable.<!-- google_ad_section_end -->
    Thursday, December 24, 2009 11:11 AM

Answers

  • Hello Shivdkte,

    Welcome to MSDN forum.

    I perform a test using the GetTempPath function, but I cannot reproduce the issue. Here is the code.

    DWORD dwBufSize=BUFSIZE;
    char lpPathBuffer[BUFSIZE];

    GetTempPathA(dwBufSize, lpPathBuffer);
    printf("%s\n",lpPathBuffer);

    It prints out the C:\Windows\TEMP\ on my box.

    As said in the documentation

    <Quote>
    The GetTempPath function checks for the existence of environment variables in the following order and uses the first path found:

    1. The path specified by the TMP environment variable. 
    2. The path specified by the TEMP environment variable. 
    3. The path specified by the USERPROFILE environment variable. 
    4. The Windows directory. 
    </Quote>

    More info

    Thanks,
    Rong-Chun Zhang

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Proposed as answer by Fisnik Hasani Tuesday, December 29, 2009 11:29 AM
    • Marked as answer by Rong-Chun Zhang Monday, January 4, 2010 10:21 AM
    Friday, December 25, 2009 11:52 AM

All replies

  • Hi,

    hmm? Not sure, when typing %TEMP% in the Windows Run Dialog program,
    I come to this path: C:\Users\User~1\AppData\Local\Temp.

    Do you have any configuration file for the Windows Service?

    Because, then you can modify that, if this thread is related to Programming (e.g. making a C#/VB application/Service),
    then please provide more information.

    Merry Christmas...

    Have a nice day...

    Best regards,
    Fisnik
    Coder24.com
    Friday, December 25, 2009 11:49 AM
  • Hello Shivdkte,

    Welcome to MSDN forum.

    I perform a test using the GetTempPath function, but I cannot reproduce the issue. Here is the code.

    DWORD dwBufSize=BUFSIZE;
    char lpPathBuffer[BUFSIZE];

    GetTempPathA(dwBufSize, lpPathBuffer);
    printf("%s\n",lpPathBuffer);

    It prints out the C:\Windows\TEMP\ on my box.

    As said in the documentation

    <Quote>
    The GetTempPath function checks for the existence of environment variables in the following order and uses the first path found:

    1. The path specified by the TMP environment variable. 
    2. The path specified by the TEMP environment variable. 
    3. The path specified by the USERPROFILE environment variable. 
    4. The Windows directory. 
    </Quote>

    More info

    Thanks,
    Rong-Chun Zhang

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Proposed as answer by Fisnik Hasani Tuesday, December 29, 2009 11:29 AM
    • Marked as answer by Rong-Chun Zhang Monday, January 4, 2010 10:21 AM
    Friday, December 25, 2009 11:52 AM
  • My application is running as a windows service under the SYSTEM ACCOUNT,When i tried to call the GetTempPathA () it gives the temp path as "C:\Windows\system32\config\systemprofile\AppData\Local\Temp"

    When i run servive in the user mode (with specific user name) it returned the TEMP path as "C:\Windows\TEMP".

    Why does the vista Windows service uses ""C:\Windows\system32\config\systemprofile\AppData\Local\Temp"  as temp path when ran under system user.

    if i ran my application/code  outside the service(i.e. in the UI mode) GetTempPathA () would return "C:\Windows\TEMP" as temp path with SYSTEM USER.

    Monday, December 28, 2009 12:36 PM
  • My code is user is executing the windoes service ,and the applications failes with error as below:
    Error Information: Error Code: -2147024893, Error description: Could not find a part of the path 'C:\Windows\system32\config\systemprofile\AppData\Local\Temp\tdjtwm5j.tmp'.   Error Information: Error Code: -2147024893, Error description: Could not find a part of the path 'C:\Windows\system32\config\systemprofile\AppData\Local\Temp\nobk55wd.tmp'.

    This happens only when run the Windows service under SYSTEM mode,in user mode it works fine,because it uses the some other path which already exists.
    which is C:\Users\User~1\AppData\Local\Temp(Same as defined in USER env variable)

    Under the SYSTEM mode it should user the system variable's TEMP variable path which is  C:\Windows\TEMP .But it is using the "'C:\Windows\system32\config\systemprofile\AppData\Local\Temp\"


    Monday, December 28, 2009 1:00 PM
  • Hello

    I have TMP and TEMP set to "C:\Windows\Temp" for the System, and the above code works for me.

    Thanks,
    Rong-Chun Zhang

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, December 29, 2009 10:58 AM
  • Hi shivdkte:

    How is the situation on your side?
    Is this thread solved or NOT?

    Please tell me.

    Because, I think that Rong-Chun Zhang has already answered your question.

    Have a nice day...

    Best regards,
    Fisnik
    Coder24.com
    Thursday, December 31, 2009 9:45 AM