Link to home
Start Free TrialLog in
Avatar of pdixit1977
pdixit1977Flag for India

asked on

Want to create a batch script for XP.

Hi
I want to create a batch script for XP which will do below tasks.
1. Stop "Symantec Management Client" service.
2. Go to location = C:\Program Files\Symantec\Symantec Endpoint Protection and delete these    files 1. Sylink.xml  2. SyLinkEx.bak  3. SyLink.bak  
3. Now copy a file from network location and paste it to = C:\Program Files\Symantec\Symantec Endpoint Protection
4. Start "Symantec Management Client" service.

Now i got stuck on very first point, when i tried to Stop "Symantec Management Client" service thru "c:\>net stop SmcService" it says "The requested pause or stop is not valid for this service.
More help is available by typing NET HELPMSG 2191."
Please help me on this.
Avatar of Bartender_1
Bartender_1
Flag of Canada image

Have you tried this:

@echo off
net stop "Symantec Management Client"
del "c:\program files\symantec\symantec endpoint protection\sylink.xml"
del "c:\program files\symantec\symantec endpoint protection\sylinkex.bak"
del "c:\program files\symantec\symantec endpoint protection\sylink.bak"
copy "\\<server>\<share>\<filename.ext>" "C:\program files\symantec\symantec endpoint protection\"
net start "Symantec Management Client"



Hope this helps!

:o)

Bartender_1
Most antivirus suites wouldn't let you turn off services, because if you could the viruses could as well.  Are these files locked by the service or are you just stopping the service as a precaution?
Are you running the batch file with administrative rights?
Avatar of pdixit1977

ASKER

Bartender: I am getting same error as mentioned in my question when run net stop "Symantec Management Client"

Aleinss: Yes seems like service is locked by the programme and yes i am running this command from my ID who have domain admins rights.
Is SmcService the right name you are calling? reason being this can be done using a VB Script.
Yes it is the correct name of service.
This is a script that can echo back to you what services can be stopped if it does show your SmcService then we can get a script for you in place. Save the file with a .vbs extension. name the file whatever you would like.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService.ExecQuery _
    ("Select * from Win32_Service Where AcceptStop = True")
For Each objService in colServices
    Wscript.Echo objService.DisplayName
Next

Try this script.

Dim Dest
Dest = "\\<server>\<share>\<filename.ext>" "C:\program files\symantec\symantec endpoint protection\"
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer &"\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
        ("Select * from Win32_Service where Name='SmcService'")
For each objService in colServiceList
    errReturn = objService.StopService()
Next

Set objFSO = CreateObject("Scripting.FileSystemObject")
' This below will delete everything in this folder with the *.* so make sure this is what you want to do.
objFSO.DeleteFile "c:\program files\symantec\symantec endpoint protection\*.*"
'This will copy the file from the current location to the destination location.
objFso.CopyFile Dest
Set colServiceList = objWMIService.ExecQuery _
    ("Select * from Win32_Service where Name='SmcService'")
For each objService in colServiceList
    errReturn = objService.StartService()
Next

this is a VB script so you will need to save it as filename.vbs and you will have to put the credentials for the server and share and filename in the top.
Dest = "\\<server>\<share>\<filename.ext>", "C:\program files\symantec\symantec endpoint protection\"
you need a comma in between the two to separate them.
Stevenabdul: I ran the first part of your script to stop the service and it says "C:\echo.vbs(2, 44) Microsoft VBScript compilation error: Expected end of statement"
If that one didnt work try coping this one. instead of creating a variable I just put it to copy the file. within the path.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer &"\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
        ("Select * from Win32_Service where Name='SmcService'")
For each objService in colServiceList
    errReturn = objService.StopService()
Next

Set objFSO = CreateObject("Scripting.FileSystemObject")

' This below will delete everything in this folder with the *.* so make sure this is what you want to do.
objFSO.DeleteFile "c:\program files\symantec\symantec endpoint protection\*.*"

'This will copy the file from the current location to the destination location.
objFso.CopyFile "\\<server>\<share>\<filename.ext>","C:\program files\symantec\symantec endpoint protection\"

Set colServiceList = objWMIService.ExecQuery _
    ("Select * from Win32_Service where Name='SmcService'")
For each objService in colServiceList
    errReturn = objService.StartService()
Next

This should work now.
This version is modified to delete just the files that you described in the top. They way how this script works is that it first stops the service deletes the files then copies the file from the location specified and then places the file in the destination folder and then finally starts the service again.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer &"\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
        ("Select * from Win32_Service where Name='SmcService'")
For each objService in colServiceList
    errReturn = objService.StopService()
Next

Set objFSO = CreateObject("Scripting.FileSystemObject")

objFSO.DeleteFile "c:\program files\symantec\symantec endpoint protection\Sylink.xml"
objFSO.DeleteFile "c:\program files\symantec\symantec endpoint protection\SyLinkEx.bak"  
objFSO.DeleteFile "c:\program files\symantec\symantec endpoint protection\SyLink.bak"  

'This will copy the file from the current location to the destination location.
objFso.CopyFile "\\<server>\<share>\<filename.ext>","C:\program files\symantec\symantec endpoint protection\"

Set colServiceList = objWMIService.ExecQuery _
    ("Select * from Win32_Service where Name='SmcService'")
For each objService in colServiceList
    errReturn = objService.StartService()
Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer &"\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
        ("Select * from Win32_Service where Name='SmcService'")
For each objService in colServiceList
    errReturn = objService.StopService()
Next


I used only this part to check the service stop but it does'nt work.
Please be informed that its not windows inbuild service. this service belongs to Symantec Antivirus.
If you go to the windows services.msc do you see the service listed.
Attached is the sceenshot of my services.msc console which also mentioned service name. I hope this will help
SMC-service.JPG
Ok I have symantec here at my office let me test it on my test machine and I will get back to you.
Ok I found the reason why the script will not stop the service.

the SMC.exe is running as a process this will have to be killed before the script can run and stop the service SmcService. create a batch file and call it whatever you want. in the batch file you will add this

Taskkill /im smcGUI.exe /f
Taskkill /im smc.exe /f

Save it with the bat extension.

and then you will add this code as a vb script code and this will run the batch file and stop the services.

dim shell
set shell=createobject("wscript.shell")
shell.run "location of the batch file.bat"
set shell=nothing
sleep 5000

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer &"\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
        ("Select * from Win32_Service where Name='SmcService'")
For each objService in colServiceList
    errReturn = objService.StopService()
Next

Set objFSO = CreateObject("Scripting.FileSystemObject")

objFSO.DeleteFile "c:\program files\symantec\symantec endpoint protection\Sylink.xml"
objFSO.DeleteFile "c:\program files\symantec\symantec endpoint protection\SyLinkEx.bak"  
objFSO.DeleteFile "c:\program files\symantec\symantec endpoint protection\SyLink.bak"  

'This will copy the file from the current location to the destination location.
objFso.CopyFile "\\<server>\<share>\<filename.ext>","C:\program files\symantec\symantec endpoint protection\"

Set colServiceList = objWMIService.ExecQuery _
    ("Select * from Win32_Service where Name='SmcService'")
'For each objService in colServiceList
    errReturn = objService.StartService()
Next

also check  the properties for symantec and make sure that the recovery tab is set to take no action.

let me know if you have anymore errors.  
dim shell
set shell=createobject("wscript.shell")
shell.run "location of batch file goes here"
set shell=nothing
sleep 5000
 
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer &"\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
        ("Select * from Win32_Service where Name='SmcService'")
For each objService in colServiceList
    errReturn = objService.StopService()
Next

Set objFSO = CreateObject("Scripting.FileSystemObject")

objFSO.DeleteFile "c:\program files\symantec\symantec endpoint protection\Sylink.xml"
objFSO.DeleteFile "c:\program files\symantec\symantec endpoint protection\SyLinkEx.bak"  
objFSO.DeleteFile "c:\program files\symantec\symantec endpoint protection\SyLink.bak"  

This will copy the file from the current location to the destination location.
objFso.CopyFile "\\<server>\<share>\<filename.ext>","C:\program files\symantec\symantec endpoint protection\"

Set colServiceList = objWMIService.ExecQuery _
   ("Select * from Win32_Service where Name='SmcService'")
For each objService in colServiceList
    errReturn = objService.StartService()
Next

I have created batch file as you suggested and mention its location at the given place of your VB script. When i ran the VB script (Service stop part only) it show me below error.

C:\echo.vbs(5, 1) Microsoft VBScript runtime error: Type mismatch: 'sleep'
I have removed the "sleep 5000" from script and it ran without error but service is still running.
make sure that the recovery tab is set to take no action and apply, because it will restart the service immediately. Under services go to the properties of the SmcService and go to the recovery tab.
great, it works this time but i have to visit each and every client machine to change the service recovery tab as take no action and this again a big headache.
Hi,

As aleinss: as suggested. I think Sylink replacer utility should work fine for you.
And it can be used to replace the sylink file remotely on multiple machines.
Just give it a try. Its simple and it serves the purpose.

Regards,
Pradeep Jhala
yes you would have to do it to all computers. Try Alienss suggestion and see if that works for you.
or change the time on the recovery Tab to 5 min.
Pradeep/aleinss.
I had already tried sylink replacer but its not grabbing all systems. I have 600 systesm and by running replacer thrice on each and every VLAN only 280 systesm got updated.

I dont where is the lack and why this not works for all systems.
all users on your network are power users?
NO, they are normal users.
there is a way that you can have the script change the services recovery tab automatically, I am looking into it.
ok, if possible please include this in your existing script. IF POSSIBLE
I will.
ok I got something for you. This new line of code that was added does this, it changes the time of the restart to whatever you set it to in the script this way you will not need to change the recovery tab on all computers just run the script.

dim shell
set shell=createobject("wscript.shell")
shell.run "C:\Users\sabdul\Desktop\SMCkill.bat"
shell.run "SC failure SmcService reset= 1 actions= restart/100000" , 0, false
set shell=nothing
 
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer &"\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
        ("Select * from Win32_Service where Name='SmcService'")
For each objService in colServiceList
    errReturn = objService.StopService()
Next

Set objFSO = CreateObject("Scripting.FileSystemObject")

objFSO.DeleteFile "c:\program files\symantec\symantec endpoint protection\Sylink.xml"
objFSO.DeleteFile "c:\program files\symantec\symantec endpoint protection\SyLinkEx.bak"  
objFSO.DeleteFile "c:\program files\symantec\symantec endpoint protection\SyLink.bak"  

'This will copy the file from the current location to the destination location.
objFso.CopyFile "\\<server>\<share>\<filename.ext>","C:\program files\symantec\symantec endpoint protection\"

Set colServiceList = objWMIService.ExecQuery _
   ("Select * from Win32_Service where Name='SmcService'")
For each objService in colServiceList
    errReturn = objService.StartService()
Next

Working now however i made a bit changes. I have replaced shell.run "C:\Users\sabdul\Desktop\SMCkill.bat" to shell.run "C:\test.bat"

Now testing rest part of script and get back to you soon with possitive results i hope.
thats correct. sounds good.
Hi Stevenabdul,
I ran this script on 4 systems and i got error from 3 system that C:\script.vbs <18, 1>  Microsoft VBScript runtime error: file not found.
Below is the script which i ran, it will help you to find the file which is not getting found.

dim shell
set shell=createobject("wscript.shell")
shell.run "C:\test.bat"
shell.run "SC failure SmcService reset= 1 actions= restart/100000" , 0, false
set shell=nothing
 
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer &"\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
        ("Select * from Win32_Service where Name='SmcService'")
For each objService in colServiceList
    errReturn = objService.StopService()
Next

Set objFSO = CreateObject("Scripting.FileSystemObject")

objFSO.DeleteFile "C:\Program Files\Symantec\Symantec Endpoint Protection\sylink.xml"
objFSO.DeleteFile "C:\Program Files\Symantec\Symantec Endpoint Protection\SyLinkEx.bak"  
objFSO.DeleteFile "C:\Program Files\Symantec\Symantec Endpoint Protection\SyLink.bak"  

objFso.CopyFile "\\172.17.7.1\Sylink_New\sylink.xml","C:\Program Files\Symantec\Symantec Endpoint Protection\"

Set colServiceList = objWMIService.ExecQuery _
   ("Select * from Win32_Service where Name='SmcService'")
For each objService in colServiceList
    errReturn = objService.StartService()
Next
are you sure that the file exists at this location.
"C:\Program Files\Symantec\Symantec Endpoint Protection\sylink.xml"
The script is saying that it cannot find the this file in the given path.
I will check it on monday meanwhile can you make your script able to run if it does'nt found any file at given path.
dim shell
set shell=createobject("wscript.shell")
shell.run "C:\SMCkill.bat"
shell.run "SC failure SmcService reset= 1 actions= restart/100000" , 0, false
set shell=nothing

On Error Resume Next

Dim D1,D2,D3
Dim Path,Dest


D1 = "c:\program files\symantec\symantec endpoint protection\Sylink.xml"
D2 = "c:\program files\symantec\symantec endpoint protection\SyLinkEx.bak"
D3 = "c:\program files\symantec\symantec endpoint protection\SyLink.bak"


'Add your path here and your destination for the file to be copied

Path = "\\<server>\<share>\<filename.ext>"
Dest = "C:\program files\symantec\symantec endpoint protection\"
 
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer &"\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
        ("Select * from Win32_Service where Name='SmcService'")
For each objService in colServiceList
    errReturn = objService.StopService()
Next

Set objFSO = CreateObject("Scripting.FileSystemObject")


   If FileExists D1 Then
       objFSO.DeleteFile D1
   End If      
   
   If FileExists D1 Then
       objFSO.DeleteFile D2  
   End If

   If FileExists D1 Then
       objFSO.DeleteFile D3  
   End If


'This will copy the file from the current location to the destination location.
objFso.CopyFile Path,Dest

Set colServiceList = objWMIService.ExecQuery _
   ("Select * from Win32_Service where Name='SmcService'")
For each objService in colServiceList
    errReturn = objService.StartService()
Next

use this one

dim shell
set shell=createobject("wscript.shell")
shell.run "C:\SMCkill.bat"
shell.run "SC failure SmcService reset= 1 actions= restart/100000" , 0, false
set shell=nothing

On Error Resume Next

Dim D1,D2,D3
Dim Path,Dest


D1 = "c:\program files\symantec\symantec endpoint protection\Sylink.xml"
D2 = "c:\program files\symantec\symantec endpoint protection\SyLinkEx.bak"
D3 = "c:\program files\symantec\symantec endpoint protection\SyLink.bak"


'Add your path here and your destination for the file to be copied

Path = "\\<server>\<share>\<filename.ext>"
Dest = "C:\program files\symantec\symantec endpoint protection\"
 
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer &"\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
        ("Select * from Win32_Service where Name='SmcService'")
For each objService in colServiceList
    errReturn = objService.StopService()
Next

Set objFSO = CreateObject("Scripting.FileSystemObject")


   If FileExists (D1) Then
       objFSO.DeleteFile D1
   End If      
   
   If FileExists (D2) Then
       objFSO.DeleteFile D2  
   End If

   If FileExists (D3) Then
       objFSO.DeleteFile D3  
   End If


'This will copy the file from the current location to the destination location.
objFso.CopyFile Path,Dest

Set colServiceList = objWMIService.ExecQuery _
   ("Select * from Win32_Service where Name='SmcService'")
For each objService in colServiceList
    errReturn = objService.StartService()
Next
thanks.
will check it and update you soon.
Did the script work for you?
the script is running but its unable to find the file "C:\Program Files\Symantec\Symantec Endpoint Protection\sylink.xml" whether file is there when i checked manually.
I will create the file myself over here and test it to see what it is doing. I will let you know my results.
hi steve,
is there any update on this.
Ok, I tested on my machine and it seems to work. it removed the sylink.xml from my computer, however, I created a file called sylink.xml. what I need you to do is, check that file on one computer and make sure that it can be deleted manually. If it states that it cannot be deleted then we have to find out what is running and stop that process before we continue. When I test it on my machine it removes the files correctly. One more thing, try taking out the On Error Resume Next on the script. and then run it, this might show some sort of error after. let me know what it states.
I checked it out again. I found that although we deleted the files, once the service is started again the file is recreated. It is probably linked to the executable.
I Think if you really want to get rid of that file you will have to remove the sylink.DLL as well.
this is the default behaviour of executable and we are doing this whole activity just for this only. We have to delete sylink.dll because it contains old server links and configuration, this will be recreate post service start with new links and configuration.
Are you deleting the sylink.dll?
give me a list of all the syslink in the symantec folder.
If you are talking about sylink file than it is only one but still i am attaching search result for whole of c drive for sylink.
Sylink.JPG
Are the files that you want deleted being deleted, way to find this out would be to test on your computer and do not restart the service check to see if the files deleted and then start the service. it is possible that what you are trying to do is not related to that file.
ASKER CERTIFIED SOLUTION
Avatar of stevenabdul
stevenabdul
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Script didn't worked for us but still the follow up and efforts made by steve are really very good. thanks steve for all your help.