Solved

uninstall winternals defrag agent through a script

Posted on 2007-12-05
16
737 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
  • 11
  • 5
16 Comments
 
LVL 12

Expert Comment

by:chandru_sol
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 12

Expert Comment

by:chandru_sol
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
any fix for the error.??????
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:jskfan
Comment Utility
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
Comment Utility
0
 
LVL 12

Expert Comment

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

regards
Chandru
0
 

Author Comment

by:jskfan
Comment Utility
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
Comment Utility
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
Comment Utility
I guess that's what I need to remove
%windir%\system32\defrag.exe

can you write  a script?

thanks
0
 

Author Comment

by:jskfan
Comment Utility
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 500 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now