Solved

running vbs script on windows 2012

Posted on 2014-12-11
11
474 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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 47

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

749 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