none
Shell functions in Windows Server Core/Nano RRS feed

  • Question

  • Hi all,

    we are attempting to build some of our existing projects so they can run on Windows Server Core and Nano. We've added WINAPI_FAMILY=WINAPI_FAMILY_SERVER to the pre-processor definitions for the relevant projects. We are getting quite a few compiler errors. A lot of the errors are related to file/directory type functions that are found in the SDK shell libraries. Functions such as SHCreateDirectroyEx, PathIsRoot, GetShortPathName, SHFileOperation, etc.

    Why are these functions only available for the desktop ?

    Or is setting WINAPI_FAMILY=WINAPI_FAMILY_SERVER the wrong thing to do to compile for Windows Server Core/Nano ?

    Anthony


    • Edited by Tony461 Friday, August 16, 2019 5:43 AM
    Friday, August 16, 2019 5:39 AM

All replies

  • we are attempting to build some of our existing projects so they can run on Windows Server Core and Nano. We've addedWINAPI_FAMILY=WINAPI_FAMILY_SERVER to the pre-processor definitions for the relevant projects. We are getting quite a few compiler errors. A lot of the errors are related to file/directory type functions that are found in the SDK shell libraries. Functions such as SHCreateDirectroyEx, PathIsRoot, GetShortPathName, SHFileOperation, etc.

    According to https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ee391646%28v%3dvs.85%29, some of those
    functions should be available in server core, though SHFileOperation isn't listed.

    Or is setting WINAPI_FAMILY=WINAPI_FAMILY_SERVER the wrong thing to do to compile for Windows Server Core/Nano ?

    Possibly! Perhaps that value is intended to identify function that are only available on server variants (I'm guessing).

    Dave

    Friday, August 16, 2019 8:57 AM
  • The Developing Native Apps on Nano Server has a project template link that has the project configured correctly for running on Nano Server.

    The things that I noticed about it are:

    1) It has WINAPI_FAMILY defined as WINAPI_FAMILY_SERVER in the project's pre-processor definitions.

    <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;WINAPI_FAMILY=WINAPI_FAMILY_SERVER;%(PreprocessorDefinitions)</PreprocessorDefinitions>

    This was copied from the project (.vcxproj) file.

    2) It is set to use the onecore API set library.

    <AdditionalDependencies>onecore.lib;vcruntimed.lib;ucrtd.lib;msvcrtd.lib</AdditionalDependencies>

    Again, copied from the project file.

    3) It is set to use the Unicode character set.

    <CharacterSet>Unicode</CharacterSet>

    This to me says 2 things.

    1) The functions available in Nano Server (not Core) are denoted by WINAPI_FAMILY_SERVER.

    2) You should set your project to use the Unicode character set to use the Unicode version of these functions.

    Out of the functions that you listed, GetShortPathName is the weird one since it isn't a shell function. But according to the fileapi header:

    #pragma region Desktop Family or OneCore Family
    #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM)
    
    WINBASEAPI
    _Success_(return != 0 && return < cchBuffer)
    DWORD
    WINAPI
    GetShortPathNameW(
        _In_ LPCWSTR lpszLongPath,
        _Out_writes_to_opt_(cchBuffer,return + 1) LPWSTR lpszShortPath,
        _In_ DWORD cchBuffer
        );
    
    
    #ifdef UNICODE
    #define GetShortPathName  GetShortPathNameW
    #endif
    
    #endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM) */
    #pragma endregion

    So GetShortPathNameW is available (server includes the system partition).

    So it seems like you can't treat Core and Nano as the same thing.


    This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    Friday, August 16, 2019 6:43 PM
  • Hi Darran,

    Thanks for the response.

    1) The functions available in Nano Server (not Core) are denoted by WINAPI_FAMILY_SERVER.

    2) You should set your project to use the Unicode character set to use the Unicode version of these functions.

    We are already doing both of these.

    The confusion over GetShortPathName() is because we have a common source file that explicitly calls the ANSI and Unicode versions. So the ANSI version was failing. 

    Regards,

    Anthony.

     


    • Edited by Tony461 Monday, August 19, 2019 7:09 AM
    Monday, August 19, 2019 6:48 AM
  • Hello,

    Do you resolve the issue? If you resolve the issue, could you please mark the helpful as answer. it will be beneficial to other community. If not, please feel free to contact us.

    Best Regards,

    Suarez Zhou

    Tuesday, August 20, 2019 6:47 AM
  • Hi Suarez,

    no, the issue is not resolved.

    Based on the responses I received, I am doing the right thing (at least for Nano) which is to set WINAPI_FAMILY=WINAPI_FAMILY_SERVER and to set the project as Unicode.

    So the question still remains, why are file system type functions such as SHCreateDirectroyEx, PathIsRoot, SHFileOperation not available for Server Nano ?

    Another strange one is MoveFileEx. It can be used for a WINAPI_FAMILY_SERVER compile (WINAPI_PARTITION_SYSTEM) but the #defines for the dwFlags parameter are not available (they're only available for the WINAPI_PARTITION_APP family).

    • Edited by Tony461 Wednesday, August 21, 2019 1:18 AM
    Tuesday, August 20, 2019 10:33 PM
  • This is because these are file operation functions that work in the context of the shell. Since Nano is meant to be headless, it doesn't have local logon capability or UI capability. If there is no UI capability, then that means the shell and related functions go away too. I wouldn't be surprised if everything that has a reliance on Win32k/Win32u has been totally removed from Nano. (This means no User or GDI).

    SHFileOperation for example needs to take a handle to a dialog, but none of the User or GDI functions are available in Nano so this wouldn't work. SHCreateDirectoryEx, besides being deprecated, also takes an optional window handle.

    It isn't as if there is no way to do these functions either, CreateDirectoryW, MoveFile and CopyFile exist and and PathIsRoot can easily be replaced through functions like GetVolumePathName.

    I would imagine that since the shell functionality has so many duplicated functions and so much reliance on UI and OLE, they would be prime candidates for removal.


    This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.


    • Edited by Darran Rowe Wednesday, August 21, 2019 1:50 AM
    Wednesday, August 21, 2019 1:50 AM
  • Hi Darran,

    This got put on the backburner while another task was being completed. 

    Looking at the issue afresh. We're now looking at targeting Server Core rather than Server Nano. WINAPI_FAMILY=WINAPI_FAMILY_SERVER seems to be specific for Server Nano. What preprocessor setting should we use to target Server Core? 

    Anthony


    • Edited by Tony461 Monday, October 28, 2019 8:57 PM
    Monday, October 28, 2019 6:45 AM
  • I can't really find anything about this, and since the API surface for core is larger than what is exposed by WINAPI_FAMILY_SERVER then it seems like you should just not define anything or use WINAPI_FAMILY_DESKTOP and then test your application to see if it works.

    There doesn't seem to be a definitive list on what is actually in Windows Server Core, and the lists of supported functions also state that there may be more functions available which work.


    This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    Wednesday, October 30, 2019 6:22 AM