There are over 500 UDFs mirrored here already - so not much normal day to day Admin work that is not already in an easy to use UDF.
Good luck and if you need further assistance please let us know. Don't forget the FAQ section here on the board as well which answers a lot of basic questions about KiXtart.
MartMart KiX Supporter
Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
This would do it. Change it to your needs. Please not that this can not be done to all services. Eventlog for example can't be stopped in this like this because it is an essential service. Not that anyone should like to stop an essential service but he who knows what everyone wants.
Code:
;Checks if the requested service is running and changes the start-up type if wanted. ;In this example the Themes service is stopped and set to disabled. ;Status: 0 is boot, 1 is system, 2 is automatic, 3 is manual, 4 is disabled. ; Break on ; $Key = "HKLM\SYSTEM\CurrentControlSet\Services\" $ServiceState = ReadValue ($key + "Themes", "Start") ; If $ServiceState = "4" ?"Can't start a disabled service. Enable the service manually." Else Select Case $ServiceState = "0" $ServiceState = "Boot" Case $ServiceState = "1" $ServiceState = "System" Case $ServiceState = "2" $ServiceState = "Automatic" Case $ServiceState = "3" $ServiceState = "Manual" Case $ServiceState = "4" $ServiceState = "Disabled" EndSelect ; Shell '%comspec% /c net start | find /i "Themes"' ; Select Case @ERROR = "0" ?"Themes service is running and starts: " + $serviceState Shell '%comspec% /c net stop "Themes"' $rd = WriteValue ($key + "Themes", "Start", "4", "REG_DWORD") ?"Requested service was running and is set to disabled." Case @ERROR <> "0" AND $ServiceState ="0" WriteValue ($key + "Themes", "Start", "4", "REG_DWORD") Case @ERROR <> "0" AND $ServiceState ="1" WriteValue ($key + "Themes", "Start", "4", "REG_DWORD") Case @ERROR <> "0" AND $ServiceState ="2" WriteValue ($key + "Themes", "Start", "4", "REG_DWORD") Case @ERROR <> "0" AND $ServiceState ="3" WriteValue ($key + "Themes", "Start", "4", "REG_DWORD") Case @ERROR <> "0" AND $ServiceState = "4" ?"Requested service is not running and has status disabled." Case @ERROR <> "0" AND $ServiceState <> "4" WriteValue ($key + "Themes", "Start", "4", "REG_DWORD") ?"Requested service is not running and is set to disabled." EndSelect EndIf ; @CRLF Do ?"Please check the messages above [Q to Quit] " Get $x Until $x = "q"
Another question... I started using the SERVICEMODE() udf but am a LITTLE confused about the syntax...
The readme says ;SYNTAX SERVICEMODE(SERVICENAME [,STARTUPMODE]) and ;EXAMPLE $mode=SERVICEMODE('service','automatic')
I tried this... Code:
IF $mode=SERVICEMODE('Altiris Agent','Disabled') SERVICEMODE('Altiris Agent','Automatic') EndIF
But it did nothing, I am probably using the syntax and examples wrong... I also tried just a simple Code:
SERVICEMODE('Altiris Agent','Automatic')
without any other logic but this did nothing either... What I am aiming at here is to simple set the service to Automatic if it is set to disabled. I did check my registry to make sure I have the exact right name of the service.
MartMart KiX Supporter
Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
OK! The SERVICEMODE() udf is a much better way to control the services then my example Had this wondering around for some time, it works great though.
Doing a $mode=SERVICEMODE('Themes','Automatic') should set the start-up mode to automatic. It does for me. First doing a check like in the example I posted above and then set the state using SERVICEMODE() udf should work. Off course you should start the service after it has been set to automatic. It does not start by itself. And you will need the proper privileges to change service start-up mode.
I changed the test service to Themes(as in $mode=SERVICEMODE('Themes','Automatic') ) and it worked GREAT... I tried The Altiris Agent again and it did not work. Which tells me my problem is either that I do not have the exact correct service name OR I am having issues with the space in the service name.. so any ideas on the correct syntax for a service with a space in the name? Im sure I need to throw a "" in somewhere.
FYI I got it working... The problem was not the space in the name of the service I was using... but rather I was using the name that was in the registry under "Display Name". I found that I must use the name of the registry KEY!!!
OK guess I am not totally done as yet. Like I said above I got the ServiceMODE function to change the service from "Disabled" to "Automatic". I even when through the help that R2D2 provided and created the below script and that changes the type from "Disabled" to "Automativ (see code). I have tried this on a couple different non-essential services and I get the same problem (see below). Code: Code:
The problem is that even though it changes the service from one start type to another I cannot start the service. I get an error saying the service is still disabled. Both the SERVICEMODE function and the above script does this.
If I use the GUI to change the service type, I do not have the problem. If I change the start type in the REGISTRY directly (using regedit) I do not have the problem. It is only when I use any script to change the value in the registry that I have this issue. To fix the service I simple open the service GUI and set it to disabled and then re-set it to automatic. That fixes it.
I have watched the registry as the script runs and can see it change the "Start" field from 4 to 2. I can see no difference between what the script does and what I do when I manually change the registry value (which works).
Anyone ever have this issue, can anyone offer any advice?
KdyerKdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Hi Pat,
I know what you are trying to do as we run Altiris Too.. Maybe do a remote Admin Script with XNET? That might be the trick you are looking for. The big problem with Altiris is that we have seen when we try to connect in using CarbonCopy, is the service has stopped and we need to start it remotely, before connecting in.
heheh nice to hear others share my misery. Altiris is a great product in most ways but the users HATE it (big brother phobia). We consider ourselves a "scholastic Campus" and it has been decreed (by powers far greater than mine) that all users will have full admin rights on their PCs. They frequently go in and delete all the altiris files in program files\altiris directory and stop and disable the services.
I am simply looking for a way to counter this issue at logon by re-installing and re-enabeling it.
you can re-push the app butt... If the service is disabled and stopped there is not way for the app to recieve the repair type push. It will not re-install because it will see the PC as already having the client installed on it and will ignore any subsequent installs.
My logon script so far works as I want, in that it will check to make sure the client files are not deleted, if they are it will force a re-install of the client. So half my battle is done.
Now I just need to re-enable the service. I am working on doing a snapshot of the PC before/after the service is enabled/disabled to see if I can use that instead.
MartMart KiX Supporter
Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Maybe a very user unfriendly option.....
How about checking the service state or if it is present at all, check if the files still exist if not remove the service using Xnet. After removing the service re-push the client app. Maybe one or more reboots are necessary, don't know not using Altiris.
Like I said not so user friendly but he, they remove the files and disable the service. This way they will get burned by the things they do but are not supposed to do. Maybe they will learn something this way and maybe this a a way to show the higher powers that admin privs to everyone is not a good option because the systems get f$#@cked up by the users.
NTDOCNTDOC Administrator
Registered: 2000-07-28
Posts: 11628
Loc: CA
Pat,
You can't start a service that is in the Disabled mode so you need to first set the Startup mode to AUTOMATIC, then actually Start the service. However, in your case if they have removed the files or enough of the files to prevent the service from starting then you need to at least set it to Automatic, then push out the Altiris Agent again.
NOTE! Chris has not updated the code yet though to support the NoVarsInStrings option. I have updated and posted an example here though for you to try.
NTDOCNTDOC Administrator
Registered: 2000-07-28
Posts: 11628
Loc: CA
Kent
Quote: Not completely true.. You can start a service if it is set to MANUAL
I said nothing about MANUAL I said you can't start one set to DISABLED until you set it to Automatic (or if what you mean is that it can also be set to MANUAL, then yes, true either MANUAL or AUTOMATIC will work, but not DISABLED.)
I will try the new function and see if that works any better. I will post back my results good or bad.
Just to be clear though on my issue. The scripts I have used so far ONLY set the service to automatic. THen when I go and manually start the service it says it is still disabled (1058 error pops up on the screen, and a 10005 DCOM error in the event log), even though the service tool claims it is set to automatic... weird.
The service will not start after that until I use the service tool to re-set the service type to any other mode and back again.