Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

uninstall winternals defrag agent through a script

Posted on 2007-12-05
16
Medium Priority
?
760 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
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
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
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
 
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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

886 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