Sign in to follow this  
Followers 0
ScriptingSteve

Compile Error for WMI scripting

5 posts in this topic

I am writing a script to change settings of Windows Services. I am implementing Microsoft's script sample:

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colServiceList = objWMIService.ExecQuery _

("Select * from Win32_Service where StartMode = 'Manual'")

For Each objService in colServiceList

errReturnCode = objService.Change( , , , , "Disabled")

Next

I have it working in AutoIt 3.1.1.76:

If IsObj($colItems) then

For $serviceItem in $colItems

$ServChange = $serviceItem.Change( , , , , "Disabled")

Next

Endif

The problem is the line "$ServChange = $serviceItem.Change( , , , , "Disabled")" produces a syntax error at compile time. If I click "Continue Anyway", the resultant compiled script works properly.

What syntax should I be using in the $ServChange= line to prevent this compilation error?

Share this post


Link to post
Share on other sites



I imagine you would use Change("", "", "", "", "Disabled")


Who else would I be?

Share this post


Link to post
Share on other sites

The problem is the line "$ServChange = $serviceItem.Change( , , , , "Disabled")" produces a syntax error at compile time. If I click "Continue Anyway", the resultant compiled script works properly.

What syntax should I be using in the $ServChange= line to prevent this compilation error?

The syntax check is done by AU3Check and it expects a value like "",0,Default or else it gives this error.

If the Syntax is valid for AutoIt3 then Tylo needs to have a look at AU3Check to see if it can be supported by AU3check as well..


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Two issues:

The Windows function fails when I tried ("","","", etc) (I already tried that)

Based on the Microsoft articles, and the VB script samples they have posted, the correct syntax for the WMI function is ( , , , ,"Thing here")

So for now it's a syntax limitation...

Share this post


Link to post
Share on other sites

Just upgraded to 3.1.1.78, and upgraded Scite to the latest version ('default' wasn't being accepted as a keyword in the version I was using).

Changing $ServChange = $serviceItem.Change( , , , , "Disabled") to:

$ServChange = $serviceItem.Change(default ,default ,default ,default , "Disabled")

compiles OK and works fine. Thanks!

Share this post


Link to post
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
Sign in to follow this  
Followers 0