Jump to content

advapi32.dll funktion ChangeServiceConfig2


 Share

Recommended Posts

I'm using AutoIt3 now since a couple of years to create some simple scripts every now and then but now I've come to a point where my coding skills reached their limits.

I've used the UDFs Service.au3 and ServiceControl.au3 to create new services and I noticed, that there's no option to create a service description. So I took a closer look to the UDFs mentioned before and after some hours of trial and error I thought that it should not be too difficult to add that feature to the UDF.

And then I found the advapi32.dll function ChangeServiceConfig2!!!

I never did any relevant code in C/C++ or other languages, OK the usual "Hello world" and a screen saver drawing colored circles on a black background using trigonometric functions more than ten years ago in a workshop. So first of all I didn't even know what a structure is. After some rummaging I found an old script from the workshop and now I have a dim hunch of what a structure is but it's not enough to code it in AutoIt. I've found some code examples in C/C++ or java but I'm not able to transform it into AutoIt code.

So I used the search here in the forum and didn't get a single hit for ChangeServiceConfig2. So I tried QueryServiceConfig2 with the same result. Why? Is it a complete nonsense to use API functions to write a simple comment to the registry when I can use RegWrite instead? Or what's the reason that nobody has ever used this function in AutoIt? Is it so simple that no one wants to waste a single word on it? Or is it impossible to use it in AutoIt? I am far from believing this.

So, if anyone has a clue how to code what I have in mind of if it's possible at all, please let me know. Any comment would be appreciated.

Thank you!

PS: You guys are doing a great job here, so keep on coding to break the matrix!

Link to comment
Share on other sites

Example:

$aManager = DllCall("advapi32.dll", "ptr", "OpenSCManager", "long", 0, "long", 0, "long", 0xf003f)
$aService = DllCall("advapi32.dll", "ptr", "OpenService", "long", $aManager[0], "str", "Alerter", "long", 0xf003f)
$serviceDescription = DllStructCreate("ptr")
$sDescription = DllStructCreate("char[260]")
DllStructSetData($sDescription, 1, "Notifies selected users and computers of administrative alerts. If the service is stopped, programs that use administrative alerts will not receive them. If this service is disabled, any services that explicitly depend on it will fail to start.")
DllStructSetData($serviceDescription, 1, DllStructGetPtr($sDescription))
DllCall("advapi32.dll", "int", "ChangeServiceConfig2", "long", $aService[0], "long", 1, "long", DllStructGetPtr($serviceDescription))
DllCall("advapi32.dll", "ptr", "CloseServiceHandle", "long", $aService[0])
DllCall("advapi32.dll", "ptr", "CloseServiceHandle", "long", $aManager[0])

Change "Alerter" to the name of your service.

Change "Notifies ..." to the description you want.

WBD

Link to comment
Share on other sites

You guys are absolutely amazing! Thank you so much!

Have you ever used a walkthrough in an adventure game? This is exactly the feeling I have right now. Like a cheater after peeking for the solution of a tricky puzzle.

But I was on the right way. The step that I failed was the structure, as I said in my first post.

Thanks again for your help!

Lesson learned.

Case closed.

Link to comment
Share on other sites

  • 8 years later...

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...