Solved

running vbs script on windows 2012

Posted on 2014-12-11
11
433 Views
Last Modified: 2015-01-16
I have this VBS script that worked fine in windows 2008 R2 but in windows 2012 R2 I get the following error.

Line:  5
Char: 1
Error: Subscript out of range
Code: 800A0009
Source: MIcrosoft VBscript runtime error

Going by that error char 1 on line 5 would be 's' from strComputer. Is that no longer used in windows 2012?

Here is the VBS script (Below)

'Declare Variables
Dim objWMIService, objProcess, colProcess, Status, strComputer, strService
 
'Assign Arguments
strComputer = WScript.Arguments(0)
strService = WScript.Arguments(1)
Status= false
 
'Check For Arguments - Quit If None Found
If Len(strService) < 1 Then
    Wscript.echo "No Arguments Entered - Exiting Script"
    WScript.Quit
End If
 
'Setup WMI Objects
Set objWMIService = GetObject("winmgmts:"& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery ("SELECT DisplayName, Status, State FROM Win32_Service WHERE DisplayName = '" & strService & "'")
 
'Check For Running Service
For Each objProcess in colProcess
    If InStr(objProcess.DisplayName,strService) > 0 And objProcess.State = "Running" Then
      Status = true
    End If
Next
 
If Status = true Then
    Wscript.echo "Service: " & UCase(strComputer) & " " & strService & " Running"
    'Perform Some Pass Logic Here
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "service@mycompany.com"
objEmail.To = "admin@mycompany.com"
objEmail.Subject = "service is Running"
objEmail.Textbody = ""
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"92ycas1.int.92y.org"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send

Else
    Wscript.echo "Service: " & UCase(strComputer) & " " & strService & " Not Running"
    'Perform Some Failed Logic Here
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "Service@mycompany.org"
objEmail.To = "admin@companyemail.com"
objEmail.Subject = "Service has stopped"
objEmail.Textbody = "ATTENTION is NEEDED"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"companyemail.com"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
      
End If
0
Comment
Question by:iamuser
11 Comments
 
LVL 22

Expert Comment

by:plusone3055
ID: 40494109
out of range means your trying to access and object that does not exist on the machine

OR your array isn't big enough to hold the data your trying to get
0
 
LVL 22

Expert Comment

by:plusone3055
ID: 40494114
out of range means your trying to access and object that does not exist on the machine

OR

your array isn't big enough to hold the data your trying to get
0
 

Author Comment

by:iamuser
ID: 40494710
so how do I fix this? the service does exist on the server. I installed it myself
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 22

Expert Comment

by:plusone3055
ID: 40494721
Change  WScript.Arguments(0)
to  WScript.Arguments(1)

and  tell me if you receive the same error :)
0
 

Author Comment

by:iamuser
ID: 40494753
I did, it still error out
0
 
LVL 22

Expert Comment

by:plusone3055
ID: 40494839
same error ?
0
 

Author Comment

by:iamuser
ID: 40495481
yup same error with this change
 
'Assign Arguments
strComputer = WScript.Arguments(1)
strService = WScript.Arguments(1)
Status= false
0
 

Author Comment

by:iamuser
ID: 40502680
anyone?
0
 
LVL 29

Accepted Solution

by:
MikeOM_DBA earned 500 total points
ID: 40510061
Move this code:
'Check For Arguments - Quit If None Found
If Len(strService) < 1 Then
    Wscript.echo "No Arguments Entered - Exiting Script"
    WScript.Quit
End If

Open in new window


to: before the 'Assign Arguments part.
And... supply at least one argument when calling the program.
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40553076
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Remote Apps is a feature in server 2008 which allows users to run applications off Remote Desktop Servers without having to log into them to run the applications.  The user can either have a desktop shortcut installed or go through the web portal to…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question