DoesServiceExist – Detect if service exist on remote host

DoesServiceExist – Detect if service exist on remote host

This script can be used to detect whether or not a service exist on a remote host.
I originally created it to determine if WDS is installed (ServiceName = WDSServer)

Usage: CScript.exe //nologo DoesServiceExist.vbs /Computer:HOSTNAME /ServiceName:SERVICENAME

Example: CScript.exe //nologo DoesServiceExist.vbs /Computer:CompanyServer01 /ServiceName:WDSServer
[sourcecode language=”plain”]
Option Explicit

On Error Resume Next

Dim strComputer
Dim strServiceName
Dim objComputer
Dim objService

strComputer = Wscript.Arguments.Named("Computer")
strServiceName = Wscript.Arguments.Named("ServiceName")

If Len(Trim(strComputer)) > 0 And Len(Trim(strServiceName)) > 0 Then
If IsOnline(strComputer) = True Then
Set objComputer = GetObject("WinNT://" & strComputer & ",computer")

If Err.Number = 0 Then
Set objService = objComputer.GetObject("service", strServiceName)

If Err.Number = 0 Then
WScript.Echo strComputer & vbTab & "Services Status" & vbTab & "Exists"
Else
WScript.Echo strComputer & vbTab & "Services Status" & vbTab & "Does not exist"
End If
Else
WScript.Echo strComputer & vbTab & "Services Status" & vbTab & "Unknown"
End If
Else
WScript.Echo strComputer & vbTab & "Services Status" & vbTab & "Offline"
End If
Else
WScript.Echo "Usage: cscript.exe //nologo DoesServiceExist.vbs /Computer:HOSTNAME /ServiceName:SERVICENAME"
End If

Function IsOnline(strComputer)
Dim objPing
Dim objStatus

Set objPing = GetObject("winmgmts:" & Chr(123) & "impersonationLevel=impersonate" & Chr(125) & "").ExecQuery("select * from Win32_PingStatus where address = ‘" & strComputer & "’")

For Each objStatus in objPing
If IsNull(objStatus.StatusCode) or objStatus.StatusCode0 Then
‘Nothing
Else
IsOnline = True
End If
Next
End Function
[/sourcecode]

Attachment(s):
[list-attachments]

InstallWDS – Installing Windows Deployment Services (WDS) from a batch file

Installing Windows Deployment Services (WDS) from a batch file

I needed to install WDS on 300+ servers but found that the server build did not have a local copy of OS setup or service pack files. I also wanted to set the paths back to the original values.

I started by adding all files required by WDS to the DFS and I created the following batch file.

[sourcecode language=”plain”]
@ECHO OFF

REG EXPORT "HKLMSOFTWAREMicrosoftWindowsCurrentVersionSetup" %WINDIR%InstallWDS.reg /y
REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionSetup" /v "SourcePath" /t REG_SZ /d "\SERVERNAMESHARE" /f
REG ADD "HKLMSOFTWAREMicrosoftWindowsCurrentVersionSetup" /v "ServicePackSourcePath" /t REG_SZ /d "\SERVERNAMESHARE" /f

VER | Find "Microsoft Windows [Version 5.2." > nul
If %ERRORLEVEL% == 0 GoTo Win2003
VER | Find "Microsoft Windows [Version 6.0." > nul
If %ERRORLEVEL% == 0 GoTo Win2008

GoTo CleanUp

:Win2003
ECHO [Components] > %WINDIR%InstallWDS.inf
ECHO RemInst = on >> %WINDIR%InstallWDS.inf
Sysocmgr.exe /i:sysoc.inf /u:%WINDIR%InstallWDS.inf
GoTo CleanUp

:Win2008
ServerManagerCmd -install WDS
GoTo CleanUp

:CleanUp
REG IMPORT %WINDIR%InstallWDS.reg
DEL %WINDIR%InstallWDS.inf
DEL %WINDIR%InstallWDS.reg
[/sourcecode]

Attachment(s):
[list-attachments]