?
Solved

uninstall winternals defrag agent through a script

Posted on 2007-12-05
16
Medium Priority
?
759 Views
Last Modified: 2012-08-14
I would like to have a script that uninstall the defrag agent in the workstations in windows domain if the agent exist in the workstation.

I looked on the help pages of the winternal defrag manager and I found this help I would like to have some help from you guys on how  to uninstall winternal from computers under a certain OU.

this is the help content:
-----
Using TCP/IP with the Preinstalled Agent
You can use TCP/IP with a preinstalled agent to defragment computers on any TCP/IP network, including networks without File and Printer Sharing.  The Defrag Manager agent allows the Schedule Console to copy the Defrag Manager files to the client systems by means of TCP/IP in the absence of File and Print sharing.

 

To configure a schedule to use TCP/IP with a preinstalled agent:

Select the Client tab of the Schedule Properties dialog box or open the Client Settings page of the New Schedule Wizard.

Select Use TCP/IP with preinstalled agent.

If you select this option you can also set TCP/IP port number and agent password options.

To install the Defrag Manager agent

Copy the TCP/IP agent dfrgmgr.exe from the Defrag Manager installation directory.

Install the agent on computers in the schedule using the following command syntax.

Syntax

dfrgmgr.exe -i [-s Server | IPAddress] [-p Port] [-k Password [-n ComputerName]]

dfrgmgr.exe -u

Parameters

-i

Install the agent.

-s <Server>|<IPAddress>

Allow connections only from a specified computer name or IP address. The computer name can be a fully qualified DNS name or a NetBIOS name.

-p

Specify the port number. You should enter a value only if you want to override the default port number 52322.

-k Password [-n ComputerName]

Specify a password. If not entered no password is used. If you enter a password, use the -n parameter to specify the name of the client computer as it appears in the schedule if that name is different from the NetBIOS name.

-u

Uninstall the agent.

 

 Notes

You can use a software deployment tool such as Microsoft SMS to install the agent, or build a custom Microsoft Windows Installer package file (.msi) to deploy the agent via logon scripts or group policy.

After you install the Defrag Manager agent you can delete the instance dfrgmgr.exe just executed, as a copy is made in the %Systemroot% directory of the computer.

You can run the command again to update any settings. This action stops agent service, uninstalls the agent, and reinstalls it with the new configuration.


thanks
0
Comment
Question by:jskfan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 5
16 Comments
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20414121
Save this as bat file and use it as computer startup script

regards
Chandru
If not exist "C:\Program files\defrag\dfrgmgr.exe" goto End1
cd\
"C:\Program files\defrag\drfgmgr.exe" -u
 
:End1
Exit

Open in new window

0
 

Author Comment

by:jskfan
ID: 20414387
chandru_sol:

for instance in my machine if I go to command prompt then enter:
dfrgmgr
it wil give me the following:
Defrag Manager Agent v4.00.5.194
Copyright (C) 2002-2005 Winternals Software
www.winternals.com

usage: dfrgmgr -i [-s <server>|<ip address>] [-p port] [-k password [-n name]]
       dfrgmgr -u
   -i     Installs Defrag Manager agent
   -s     Specifies that connections will only be accepted from a
          particular machine or IP address.
   -p     Specifies port number to use (default is 52322)
   -k     Specifies password to use (default is none)
   -n     Specifies computer name as specified in schedule
   -u     Uninstalls Defrag Manager agent

but physically I couldn't locate the dfrgmgr file.
this is why I want first to find it then run the dfrgmgr and confirm that it's no longer there.
0
 

Author Comment

by:jskfan
ID: 20415393
when I try to unistall it through command line using:
dfrgmgr -u
I get this error:

Error deleting agent from C:\Windows\DfrgMgr.exe:
Access is denied
Schedule(s)uninstalled

I am logged to my computer with domain admins account
0
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
LVL 12

Expert Comment

by:chandru_sol
ID: 20416984
From the above the file is in c:\windows \dfrgmgr.exe

Can you see the program is installed in Add/remove programs"?
0
 

Author Comment

by:jskfan
ID: 20419768
I found where the defrag starts from. It's a scheduled task that starts as follow:

%windir%\system32\defrag.exe -c -i

So I will need a script that removes the scheduled task which name is scheduledDefrag and also removes the defrag.exe from %windir%\system32

thanks
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20421402
Try this for deleteing the scheduled task

regards
Chandru
intJobID = "Scheduledtask name"
strComputer = "."
set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objInstance = objWMI.Get("Win32_ScheduledJob.JobID=" & intJobID)
intRC = objInstance.Delete
if intRC <> 0 then
   Wscript.Echo "Failure deleting task id: " & intJobID
else 
   Wscript.Echo "Sucessfully deleted task id: " & intJobID
end if

Open in new window

0
 

Author Comment

by:jskfan
ID: 20427051
I am getting error: Invalid object path on line 4 char 1

Set objInstance = objWMI.Get("Win32_ScheduledJob.JobID=" & intJobID)
0
 

Author Comment

by:jskfan
ID: 20434551
any fix for the error.??????
0
 

Author Comment

by:jskfan
ID: 20442694
Don't you think intjobID should be a number? but I am not sure how to find the jobID of a specific scheduled task
0
 

Author Comment

by:jskfan
ID: 20442720
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20442995
Can you try the enumeration script in the link and see if you could find the jobid?

regards
Chandru
0
 

Author Comment

by:jskfan
ID: 20443641
I tried and didn't show anything. then I noticed this:

Enumerates all the scheduled tasks on a computer. Note: WMI can only enumerate scheduled tasks created with the Win32_ScheduledJob class or the At.exe utility. It cannot enumerate tasks created using the Task Scheduler.
0
 

Author Comment

by:jskfan
ID: 20446224
I don't know if this command is removed if it willl throw an error for a logged on user:
%windir%\system32\defrag.exe -c -i
0
 

Author Comment

by:jskfan
ID: 20446361
I guess that's what I need to remove
%windir%\system32\defrag.exe

can you write  a script?

thanks
0
 

Author Comment

by:jskfan
ID: 20446541
dim filesys
Set filesys = CreateObject("Scripting.FileSystemObject")
'filesys.CreateTextFile "c:\somefile.txt", True
If filesys.FileExists("c:\windows\system32\defrag.exe") Then
   filesys.DeleteFile "c:\windows\system32\defrag.exe"
'   wscript.echo "File deleted"
End If
0
 
LVL 12

Accepted Solution

by:
chandru_sol earned 1500 total points
ID: 20446943
That script should work. I think you have started learning scripts which is really good and all the best.

Let me know if it fails or you need any additional codes
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question