noob62 Posted September 4, 2012 Share Posted September 4, 2012 We have a program that manages all of our servers and applies policies to these systems. I'm trying to create a script to look for services related to system roles. I have the following script done so far and I'm sure there are a some things wrong with it. One issue is that it doesn't seem to read the text file for the searched term. Any help/guidance would be much appreciated. ;name of the service to look for $DHCP = 'DHCP Server' $DNS = 'DNS Server' $AD = 'Active Directory Domain Services' ;Create folder for text file DirCreate("C:\ScriptTemp") ;send a list of the services that are running to a file Run(@ComSpec & " /C " &"net start > C:\ScriptTemp\services.txt", "", @SW_HIDE) ;read that file $FileText = FileRead("C:\ScriptTemp\services.txt") ;check for the service name If StringInStr($FileText, $DHCP) Then RegWrite("HKLM\SOFTWARE\Network Associates\ePolicy Orchestrator\Agent\CustomProps", "CustomProps1", "REG_SZ", "DHCP Server") ElseIf StringInStr($FileText, $DNS) Then RegWrite("HKLM\SOFTWARE\Network Associates\ePolicy Orchestrator\Agent\CustomProps", "CustomProps1", "REG_SZ", "DNS Server") ElseIf StringInStr($FileText, $AD) Then RegWrite("HKLM\SOFTWARE\Network Associates\ePolicy Orchestrator\Agent\CustomProps", "CustomProps1", "REG_SZ", "Active Directory") ElseIf ProcessExists("sqlservr.exe") Then RegWrite("HKLM\SOFTWARE\Network Associates\ePolicy Orchestrator\Agent\CustomProps", "CustomProps1", "REG_SZ", "SQL Server") ElseIf ProcessExists("SPWRITER.exe") Then RegWrite("HKLM\SOFTWARE\Network Associates\ePolicy Orchestrator\Agent\CustomProps", "CustomProps2", "REG_SZ", "SharePoint Server") Elseif ProcessExists("mad.exe") Then RegWrite("HKLM\SOFTWARE\Network Associates\ePolicy Orchestrator\Agent\CustomProps", "CustomProps3", "REG_SZ", "Exchange Server") EndIf ;delete the text file and folder FileDelete("C:\ScriptTemp\services.txt") DirRemove("C:\ScriptTemp") Link to comment Share on other sites More sharing options...
BrewManNH Posted September 4, 2012 Share Posted September 4, 2012 Well, it's only going to look for the first item it finds in the text file and then exit because you're using an If/Then to check for the string, but not checking for any other strings that might be there. You're going to have to do it differently, maybe something like this would work better. ;name of the service to look for $aServices[3] = ['DHCP Server', 'DNS Server', 'Active Directory Domain Services'] ;Create folder for text file DirCreate("C:ScriptTemp") ;send a list of the services that are running to a file Run(@ComSpec & " /C " & "net start > C:ScriptTempservices.txt", "", @SW_HIDE) ;read that file $FileText = FileRead("C:ScriptTempservices.txt") ;check for the service name For $I = 0 To 2 If StringInStr($FileText, $aServices[$I]) Then RegWrite("HKLMSOFTWARENetwork AssociatesePolicy OrchestratorAgentCustomProps", "CustomProps1", "REG_SZ", $aServices[$I]) EndIf Next If ProcessExists("sqlservr.exe") Then RegWrite("HKLMSOFTWARENetwork AssociatesePolicy OrchestratorAgentCustomProps", "CustomProps1", "REG_SZ", "SQL Server") If ProcessExists("SPWRITER.exe") Then RegWrite("HKLMSOFTWARENetwork AssociatesePolicy OrchestratorAgentCustomProps", "CustomProps2", "REG_SZ", "SharePoint Server") If ProcessExists("mad.exe") Then RegWrite("HKLMSOFTWARENetwork AssociatesePolicy OrchestratorAgentCustomProps", "CustomProps3", "REG_SZ", "Exchange Server") ;delete the text file and folder FileDelete("C:ScriptTempservices.txt") DirRemove("C:ScriptTemp") If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
noob62 Posted September 17, 2012 Author Share Posted September 17, 2012 Thanks!! That works better then the way I was doing it. If I wanted to write all the detected service running to the regkey could I just write the results to an array then write whats in the array to the regkey? Link to comment Share on other sites More sharing options...
noob62 Posted December 3, 2012 Author Share Posted December 3, 2012 If I wanted to post multiple detections to the string would pasting the strings to a text file then copy the text when its over and pasting that to the registry key be the most efficient way? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now