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.
pdixit1977Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bartender_1Microsoft Network AdministratorCommented:
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
0
Adam LeinssServer SpecialistCommented:
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?
0
pdixit1977Author Commented:
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.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

stevenabdulCommented:
Is SmcService the right name you are calling? reason being this can be done using a VB Script.
0
pdixit1977Author Commented:
Yes it is the correct name of service.
0
stevenabdulCommented:
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

0
Adam LeinssServer SpecialistCommented:
0
stevenabdulCommented:
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.
0
stevenabdulCommented:
Dest = "\\<server>\<share>\<filename.ext>", "C:\program files\symantec\symantec endpoint protection\"
you need a comma in between the two to separate them.
0
pdixit1977Author Commented:
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"
0
stevenabdulCommented:
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.
0
stevenabdulCommented:
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
0
pdixit1977Author Commented:
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.
0
pdixit1977Author Commented:
Please be informed that its not windows inbuild service. this service belongs to Symantec Antivirus.
0
stevenabdulCommented:
If you go to the windows services.msc do you see the service listed.
0
pdixit1977Author Commented:
Attached is the sceenshot of my services.msc console which also mentioned service name. I hope this will help
SMC-service.JPG
0
stevenabdulCommented:
Ok I have symantec here at my office let me test it on my test machine and I will get back to you.
0
stevenabdulCommented:
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.

0
stevenabdulCommented:
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.  
0
stevenabdulCommented:
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

0
pdixit1977Author Commented:
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'
0
pdixit1977Author Commented:
I have removed the "sleep 5000" from script and it ran without error but service is still running.
0
stevenabdulCommented:
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.
0
pdixit1977Author Commented:
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.
0
jhalapradeepCommented:
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
0
stevenabdulCommented:
yes you would have to do it to all computers. Try Alienss suggestion and see if that works for you.
0
stevenabdulCommented:
or change the time on the recovery Tab to 5 min.
0
pdixit1977Author Commented:
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.
0
stevenabdulCommented:
all users on your network are power users?
0
pdixit1977Author Commented:
NO, they are normal users.
0
stevenabdulCommented:
there is a way that you can have the script change the services recovery tab automatically, I am looking into it.
0
pdixit1977Author Commented:
ok, if possible please include this in your existing script. IF POSSIBLE
0
stevenabdulCommented:
I will.
0
stevenabdulCommented:
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

0
pdixit1977Author Commented:
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.
0
stevenabdulCommented:
thats correct. sounds good.
0
pdixit1977Author Commented:
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
0
stevenabdulCommented:
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.
0
pdixit1977Author Commented:
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.
0
stevenabdulCommented:
ok
0
stevenabdulCommented:
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

0
stevenabdulCommented:
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
0
pdixit1977Author Commented:
thanks.
will check it and update you soon.
0
stevenabdulCommented:
Did the script work for you?
0
pdixit1977Author Commented:
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.
0
stevenabdulCommented:
I will create the file myself over here and test it to see what it is doing. I will let you know my results.
0
pdixit1977Author Commented:
hi steve,
is there any update on this.
0
stevenabdulCommented:
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.
0
stevenabdulCommented:
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.
0
stevenabdulCommented:
I Think if you really want to get rid of that file you will have to remove the sylink.DLL as well.
0
pdixit1977Author Commented:
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.
0
stevenabdulCommented:
Are you deleting the sylink.dll?
0
stevenabdulCommented:
give me a list of all the syslink in the symantec folder.
0
pdixit1977Author Commented:
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
0
stevenabdulCommented:
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.
0
stevenabdulCommented:
if you are going to delete the syslink.dll all you have to do is once the service is stopped then you can delete what you want, what we need to do is add another line of code to delete the sylink.dll fairly simple process.

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

On Error Resume Next

Dim D1,D2,D3
Dim Path,Dest
Dim D4


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

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 FileExist (D1) then
objFSO.DeleteFile D1
End If

If FileExist (D2) then
objFSO.DeleteFile D2  
End If

If FileExist (D3) then
objFSO.DeleteFile D3  
End If

If FileExist (D4) 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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pdixit1977Author Commented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.