Solved

running vbs script on windows 2012

Posted on 2014-12-11
11
333 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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 45

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

Want to promote your upcoming event?

Are you going to an event? Are you going to be exhibiting at a tradeshow? Talking at a conference? Using a promotional banner in your email signature ensures that your organization’s most important contacts stay in the know and can potentially spread the word about the event.

Join & Write a Comment

Suggested Solutions

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

758 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

22 Experts available now in Live!

Get 1:1 Help Now