How can a script or EXE detect if it's running on a server?


  1. Posts : 16
    Windows 10
       #1

    How can a script or EXE detect if it's running on a server?


    What call or query can I make to determine whether the PC my software is running on is a single-user PC or a server? For example, is there a registry entry to check?

    The utility systeminfo.exe can return a comprehensive summary with lines for "OS Name:" and "OS Configuration:". But what I'd like is something far simpler: IsServer=Yes/No.

    If there is no single parameter to check, then is "OS Configuration" a reliable indication? If so, what does a server version have on that line. (I don't have access to a server to test this ... and my development PC shows Standalone Workstation.)

    Thanks in advance for any help.
      My Computer


  2. Posts : 668
    Win 10 pro
       #2

    Hi contours,
    would you please try to describe what your concern/problem is? It is not clear what your asking.
    it seems you are making some assumptions that maybe are based on wrong base.
    i'll try to explain some basic takes I have that hopefully will help you a bit.

    There is (very generally speaking, an oversemplifing) no such thing as a server or a single pc, the underlying OS can expose services that other user can access remotely.
    If you share a folder with your win 10 home pc you're exposing a service and that pc can be viewed as a "file server" if named folder is used for data of a project.

    HTH.
      My Computer


  3. Posts : 83
    Windows 10 Pro
       #3

    There are a few ways you can go:

    You could call
    Code:
    systeminfo | find "OS Name"
    via cmd

    Or
    Code:
    wmic os get name /format:list
    would also get the info as well.

    Fully working script:

    Code:
    @echo off
    setlocal
    
    for /f "usebackq tokens=1,2 delims==|" %%I in (`wmic os get name^,version /format:list`) do 2>NUL set "%%I=%%J"
    
    echo OS Name: %name%
    echo OS Version: %version%
      My Computer


  4. Posts : 83
    Windows 10 Pro
       #4

    roy111 said:
    Hi contours,
    would you please try to describe what your concern/problem is? It is not clear what your asking.
    it seems you are making some assumptions that maybe are based on wrong base.
    i'll try to explain some basic takes I have that hopefully will help you a bit.

    There is (very generally speaking, an oversemplifing) no such thing as a server or a single pc, the underlying OS can expose services that other user can access remotely.
    If you share a folder with your win 10 home pc you're exposing a service and that pc can be viewed as a "file server" if named folder is used for data of a project.

    HTH.
    He/She wants to detect if a software that he written is running on a home or server OS. Like what some antivirus software do: Homeversion of antivirus software won't run on a server OS because of the checks that been put in place.
      My Computer


  5. Posts : 668
    Win 10 pro
       #5

    I see, sorry don't know that.
      My Computer


  6. Posts : 16
    Windows 10
    Thread Starter
       #6

    @Danielx64, thanks for those methods.

    what does a server version have on that line?
    I've seen examples that show "Enterprise" in the OS name. Do you know if that's always the case for a server? (Again, I can't test this at the moment, but I'd like to be able to provide for it.)
      My Computer


  7. Posts : 268
    Windows 10 Pro x64 v22H2
       #7

    I use the Microsoft Deployment Toolkit (MDT) which can distinguish just what you want. MDT creates variables: IsServer, IsDesktop, IsLaptop where only one is True after the query.

    I googled and found MDT sets IsServer based on Win32_SystemEnclosure ChassisType. I don't know the underlying wmic command(s) needed. Perhaps someone else can help with that
      My Computer


  8. Posts : 83
    Windows 10 Pro
       #8

    contours said:
    @Danielx64, thanks for those methods.



    I've seen examples that show "Enterprise" in the OS name. Do you know if that's always the case for a server? (Again, I can't test this at the moment, but I'd like to be able to provide for it.)
    There is such a thing called"windows server 2012 enterprise server" and " windows 8 enterprise" for example.

    So yes both desktop and server OS can be enterprise.
      My Computer


  9. Posts : 1,255
    Windows 10 Pro
       #9

    There are a variety of ways a program can determine if it is running on a server. Which method is best depends greatly on your programming environment, such as which programming language you are using. A script would be more limited. The official native win32 method would be to call the getVersionEx function. See the MSDN website for how to use it. Your programming language may offer something appropriate. There is also a registry entry at "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion" in the value "InstallationType". It will have the string value "Client" for a client OS. The problem with using the registry is that many entries are not officially documented and could change in a later version.
      My Computer


  10. Posts : 16
    Windows 10
    Thread Starter
       #10

    @LMiller7, that's a good suggestion about the InstallationType key. I confirmed on both my Win7 desktop and my Win10 laptop that it contains "Client". Unless some better method comes up, I think it will meet my needs. I'll make note of your point about documentation, but I would hope that something as fundamental as this key would be stable over the years.

    Thanks for your help.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 07:56.
Find Us




Windows 10 Forums