Im working on migrating or script from a batch file to a vbs file. This
script is going to map drives and log certain infomation about the PC
as well as a few other things. What I need to do is have it map the
drives and after that deturmin is its running on a server or
workstation. If its running on a server, then I want it to exit the
script. I though using the version numbers would work till I found out
the workstation and server have the same numbers in 2k. In the batch
file we have a app from a resource kit called gettype.exe which
deturmins the OS and role of that machine and raises a error level that
defines the machines role, but I am unsure how to tap into the
errorlevels in vbs. Im not set on this method but that is the only
option i have right now. Anyone know either how to get the errorlevel
from the file or another way of getting the role?

Thanks in advance

Re: Identifying if login script is running on a server or workstation. by Richard

Richard
Fri Oct 13 10:50:27 CDT 2006


<whosyodaddy1019@hotmail.com> wrote in message
news:1160752747.571496.310380@e3g2000cwe.googlegroups.com...
> Im working on migrating or script from a batch file to a vbs file. This
> script is going to map drives and log certain infomation about the PC
> as well as a few other things. What I need to do is have it map the
> drives and after that deturmin is its running on a server or
> workstation. If its running on a server, then I want it to exit the
> script. I though using the version numbers would work till I found out
> the workstation and server have the same numbers in 2k. In the batch
> file we have a app from a resource kit called gettype.exe which
> deturmins the OS and role of that machine and raises a error level that
> defines the machines role, but I am unsure how to tap into the
> errorlevels in vbs. Im not set on this method but that is the only
> option i have right now. Anyone know either how to get the errorlevel
> from the file or another way of getting the role?

You could run the program with the Run method of the wshShell object using
syntax similar to:

intResponse = objShell.Run("c:\MyFolder\MyProgram", 0, True)

The parameter 0 means to run the program hidden, True means to wait for the
program to complete before continuing. Any return code is assigned to
intResponse. However, if the program spawns another process, this will not
wait for the spawned process to complete. Also, unless you copy the program
to the client, you must map a drive and use a UNC path.

A better solution is to adapt the following code, which probably duplicates
the gettype utility. WMI is built into any computer with W2k or above, but
must be installed on Win9x and NT clients. Instead of echoing the machine
role, as below, you would exit if objComputer.DomainRole is 2 or above.
================
Option Explicit

Dim objNetwork, strComputer, objWMIService, colSettings
Dim objComputer, strRole

Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" _
& strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery _
("SELECT * FROM Win32_ComputerSystem")
For Each objComputer In colSettings
Select Case objComputer.DomainRole
Case 0
strRole = "Standalone Workstation"
Case 1
strRole = "Member Workstation"
Case 2
strRole = "Standalone Server"
Case 3
strRole = "Member Server"
Case 4
strRole = "Backup Domain Controller"
Case 5
strRole = "Primary Domain Controller"
Case Else
strRole = "Unknown"
End Select
Next

Wscript.Echo strRole
============
WMI can also determine the OS, but it sounds like you don't need that.
Another method would be to bind to the computer object and check the
operatingSystem property. The string "Server" will be in this value if it is
a server. However, this requires NT or above.

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net