×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How do I resolve this permissions error in my script?

How do I resolve this permissions error in my script?

How do I resolve this permissions error in my script?

(OP)
Back in 2018 I wrote a vbscript to start a service if the service was stopped. Back then I had this run as a scheduled task at specific time but decided to remove if from scheduler and run it manually if I ever needed it. I'm switching computers and tried this script out on my old Windows 10 Pro PC before moving it to my new Windows 11 PC and it no longer works. I put some echo's in he script and found that the return code is 2 and according to what I found on the internet it's telling me I don't have permissions to start the service. Obviously, I have not run this script for a very long tome and when I wrote the script my PC was Windows 7 Pro where this action might have been allowed. Before I delete this script I wanted to see if there's a way that it can be run under Windows 10 and 11. Here's the code:

ServiceName = "Cloudberry Backup Service"
Set wmi = GetObject("winmgmts://./root/cimv2")
state = wmi.Get("Win32_Service.Name='" & ServiceName & "'").State
wscript.echo state
If State = "Stopped" then
Set shell = CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name ='" & ServiceName & "'")
For Each objService in colListOfServices
wscript.echo "Service Name: " & objservice.name & vbnewline & "State: " & objservice.state
objService.StartService()
errReturn = objService.StartService()
wscript.echo errReturn
Next
End If

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close