im using sql server 2012 and replication process in it. now the replication process is working correctly, but i want to delete this replication, i mean all the publications, subscriptions and articles through script. i went through this site http://support.microsoft.com/kb/324401 and tried the following script
:setvar PublisherDatabase "AdventureWorks2012"
:setvar SubscriberServer "HYDHTC0131320D\MSSQLSERVER2"
use [$(PublisherDatabase)]
--Drop all subscriptions
exec sp_dropsubscription
@publication = N'TestPubs',
@article = N'all',
--@subscriber = [$(SubscriberServer)]
@subscriber = N'all',
@destination_db = N'all'
--Drop publication
if exists (Select 1 From SysPublications where name = N'TestPubs')
EXEC sp_droppublication @publication = N'TestPubs'
EXEC sp_replicationdboption @dbname = [$(PublisherDatabase)], @optname = N'publish', @value = N'false'
--Drop subscriber entry
EXEC sp_dropsubscriber @subscriber = [$(SubscriberServer)]
--Drop distributor
EXEC sp_dropdistributor @no_checks = 1
after i execute the above script, im getting the following error.
Only one Log Reader Agent or log-related procedure (sp_repldone, sp_replcmds, and sp_replshowcmds) can connect to a database at a time. If you executed a log-related procedure, drop the connection over which the procedure was executed or execute sp_replflush over that connection before starting the Log Reader Agent or executing another log-related procedure.
Msg 18752, Level 16, State 1, Procedure sp_replcmds, Line 1
Only one Log Reader Agent or log-related procedure (sp_repldone, sp_replcmds, and sp_replshowcmds) can connect to a database at a time. If you executed a log-related procedure, drop the connection over which the procedure was executed or execute sp_replflush over that connection before starting the Log Reader Agent or executing another log-related procedure.
The Subscriber was dropped.
Msg 20015, Level 16, State 1, Procedure
sp_MSreplremoveuncdir, Line 83
Could not remove directory 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\ReplData\unc\HYDHTC0131320D_ADVENTUREWORKS2012_TESTPUBS\20120719152739\'. Check the security context of xp_cmdshell and close other processes that may be accessing the directory.
check this screenshot for more details

can anyone help me in solving these issues
It looks like you had some errors when dropping replication and have some orphaned subscription metadata at teh Subscriber. Orphaned metadata can be removed from the subscription database using sp_removedbreplication.
For future reference, you can remove all subscriptions, publications, and disable publishing and distribution following these steps:
Relevant bits of code from the links
a) To drop a push subscription on transactional replication
b) To drop a subscription on a merge replication
c) To drop a publication and set a source DB to stop being a publisher, on a transactional replication.
d) To drop a publication and set a source DB to stop being a publisher, on a merge replication.