Jump to content

Windows Services UDF


GEOSoft
 Share

Recommended Posts

$Computer = "COMPUTERNAME"
$Domain = "DOMAIN"
$User = InputBox("User Name", "Please enter your user name:")
$Password = InputBox("Password", "Please enter your password:", "", "*")
$objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator")
$objSWbemServices = $objSWbemLocator.ConnectServer($Computer, _
"root\cimv2", _
$User, _
$Password, _
"MS_409", _
"ntlmdomain:" + $Domain)
$colSwbemObjectSet = _
$objSWbemServices.ExecQuery("Select * From Win32_Process")
For $objProcess In $colSWbemObjectSet
MsgBox(0, "Output", "Process Name: " & $objProcess.Name)
Next

.. am getting;

c:\Scripts\services.au3 (18) : ==> The requested action with this object has failed.: 
$objSWbemServices = $objSWbemLocator.ConnectServer($Computer, "root\cimv2", $User, $Password, "MS_409", "ntlmdomain:" + $Domain) 
$objSWbemServices = $objSWbemLocator.ConnectServer($Computer, "root\cimv2", $User, $Password, "MS_409", "ntlmdomain:" + $Domain)^ ERROR

I obviously change the $Computer and $Domain.

Close doesn't always work.

Try this

$Computer = "COMPUTERNAME"
$Domain = "DOMAIN"
$User = InputBox("User Name", "Please enter your user name:")
$Password = InputBox("Password", "Please enter your password:", "", "*")
$objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator")
$objSWbemServices = $objSWbemLocator.ConnectServer($Computer, _
"root\cimv2", _
$User, _
$Password, _
"MS_409", _
"ntlmdomain:" & $Domain)
$colSwbemObjectSet = _
$objSWbemServices.ExecQuery("Select * From Win32_Process")
For $objProcess In $colSWbemObjectSet
MsgBox(0, "Output", "Process Name: " & $objProcess.Name)
Next

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • Replies 100
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

still not working...

Scripts\services.au3 (18) : ==> The requested action with this object has failed.: 
$objSWbemServices = $objSWbemLocator.ConnectServer($Computer, "root\cimv2", $User, $Password, "MS_409", "ntlmdomain:" & $Domain) 
$objSWbemServices = $objSWbemLocator.ConnectServer($Computer, "root\cimv2", $User, $Password, "MS_409", "ntlmdomain:" & $Domain)^ ERROR

I have made sure the username password is correct.

Link to comment
Share on other sites

still not working...

Scripts\services.au3 (18) : ==> The requested action with this object has failed.: 
$objSWbemServices = $objSWbemLocator.ConnectServer($Computer, "root\cimv2", $User, $Password, "MS_409", "ntlmdomain:" & $Domain) 
$objSWbemServices = $objSWbemLocator.ConnectServer($Computer, "root\cimv2", $User, $Password, "MS_409", "ntlmdomain:" & $Domain)^ ERROR

I have made sure the username password is correct.

Try changing

$Domain = "DOMAIN"

To

$Domain = '"DOMAIN"'

OR change

$objSWbemServices = $objSWbemLocator.ConnectServer($Computer, "root\cimv2", $User, $Password, "MS_409", "ntlmdomain:" & $Domain)

To

$objSWbemServices = $objSWbemLocator.ConnectServer($Computer, "root\cimv2", $User, $Password, "MS_409", "ntlmdomain:" & Chr(34) & $Domain & Chr(34))^

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Still nothing.. this really doesnt want to work!!

Scripts\services.au3 (18) : ==> The requested action with this object has failed.: 
$objSWbemServices = $objSWbemLocator.ConnectServer($Computer, "root\cimv2", $User, $Password, "MS_409", "ntlmdomain:" & chr(34) & $Domain & Chr(34)) 
$objSWbemServices = $objSWbemLocator.ConnectServer($Computer, "root\cimv2", $User, $Password, "MS_409", "ntlmdomain:" & chr(34) & $Domain & Chr(34))^ ERROR
Edited by ale1981
Link to comment
Share on other sites

Still nothing.. this really doesnt want to work!!

Scripts\services.au3 (18) : ==> The requested action with this object has failed.: 
$objSWbemServices = $objSWbemLocator.ConnectServer($Computer, "root\cimv2", $User, $Password, "MS_409", "ntlmdomain:" & chr(34) & $Domain & Chr(34)) 
$objSWbemServices = $objSWbemLocator.ConnectServer($Computer, "root\cimv2", $User, $Password, "MS_409", "ntlmdomain:" & chr(34) & $Domain & Chr(34))^ ERROR
PM me the script and I'll take a look at it.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...

I've done some major updates with this UDF. It now includes most of the code and modifications posted in the thread. I also removed the code from the first post. Please use the link instead. For the download you can either use the link in the post or click on Download at the bottom of the web page.

Thanks to all who suggested modifications and provided additional code. If there is something on the page that you did not get credit for then let me know and I'll change it. If you have more functions to add then please PM them to me for inclusion.

Enjoy

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

It would be nice to have these UDF included with AutoIt.

I have not submitted it for inclusion and it may never be submitted.

There is more testing/debugging to be done before that would be considered.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

;
#include <services.au3>
Global $sDesc, $serv = "Spooler"
$Details = _Service_GetDetails("$serv")
If IsArray($Details) Then
   $sDesc = $Details[10]
   MsgBox(0, "Result", $serv & @CRLF & @CRLF $sDesc)
Else
  MsgBox(0, "Ooooops", $serv & " does not exist.")
EndIf
;

EDIT: Make sure you have the latest version of services.au3

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I think you misinterpreted my question. I have found a workaround though: you can make a registry key called "Description" and import it to the registry entry of your service. Not pretty, but works.

Edited by faire
Link to comment
Share on other sites

I think you misinterpreted my question. I have found a workaround though: you can make a registry key called "Description" and import it to the registry entry of your service. Not pretty, but works.

You are correct. I totally missed the SET. I can write a function to do that, but not today.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

How can I set the Description text of a service?

CODE
$sComputer = "."

$sServiceName = "< MY SERVICE >"

$sDescription = "My Service Description"

RunWait(@ComSpec & ' /C sc \\' & $sComputer & ' description ' & $sServiceName & ' "' & $sDescription & '"', "", @SW_HIDE)

Link to comment
Share on other sites

Hmm.. this is odd! My service gets terminated after 30 seconds with the error: "Error 1053: The service did not respond to the start or control request in a timely fashion". It runs fine for those 30 seconds though, it's just that Windows terminates it because it "doesn't respond to the start or control request".

Do I need to add some special code to my script for it to be properly run as a service?

To further the explanation, let's take this rather silly code:

While 1
Sleep(20)
$Pid = WinGetProcess("Untitled - Notepad")
ProcessClose($Pid)
WEnd

Surely this doesn't contain anything which should stop it from running as a service :)

Edit: found this:

"NOTE: To verify that the service was created correctly, check the registry to verify that the ImagePath value under

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\service name

is set to point to SRVANY.EXE. If this is not set correctly, the service will stop shortly after it starts and return an Event ID 7000 "The service name failed to start."

So you DO still need SRVANY.EXE for this to work? :(

Edit2: I've taken the approach outlined in post #23. The service being started acts as a launcher for the real program. The only drawback is that it still leaves a nasty error in the Eventlog (two, actually: 7000 and 7009), but that's ok...

Edited by faire
Link to comment
Share on other sites

Hi.

I was using the latest version of the script and I got this error while using the function Service_Delete()

Thanks. It's getting a bit late here right now but I'll look at it in the morning.

Edit: Did you check to make sure the service exists befor trying to delete it?

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Beta version sent to you by PM

EDIT:

Apparently it worked for you so the file has been updated on the site.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

The file you download from the site is still the old one.

Thanks. I'll try it again.

EDIT: I must have forgotten to upload the zip when I uploaded the au3 file. It's okay now.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Thanks. I'll try it again.

EDIT: I must have forgotten to upload the zip when I uploaded the au3 file. It's okay now.

It's there now. Thanks.

Question:

Do you need ProcessWaitClose($sServiceName) after _Service_Delete()?

My contributions:Local account UDF Registry UDFs DriverSigning UDF Windows Services UDF [url="http://www.autoitscript.com/forum/index.php?showtopic=81880"][/url]

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