Discussion:
Command scripts
(too old to reply)
TcsSomewhere
2009-07-14 13:56:27 UTC
Permalink
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
Richard Mueller [MVP]
2009-07-14 15:24:40 UTC
Permalink
Post by TcsSomewhere
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
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 Directory Services
Hilltop Lab - http://www.rlmueller.net
--
Pegasus [MVP]
2009-07-14 16:09:15 UTC
Permalink
Post by TcsSomewhere
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
Perhaps something as simple as the "ver" console command will meet your
requirements.
Al Dunbar
2009-07-14 23:44:28 UTC
Permalink
Post by Pegasus [MVP]
Post by TcsSomewhere
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
Perhaps something as simple as the "ver" console command will meet your
requirements.
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
Pegasus [MVP]
2009-07-15 08:23:53 UTC
Permalink
Post by Al Dunbar
Post by Pegasus [MVP]
Post by TcsSomewhere
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
Perhaps something as simple as the "ver" console command will meet your
requirements.
Perhaps a more succinct result can be had by extracting the "computer
for /f "tokens=3" %F in ('net accounts ^| find /i "computer role:"') do
(set role=%F)
/Al
Nice one - I had forgotten about this none!
F. Dunoyer
2009-07-15 11:59:43 UTC
Permalink
Post by Al Dunbar
Post by Pegasus [MVP]
Post by TcsSomewhere
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
Perhaps something as simple as the "ver" console command will meet your
requirements.
Perhaps a more succinct result can be had by extracting the "computer role"
for /f "tokens=3" %F in ('net accounts ^| find /i "computer role:"') do (set
role=%F)
/Al
Nice ! but be careful : a DC is not a "SERVER"
--
François Dunoyer
Astuces pour Windows : http://fds.mvps.org/ta/
Site perso : http://www.fdunoyer.net
Blog : http://fds34.spaces.live.com/
Al Dunbar
2009-07-15 23:28:17 UTC
Permalink
Post by F. Dunoyer
Post by Al Dunbar
Post by Pegasus [MVP]
Post by TcsSomewhere
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
Perhaps something as simple as the "ver" console command will meet your
requirements.
Perhaps a more succinct result can be had by extracting the "computer
for /f "tokens=3" %F in ('net accounts ^| find /i "computer role:"') do
(set role=%F)
/Al
Nice ! but be careful : a DC is not a "SERVER"
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
F. Dunoyer
2009-07-16 18:25:41 UTC
Permalink
Post by Al Dunbar
Post by F. Dunoyer
Post by Al Dunbar
Post by Pegasus [MVP]
Post by TcsSomewhere
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
Perhaps something as simple as the "ver" console command will meet your
requirements.
Perhaps a more succinct result can be had by extracting the "computer
for /f "tokens=3" %F in ('net accounts ^| find /i "computer role:"') do
(set role=%F)
/Al
Nice ! but be careful : a DC is not a "SERVER"
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.
I Think that the test of "Workstation" is a better way
On my own server (French 2003 entreprise DC) the value is : "PRINCIPAL"
(primary)
--
François Dunoyer
Quelques liens pour Windows : http://fds.mvps.org/AdressesInternets.htm
Site perso : http://fds.mvps.org
Blog : http://fds34.spaces.live.com/
Al Dunbar
2009-07-16 23:31:09 UTC
Permalink
Post by F. Dunoyer
Post by Al Dunbar
Post by F. Dunoyer
Post by Al Dunbar
Post by Pegasus [MVP]
Post by TcsSomewhere
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
Perhaps something as simple as the "ver" console command will meet
your requirements.
Perhaps a more succinct result can be had by extracting the "computer
for /f "tokens=3" %F in ('net accounts ^| find /i "computer role:"') do
(set role=%F)
/Al
Nice ! but be careful : a DC is not a "SERVER"
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.
I Think that the test of "Workstation" is a better way
On my own server (French 2003 entreprise DC) the value is : "PRINCIPAL"
(primary)
Hmmm, I hadn't even thought of the obvious globalization issues....

/Al
Mark D. MacLachlan
2009-07-15 13:52:55 UTC
Permalink
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
[/code]
Bill Stewart
2009-07-17 17:32:57 UTC
Permalink
Post by TcsSomewhere
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?
Try my OSTest.exe utility (http://www.westmesatech.com/wast.html).

ostest -r Server
if errorlevel 1 goto :SERVER
--
Bill Stewart
Paul Yhonquea
2009-08-10 00:29:18 UTC
Permalink
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
Post by TcsSomewhere
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
Loading...