Typical disclaimer:  I *really* need to stress that everything below is based on my own research and findings - the information below does not indicate official documentation or support, however some of this may be accurate. 

Questions and/or suggestions are welcome, and as usual - hope that helps!  ^_^

John

_____________________________

The following K1000 script can be used to completely remove the K1000 Agent from Windows devices.  It is architecture agnostic and will work equally well for x86 and x64 versions of Windows.

Successful testing was completed against the following platforms:

  • Windows 7 Professional SP1 x86
  • Windows 7 Enterprise SP1 x64
  • Windows 8 Enterprise x86

K1000 Script Configuration


Name
Agent Uninstall And Cleanup
Enabled
Yes
Type
Online KScript (although Offline should work as well)
Operating Systems
Microsoft Windows
Windows Run As
Local System

Task 1 Configuration


Verify
Verify the service "AMPAgent" is running.
On Success
Run the batch file "AgentUninstallAndCleanup" with params "".


AgentUninstallAndCleanup Batch File (Retain KUID)

The following batch file works in several steps, but basically it does the following:

1) Creates a cleanup batch file to remove any remaining Agent directories after the Agent is uninstalled, as well as the cleanup batch file itself.  This is placed in the C:\Windows\Temp directory, where it is executed by a scheduled task and then is removed once it has been run.

2) Creates a scheduled task to run the batch file created in step 1.  This scheduled task executes 2 minutes after creation.  If the scheduled task already exists, it is removed and recreated.

3) Runs the standard "AMPTools uninstall" command to uninstall the Agent.


:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::Create a batch file in C:\Windows\Temp to remove any remaining Agent directories after the Agent is uninstalled::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo rmdir /s/q C:\ProgramData\Dell\KACE >> C:\Windows\Temp\AgentCleanup.bat
echo rmdir /s/q "C:\Program Files\Dell\KACE" >> C:\Windows\Temp\AgentCleanup.bat
echo rmdir /s/q "C:\Program Files (x86)\Dell\KACE" >> C:\Windows\Temp\AgentCleanup.bat
echo del C:\Windows\Temp\AgentCleanup.bat /f/s/q >> C:\Windows\Temp\AgentCleanup.bat
 
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::Create a scheduled task to run the AgentCleanup batch file (delete & recreate if it already exists)                   ::
::The scheduled task will run 2 minutes after being created, which should be enough time for the Agent to be uninstalled::
::This can be adjusted in the "set /A minute+=2" line - just change the 2 to the desired length of time (in minutes)    ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
cls
schtasks /query > doh
findstr /B /I "AgentCleanup" doh >nul
if %errorlevel%==0  goto :delete
goto :create
  
:delete
schtasks /delete /tn "AgentCleanup" /f >nul
  
:create
setlocal
  
set hour=%time:~0,2%
set minute=%time:~3,2%
set /A minute+=2
  
if %minute% GTR 59 (
 set /A minute-=60
 set /A hour+=1
)
  
if %hour%==24 set hour=00
if "%hour:~0,1%"==" " set hour=0%hour:~1,1%
if "%hour:~1,1%"=="" set hour=0%hour%
if "%minute:~1,1%"=="" set minute=0%minute%
  
set tasktime=%hour%:%minute%
  
schtasks /ru "SYSTEM" /create /sc ONCE /tn AgentCleanup /tr C:\Windows\Temp\AgentCleanup.bat /st %tasktime% >nul
del doh >nul
:::::::::::::::::::::::
::Uninstall the Agent::
:::::::::::::::::::::::
if /i "%programfiles%"=="%programfiles(x86)%" ("C:\Program Files (x86)\Dell\KACE\AMPTools.exe" uninstall) else ("C:\Program Files\Dell\KACE\AMPTools.exe" uninstall)
 
:::::::::::::::::
::2015/06/03-jv::
:::::::::::::::::

AgentUninstallAndCleanup Batch File (Remove KUID - Agent 6.2 and below)

The following batch file works the same as the previous, but includes a command to remove all references to the KUID in the registry.  This approach is necessary if the Agent is version 6.2 or lower.


:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::Create a batch file in C:\Windows\Temp to remove any remaining Agent directories after the Agent is uninstalled::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo rmdir /s/q C:\ProgramData\Dell\KACE >> C:\Windows\Temp\AgentCleanup.bat
echo rmdir /s/q "C:\Program Files\Dell\KACE" >> C:\Windows\Temp\AgentCleanup.bat
echo rmdir /s/q "C:\Program Files (x86)\Dell\KACE" >> C:\Windows\Temp\AgentCleanup.bat
echo del C:\Windows\Temp\AgentCleanup.bat /f/s/q >> C:\Windows\Temp\AgentCleanup.bat
 
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::Create a scheduled task to run the AgentCleanup batch file (delete & recreate if it already exists)                   ::
::The scheduled task will run 2 minutes after being created, which should be enough time for the Agent to be uninstalled::
::This can be adjusted in the "set /A minute+=2" line - just change the 2 to the desired length of time (in minutes)    ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
cls
schtasks /query > doh
findstr /B /I "AgentCleanup" doh >nul
if %errorlevel%==0  goto :delete
goto :create
  
:delete
schtasks /delete /tn "AgentCleanup" /f >nul
  
:create
setlocal
  
set hour=%time:~0,2%
set minute=%time:~3,2%
set /A minute+=2
  
if %minute% GTR 59 (
 set /A minute-=60
 set /A hour+=1
)
  
if %hour%==24 set hour=00
if "%hour:~0,1%"==" " set hour=0%hour:~1,1%
if "%hour:~1,1%"=="" set hour=0%hour%
if "%minute:~1,1%"=="" set minute=0%minute%
  
set tasktime=%hour%:%minute%
  
schtasks /ru "SYSTEM" /create /sc ONCE /tn AgentCleanup /tr C:\Windows\Temp\AgentCleanup.bat /st %tasktime% >nul
del doh >nul
 
:::::::::::::::::::::::
::Uninstall the Agent::
:::::::::::::::::::::::
if /i "%programfiles%"=="%programfiles(x86)%" ("C:\Program Files (x86)\Dell\KACE\AMPTools.exe" uninstall) else ("C:\Program Files\Dell\KACE\AMPTools.exe" uninstall)
 
::::::::::::::::::::
::Registry Cleanup::
::::::::::::::::::::
if /i "%programfiles%"=="%programfiles(x86)%" (reg delete HKLM\SOFTWARE\Wow6432Node\Dell\Kace /f) else (reg delete HKLM\SOFTWARE\Dell\Kace /f)
 
:::::::::::::::::
::2015/06/03-jv::
:::::::::::::::::

AgentUninstallAndCleanup Batch File (Remove KUID - Agent 6.3 and above)

The following batch file works the same as the previous, but uses the "all-kuid" option (available starting in version 6.3 of the Agent) to remove all references to the KUID in the registry.


:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::Create a batch file in C:\Windows\Temp to remove any remaining Agent directories after the Agent is uninstalled::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo rmdir /s/q C:\ProgramData\Dell\KACE >> C:\Windows\Temp\AgentCleanup.bat
echo rmdir /s/q "C:\Program Files\Dell\KACE" >> C:\Windows\Temp\AgentCleanup.bat
echo rmdir /s/q "C:\Program Files (x86)\Dell\KACE" >> C:\Windows\Temp\AgentCleanup.bat
echo del C:\Windows\Temp\AgentCleanup.bat /f/s/q >> C:\Windows\Temp\AgentCleanup.bat
 
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::Create a scheduled task to run the AgentCleanup batch file (delete & recreate if it already exists)                   ::
::The scheduled task will run 2 minutes after being created, which should be enough time for the Agent to be uninstalled::
::This can be adjusted in the "set /A minute+=2" line - just change the 2 to the desired length of time (in minutes)    ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
cls
schtasks /query > doh
findstr /B /I "AgentCleanup" doh >nul
if %errorlevel%==0  goto :delete
goto :create
  
:delete
schtasks /delete /tn "AgentCleanup" /f >nul
  
:create
setlocal
  
set hour=%time:~0,2%
set minute=%time:~3,2%
set /A minute+=2
  
if %minute% GTR 59 (
 set /A minute-=60
 set /A hour+=1
)
  
if %hour%==24 set hour=00
if "%hour:~0,1%"==" " set hour=0%hour:~1,1%
if "%hour:~1,1%"=="" set hour=0%hour%
if "%minute:~1,1%"=="" set minute=0%minute%
  
set tasktime=%hour%:%minute%
  
schtasks /ru "SYSTEM" /create /sc ONCE /tn AgentCleanup /tr C:\Windows\Temp\AgentCleanup.bat /st %tasktime% >nul
del doh >nul
 
:::::::::::::::::::::::
::Uninstall the Agent::
:::::::::::::::::::::::
if /i "%programfiles%"=="%programfiles(x86)%" ("C:\Program Files (x86)\Dell\KACE\AMPTools.exe" uninstall all-kuid) else ("C:\Program Files\Dell\KACE\AMPTools.exe" uninstall all-kuid)
 
:::::::::::::::::
::2015/06/03-jv::
:::::::::::::::::

Notes

1) The AgentCleanup scheduled task remains after the K1000 script runs.  However, this should not be a major issue since it only runs once and the batch file it runs (AgentCleanup.bat) is deleted after execution.

2) Carriage returns will break some of the longer statements (if /i ... in the Uninstall the Agent and Registry Cleanup sections) - these appear on multiple lines here due to text wrapping.  Copying and pasting into a text editor like Notepad should result in these statements being placed on a single line.