Solved

running vbs script on windows 2012

Posted on 2014-12-11
11
369 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
 
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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…

867 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now