How to tell if DLL on Desktop or Server?

I have a DLL that is going to be deployed both on Servers and Desktops.  Instead of creating two seperate DLLs for desktop and server we want to have one dll, but the functionality is different based on if the dll is being ran on a desktop vs a server.  So how can we do a programmatic check to see if the DLL is on a desktop or server?

Thanks,

Leo
LVL 8
Leo EikelmanDirector, IT and Business DevelopmentAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vinnyd79Commented:
There is a registry value you can check. Check out this link:

http://support.microsoft.com/kb/q152078/
Leo EikelmanDirector, IT and Business DevelopmentAuthor Commented:
So this checks if a Windows NT computer is a workstation, server, etc...

would I be able to check this value on Windows 2000 server and Windows XP desktop?

Could you provide a code example?

Thanks,

Leo
vinnyd79Commented:
Try adding this to a module:


Option Explicit
Public Const REG_SZ As Long = 1
Public Const REG_DWORD As Long = 4
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const ERROR_NONE = 0
Public Const ERROR_BADDB = 1
Public Const ERROR_BADKEY = 2
Public Const ERROR_CANTOPEN = 3
Public Const ERROR_CANTREAD = 4
Public Const ERROR_CANTWRITE = 5
Public Const ERROR_OUTOFMEMORY = 6
Public Const ERROR_ARENA_TRASHED = 7
Public Const ERROR_ACCESS_DENIED = 8
Public Const ERROR_INVALID_PARAMETERS = 87
Public Const ERROR_NO_MORE_ITEMS = 259
Public Const KEY_QUERY_VALUE = &H1

Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias _
   "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
   ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions _
   As Long, ByVal samDesired As Long, ByVal lpSecurityAttributes _
   As Long, phkResult As Long, lpdwDisposition As Long) As Long
Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias _
   "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
   ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Declare Function RegQueryValueExString Lib "advapi32.dll" Alias _
   "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
   String, ByVal lpReserved As Long, lpType As Long, ByVal lpData _
   As String, lpcbData As Long) As Long
   Declare Function RegQueryValueExLong Lib "advapi32.dll" Alias _
   "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
   String, ByVal lpReserved As Long, lpType As Long, lpData As _
   Long, lpcbData As Long) As Long
   Declare Function RegQueryValueExNULL Lib "advapi32.dll" Alias _
   "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
   String, ByVal lpReserved As Long, lpType As Long, ByVal lpData _
   As Long, lpcbData As Long) As Long

Public ProdType As String

Public Function QueryValue(sKeyName As String, sValueName As String)
       Dim lRetVal As Long         'result of the API functions
       Dim hKey As Long         'handle of opened key
       Dim vValue As Variant      'setting of queried value

       lRetVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE, sKeyName, 0, _
   KEY_QUERY_VALUE, hKey)
       lRetVal = QueryValueEx(hKey, sValueName, vValue)
       ProdType = vValue
       RegCloseKey (hKey)
   End Function

Public Function QueryValueEx(ByVal lhKey As Long, ByVal szValueName As _
   String, vValue As Variant) As Long
Dim cch As Long, lrc As Long, lType As Long, lValue As Long
Dim sValue As String

On Error GoTo QueryValueExError

       ' Determine the size and type of data to be read
       lrc = RegQueryValueExNULL(lhKey, szValueName, 0&, lType, 0&, cch)
       If lrc <> ERROR_NONE Then Error 5

       Select Case lType
           ' For strings
           Case REG_SZ:
               sValue = String(cch, 0)

   lrc = RegQueryValueExString(lhKey, szValueName, 0&, lType, _
   sValue, cch)
               If lrc = ERROR_NONE Then
                   vValue = Left$(sValue, cch - 1)
               Else
                   vValue = Empty
               End If
           ' For DWORDS
           Case REG_DWORD:
   lrc = RegQueryValueExLong(lhKey, szValueName, 0&, lType, _
   lValue, cch)
               If lrc = ERROR_NONE Then vValue = lValue
           Case Else
               'all other data types not supported
               lrc = -1
       End Select

QueryValueExExit:
       QueryValueEx = lrc
       Exit Function

QueryValueExError:
       Resume QueryValueExExit
   End Function

Public Function IsServer() As Boolean
QueryValue "SYSTEM\CurrentControlSet\Control\ProductOptions", "ProductType"
Select Case ProdType
    Case "WinNT"
        IsServer = False
    Case "LanmanNT", "ServerNT"
        IsServer = True
End Select
End Function




Then try calling it like this:

Private Sub Command1_Click()
MsgBox IsServer
End Sub

If it is a server it will return true otherwise it should return false.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Leo EikelmanDirector, IT and Business DevelopmentAuthor Commented:
I will give that a shot and get back to you

Leo
Leo EikelmanDirector, IT and Business DevelopmentAuthor Commented:
Is there any way of doing this without using the registry?

I know of the function GetVersionExA in kernel32 but that only returns Major Version, Minor Version, Build Number, etc... is there one that returns if it's a server or desktop?

Just some simple api


Leo
vinnyd79Commented:
The only other way I can think of at the moment is to check the running services to see if the server service is running.

http://vbnet.mvps.org/index.html?code/network/enumservices.htm

Leo EikelmanDirector, IT and Business DevelopmentAuthor Commented:
that would not work because all of the computers are on a network so the server service is running on all of them.

I thought there would be some simple API from windows to figure this out.

any more suggestions?

Leo
vinnyd79Commented:
vinnyd79Commented:
Actually it's the osversioninfoex structure you need to use with GetVersionExA API.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Leo EikelmanDirector, IT and Business DevelopmentAuthor Commented:
Thank you vinny, I got it working using the osversioninfoex structure and the GetVersionExA API.

: )
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.