Command scripts

Discussion in 'Scripting' started by Tcs, Jul 14, 2009.

  1. Tcs

    Tcs Guest

    I'm dealing with logon scripts, and am trying to keep this simple, if
    possible.

    I'd like to be able to tell if the machine I'm logging into is a
    server, vs a client. There doesn't seem to be any variable available
    that designates such a thing. I suppose I could test for a particular
    server program, but I'm not sure what will always be there, and isn't
    dependent upon what components have been installed.

    Anyone have any suggestions/thoughts/ideas?

    Thanks in advance,

    Tom
     
    Tcs, Jul 14, 2009
    #1
    1. Advertisements

  2. You can use DomainRole property of the Win32_ComputerSystem class of WMI.
    See this link from the Script Center:

    http://www.microsoft.com/technet/scriptcenter/guide/sas_srv_yzhs.mspx
     
    Richard Mueller [MVP], Jul 14, 2009
    #2
    1. Advertisements

  3. Perhaps something as simple as the "ver" console command will meet your
    requirements.
     
    Pegasus [MVP], Jul 14, 2009
    #3
  4. Tcs

    Al Dunbar Guest

    Perhaps a more succinct result can be had by extracting the "computer role"
    value displayed by the "net accounts" command, i.e.:

    for /f "tokens=3" %F in ('net accounts ^| find /i "computer role:"') do (set
    role=%F)

    /Al
     
    Al Dunbar, Jul 15, 2009
    #4
  5. Nice one - I had forgotten about this none!
     
    Pegasus [MVP], Jul 15, 2009
    #5
  6. Tcs

    F. Dunoyer Guest

    Al Dunbar a écrit :
    Nice ! but be careful : a DC is not a "SERVER"
     
    F. Dunoyer, Jul 15, 2009
    #6
  7. Give this a try.

    Code:
    Dim wshShell, wshNetwork
    Dim strComputerName, objComputer
    
    ' Create Global Objects
    Set wshNetwork = CreateObject("WScript.Network")
    
    ' Initialize Variables
    strComputerName = wshNetwork.ComputerName
    
    strDN = GetDN(strComputerName)
    
    Set objComputer = GetObject("LDAP://" & strDN)
    If Instr(objComputer.operatingSystem,"Server") Then
    WScript.Echo "Server Found"
    Else
    WScript.Echo "Not A Server"
    End If
    
    
    Function GetDN(strComputerName)
    ' Use the NameTranslate object to convert the NT name of the computer to
    ' the Distinguished name required for the LDAP provider. Computer names
    ' must end with "$". Returns comma delimited string to calling code.
    ' Name translate thanks to Richard Meuller
    
    Dim objTrans, objDomain
    ' Constants for the NameTranslate object.
    Const ADS_NAME_INITTYPE_GC = 3
    Const ADS_NAME_TYPE_NT4 = 3
    Const ADS_NAME_TYPE_1779 = 1
    
    Set objTrans = CreateObject("NameTranslate")
    Set objDomain = getObject("LDAP://rootDse")
    objTrans.Init ADS_NAME_INITTYPE_GC, ""
    objTrans.Set ADS_NAME_TYPE_NT4, wshNetwork.UserDomain & "\" _
    & strComputerName & "$"
    GetDN = objTrans.Get(ADS_NAME_TYPE_1779)
    'Set DN to upper Case
    GetDN = UCase(GetDN)
    End Function
    
     
    Mark D. MacLachlan, Jul 15, 2009
    #7
  8. Tcs

    Al Dunbar Guest

    I'm not sure if you mean that a DC returns a value of "DC", not "SERVER", or
    if you have non-server O/S systems performing the DC role. Like the "VER"
    method, this gives you information that differentiates computers in some
    way. If not in exactly the way one might expect, it still might allow the
    desired information to be deduced.

    I have not tried this on computers having every possible combination of
    roles. In our environment it is safe to assume that anything not reporting
    itself as "WORKSTATION" would be some sort of server. Some people have also
    assumed that if the first character in the computername is "S", then it is a
    server, as that was part of our original naming convention. Of course, code
    based on that assumption is broken now...

    Of course, it all boils down to what differentiates "servers" from "clients"
    in the OP's environment.


    /Al
     
    Al Dunbar, Jul 16, 2009
    #8
  9. Tcs

    F. Dunoyer Guest

    Al Dunbar a écrit :
    I Think that the test of "Workstation" is a better way
    On my own server (French 2003 entreprise DC) the value is : "PRINCIPAL"
    (primary)
     
    F. Dunoyer, Jul 16, 2009
    #9
  10. Tcs

    Al Dunbar Guest

    Hmmm, I hadn't even thought of the obvious globalization issues....

    /Al
     
    Al Dunbar, Jul 17, 2009
    #10
  11. Tcs

    Bill Stewart Guest

    Try my OSTest.exe utility (http://www.westmesatech.com/wast.html).

    ostest -r Server
    if errorlevel 1 goto :SERVER
     
    Bill Stewart, Jul 17, 2009
    #11
  12. I know I am a bit late on this thread, but I do know from experience, WMI is
    the way to go (DomainRole property of Win32_ComputerSystem) - kudos to Rick
    Mueller. Using the "NET ACCOUNTS" method (in the US versions) will return
    "SERVER" for non-DC servers, "WORKSTATION" for clients, "PRIMARY" for the
    PDC emulator, and "BACKUP" for all other DCs.



    Paul Yhonquea
     
    Paul Yhonquea, Aug 10, 2009
    #12
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.