Jump to content

Script Error


Recommended Posts

I am trying to make my first Autoit script to disable some services on several pc's. I found 

On page 5 the last post says script breaking changes and says to change something in the services.au3 but I am not sure what to change it to. I am recieving that same error. Here is my script appreciate anyone telling me what I need to change and would like to hear if I am doing anything wrong in my script below.

#RequireAdmin

#include "Services.au3"
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Local $aServiceNames[5]
;$aServiceNames[0] = "bthserv" ;--> Bluetooth service
$aServiceNames[0] = "Fax" ;--> Fax Service
$aServiceNames[1] = "TermService" ;--> Remote Desktop Service
$aServiceNames[2] = "RemoteRegistry" ;--> Remote Registry Service
$aServiceNames[3] = "stisvc" ;-->  Windows Image Acquisition
$aServiceNames[4] = "wisvc" ;--> Windows Insider Service

; Loop through service names, calling _Service_setStartType to disable
For $i = 0 To UBound($aServiceNames) - 1
    _Service_SetStartType($aServiceNames, $SERVICE_DISABLED[$i])
Next

;_Service_SetStartType($sServiceName, $iStartType [, $sComputerName])

 

Link to comment
Share on other sites

Here a very simple way to stop and disable a service :

#RequireAdmin

; https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-service

StopService("PhoneSvc")
If @error Then ConsoleWrite("Not a service" & @CRLF)

Func StopService($sService)
  Local $oHandler = ObjEvent("AutoIt.Error", WMIerror)
  Local $oWMI = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2")
  Local $oService = $oWMI.Get("Win32_Service.Name='" & $sService & "'")
  If @error Then Return SetError(@error)
  $oService.StopService()
  $oService.ChangeStartMode("Disabled")
EndFunc

Func WMIerror($oError)
EndFunc

 

Edited by Nine
Link to comment
Share on other sites

41 minutes ago, Andreik said:

Just open Services.au3 and replace $RIGHTS_DELETE with $STANDARD_RIGHTS_DELETE.

This has made the script continue thank you. 

I have a new error am I using the wrong  name for $SERVICE_DISABLED or is it something to do with the collection or array I tried to create at the start of the script?

\Disable Services.au3" (18) : ==> Subscript used on non-accessible variable.:
_Service_SetStartType($aServiceNames, $SERVICE_DISABLED[$i])
_Service_SetStartType($aServiceNames, $SERVICE_DISABLED^ ERROR

Link to comment
Share on other sites

11 hours ago, SmOke_N said:

I found the answer in this post 

yeah yeah hour super smart and can do everything better than everyone else except go read the last post that I referenced. Your expectation is that everyone coming in will know all the rules of posting in here and so when they don't measure up to your expectiations you try to virtue signal your greatness. No need to respond I will delete my account and go to a Python site to learn how to do this and use that going forward. 

Link to comment
Share on other sites

1 hour ago, Noobis said:

This has made the script continue thank you. 

I have a new error am I using the wrong  name for $SERVICE_DISABLED or is it something to do with the collection or array I tried to create at the start of the script?

\Disable Services.au3" (18) : ==> Subscript used on non-accessible variable.:
_Service_SetStartType($aServiceNames, $SERVICE_DISABLED[$i])
_Service_SetStartType($aServiceNames, $SERVICE_DISABLED^ ERROR

This is your error and has nothing to do with UDF. Post the script that produce this error.

When the words fail... music speaks.

Link to comment
Share on other sites

1 hour ago, Noobis said:

No need to respond I will delete my account and go to a Python

You're like, "Dad, i'm gonna tell Mom you're making fun of me". Take it like a grown up, not like a child. In this or any forum.
You know that you asked a question based on something you did not share. Hard to answer.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...