Jump to content

Recommended Posts

  • Moderators

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to post
Share on other sites
  • Moderators

AVG is a very basic AV it does not compare to many high end solutions like Kaspersky and Nod32, why wouldn't I want to upgrade, you get what you pay for.

I see no reason not to upgrade. I myself can't stand AVG. But it's silly to think that an AV software could be "silently" uninstalled, what would stop something malicious from uninstalling it? And if it can... well... that's just stupid.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to post
Share on other sites
  • 9 months later...

I have a bunch of machines I am upgrading to a different antivirus. does anyone no how to silently uninstall AVG

/UNINSTALL /HIDE does not work

First of all, I have 25,000 machines to uninstall, so visiting every machine is out of the question. AVG is holding us hostage, but it wont work and i think they will regret their decision not to provide a silent uninstall, for corporate customers, as do all other vendors. in writing this program, my goal was to hide all windows after checking the boxes on their pop up and clicking OK. after uninstalling, i wanted to kill the final windows and let the user continue without restarting immediately.

i tried to do this using a handle to connect the windows, so the window would not have to be active, but was unsuccessful. the window has to be active and sometimes the avg window gets covered with another window and does not get processed. The program i wrote (some of it i clipped and modified), to uninstall AVG, (because they do not have a silent install), ran into several problems with permissions. the original part uses no functions, since after i use runaset, the program should run in admin mode. i verified this with the msgbox test to show when it is in admin mode. if not in admin mode, the program does a runasset command, runs itself in the admin context and exits the non admin program. otherwise, it continues in the admin context. so far so good, but i found that AVG uninstall starts and is not able to stop its own processes or services, due to permissions issues. i was wrong in thinking that running the program with admin credentials in a non-priv user account would run as admin until completed. at first i used vbscript to stop processes and services, but the script worked half of the time, probably because it did not have full rights. however, i switched to Taskkill.exe (should be on every windows XP machine... type taskkill /? at a command prompt to check it out), which stops both processes and services everytime. the only thing it did not do was disable the services, which were stopped. i believe it is almost there (working), except that there is some timing issues with dealing with the windows. it works most of the time, but sometimes cannot find the "Uninstalling..." window", which i would like to hide. there is a seperate program called avgrunonce.au3, which is used as a gpo script (since the uninstall program has a gui and must after widows is active) and which does the following:

1) checks to see if AVG is installed and exits if not

2) copies the _avgremove.exe to the local hard drive

3) puts an entry in the registry HKCU runonce, to run _avgremove.exe

since my program does not work 100%, i am going to write one which merely disables AVG services; removes the startup key from the registry and see how much trouble is involved with dealing with com objects in outlook and IE. i am thinking i may not have to deal with the com add ins, since they will not be called and therefore will not cause trouble. if someone has a solution for the problems i outlined, please post it.


If FileExists("C:\Program Files\Grisoft\AVG7\avgw.exe") Then

FileCopy("\\avgctr\avgutil\_AVGremove.exe", "c:\temp\_AVGremove.exe", 9)

; Write a single REG_SZ value

RegWrite("HKCU\SOFTWARE\Microsoft\Windows\Currentversion\Runonce", "AVGremove", "REG_SZ", "c:\temp\_avgremove.exe")



&&&&&&&&&&&&main program&&&&&&&&&&&&&&

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****






#AutoIt3Wrapper_Run_After=copy "%out%" "\\9144-a-1531a1\c$\temp\_avgremove.exe"



#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****



;this program will uninstall AVG 7.5 client from workstations

;written by James L - 10/7/2007


Opt("WinWaitDelay", 100)

Opt("WinTitleMatchMode", 2)

Opt("WinDetectHiddenText", 0)

Opt("WinTextMatchMode", 2)

Local $temp1, $temp2, $temp

Local $var = "testttt", $tmpSvcErr, $tmpSvcState

Local $sServiceToDissable = "avg"

; Are we already admin?

MsgBox(0, "", "before isadmin avg-remove===isadmin==" & IsAdmin(), 5)

If Not IsAdmin() Then

ConsoleWrite('in isadmin*' & @AutoItExe & '*' & ' *' & @ScriptFullPath & ',' & @WorkingDir & @CRLF)

RunAsSet('avg-remove', 'domain', 'password', 1)

Run('"' & @AutoItExe & '"' & ' "' & @ScriptFullPath & '"', @WorkingDir)

;MsgBox(0, "", @AutoItExe & "<<>>" & @ScriptFullPath & "<<>>" & @WorkingDir, 5)



If FileExists("C:\Program Files\Grisoft\AVG7\avgw.exe") Then

;avg uninstall will not work, AVG license error window open,

;so wait to see if it opens and then close it if it does.

WinWait("License error", "AVG", 3)

If WinExists("License error", "AVG") Then

WinKill("License error", "AVG")

WinWaitClose("License error", "AVG", 5)

;avg will not uninstall with invalid license, so fix it and wait to be done

; RunWait(@ComSpec & " /c " & "\\avgctr\AVGlicense\AVGlicense.exe", "", @SW_HIDE)

RunWait(@ComSpec & " /c " & "start \\avgctr\AVGlicense\AVGlicense.exe")



;exit if avg is not installed.



RunWait("taskkill.exe /f /t /im avg* ", "", @SW_HIDE)


;MsgBox(0, "first", $sServiceToDissable, 2)

$temp = _disableAVGsvc($sServiceToDissable)

;MsgBox(0, $temp, $sServiceToDissable, 5)

;$temp = _ProcessKill($sServiceToDissable)

;MsgBox(0, $temp, $sServiceToDissable, 5)

;run standard avg uninstall program

Run('C:\Program Files\Grisoft\AVG7\setup.exe /uninstall')

If Not WinExists("AVG 7.5", "Checking System Status") Then WinWait("AVG 7.5", "Checking System Status", 10)

;wait for AVG to check the status of avg installation before continuing with uninstall

If WinExists("AVG 7.5", "Checking System Status") Then

;hide check status window, so user cannot cancel

WinSetState("AVG 7.5", "Checking System Status", @SW_HIDE)

WinWaitClose("AVG 7.5", "Checking System Status", 3)


;avg uninstall process will not contiune if checking status does not open, so exit procedure



;wait for checking status window to close before checking for uninstall window

;if windows "uninstall avg" window exists, then uninstalling avg is initiating

WinWait("AVG 7.5", "Uninstall AVG", 30)

If WinExists("AVG 7.5", "Uninstall AVG") Then

;necessary to make window active inorder to use control commands

WinActivate("AVG 7.5", "Uninstall AVG")

If WinActive("AVG 7.5", "Uninstall AVG") Then

;run control commands to check two boxes and click Yes, to continue

$avghandle = ControlGetHandle("AVG 7.5", "Uninstall AVG", "Button4")


ControlCommand("AVG 7.5", "Uninstall AVG", "Button4", "check", "")

ControlCommand("AVG 7.5", "Uninstall AVG", "Button5", "check", "")

ControlCommand("AVG 7.5", "Uninstall AVG", "Button1", "check", "")

; WinWaitClose("AVG 7.5", "Uninstall AVG", 5)



;stop uninstall process, if uninstall avg window is not available



;wait for AVG 7 - uninstalling... window to open, so process monitoring can continue

;now check process conditions and handle exceptions

If Not WinExists("AVG 7", "Uninstalling") Then WinWait("AVG 7", "Uninstalling", 60)

If WinExists("AVG 7", "Uninstalling") Then

MsgBox(0, "***Uninstalling***", " ***YESSSSS*** Exists", 2)

;WinActivate("AVG 7", "Uninstalling")

;If Not WinActive("AVG 7", "Uninstalling") Then WinWaitActive("AVG 7", "Uninstalling", 5)

WinSetState("AVG 7", "Uninstalling", @SW_HIDE)

; WinWaitClose("AVG 7", "Uninstalling...", 10)


MsgBox(0, "***Uninstalling...***", " ***NOT*** Exists..... ", 2)

;exit program, if uninstalling avg does not begin

; Exit


;MsgBox(0, "before result<<", "before result>>", 2)

If Not WinExists("Result of the uninstallation") Then WinWait("Result of the uninstallation", 120)

WinActivate("Result of the uninstallation")

WinWaitActive("Result of the uninstallation", "", 10)

If WinExists("Result of the uninstallation") Then

;WinActivate("Result of the uninstallation")

MsgBox(0, "", "***in K result of unin.....", 3)

WinKill("Result of the uninstallation")


;at this point all avg windows should be closed, so user does not have to deal with it

If WinExists("AVG") Then WinKill("AVG")

Func _ProcessKill($ProcTmp)

Local $TmpStrLen, $dll, $i, $list, $TmpProcessName, $pid

Local $bool = 0

$ProcTmp = StringLower($ProcTmp)

$TmpStrLen = StringLen($ProcTmp)

; List all processes

$dll = DllOpen("kernel32.dll")

$list = ProcessList()

For $i = 1 To $list[0][0]

$pid = $list[$i][1]

$TmpProcessName = $list[$i][0]

If $ProcTmp = StringMid($TmpProcessName, 1, $TmpStrLen) Then

MsgBox(0, "stop process", $list[$i][1] & "< process >" & $list[$i][0], 4)

ConsoleWrite($list[$i][1] & "<>" & $list[$i][0] & @CRLF)

ProcessWaitClose($list[$i][1], 240)

DllCall($dll, 'ptr', 'DebugActiveProcess', 'int', $pid)


ElseIf $ProcTmp < StringMid($TmpProcessName, 1, $TmpStrLen) Then

MsgBox(0, "DONE with stop process >" & $ProcTmp, $list[$i][1] & "< process >" & $list[$i][0], 8)

Return "no more avg processes to stop"





EndFunc ;==>_ProcessKill

Func _disableAVGsvc($SVCtmp)

Local $j1, $aTemp, $temp1, $temp2, $services_array, $aTempSvc

Local $tmpSvcState, $TmpStrLen = StringLower(StringLen($SVCtmp))

Local $bool = 1

$services_array = _RetrieveServices(@ComputerName)

$SVCtmp = StringLower($SVCtmp)

If Not @error And IsArray($services_array) Then

For $j1 = 1 To $services_array[0]

$aTemp = StringSplit($services_array[$j1], "|")

$tmpSvcState = _GetServiceState($aTemp[1])

If StringLower($tmpSvcState) = "running" And $SVCtmp = StringMid($aTemp[1], 1, $TmpStrLen) Then

ConsoleWrite("service before test, is> " & $j1 & " TO " & $services_array[0] & "<>" & $aTemp[1] & "> with state>" & $aTemp[2] & " STRLEN>" & $TmpStrLen & @CRLF)

$tmpSvcErr = _SetServiceState(@ComputerName, $aTemp[1], "Stop")



$aTempSvc = $aTemp[1]

; $tmpSvcState = _GetServiceState($aTempSvc)

If $SVCtmp = StringMid($aTemp[1], 1, $TmpStrLen) Then

$tmpSvcState = _SetServiceState(@ComputerName, $aTemp[1], "Disabled")

;MsgBox(0, "stop service", $aTemp[1] & "<>" & $aTemp[2] & $tmpSvcErr, 4)

ConsoleWrite("stop service status==" & $aTemp[1] & "<>" & $aTemp[2] & @LF)

ElseIf ($SVCtmp < StringMid($aTemp[1], 1, $TmpStrLen)) Then

Return ("done with avg services")





EndFunc ;==>_disableAVGsvc

Func _GetServiceState($sServiceName)

$a_services = _RetrieveServices(@ComputerName)

If Not @error And IsArray($a_services) Then

For $x = 1 To $a_services[0]

$aTemp = StringSplit($a_services[$x], "|")

If $aTemp[1] = $sServiceName Then

Return $aTemp[2]



Return "Service not found"


EndFunc ;==>_GetServiceState

Func _RetrieveServices($s_Machine)

Local Const $wbemFlagReturnImmediately = 0x10

Local Const $wbemFlagForwardOnly = 0x20

Local $colItems = "", $even = 1, $objItem, $services

Local $objWMIService = ObjGet("winmgmts:\\" & $s_Machine & "\root\CIMV2")

If @error Then

MsgBox(16, "_RetrieveServices", "ObjGet Error: winmgmts")



$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Service", "WQL", _

$wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If @error Then

MsgBox(16, "_RetrieveServices", "ExecQuery Error: SELECT * FROM Win32_Service")



If IsObj($colItems) Then

For $objItem In $colItems

If IsArray($services) Then

ReDim $services[uBound($services) + 1]


Dim $services[2]


$services[0] = UBound($services) - 1

;~ $services[uBound($services) - 1] = $objItem.Name

$services[uBound($services) - 1] = $objItem.Name & "|" & $objItem.State


Return $services


EndFunc ;==>_RetrieveServices

Func _SetServiceState($s_pc, $service, $State)

Local Const $wbemFlagReturnImmediately = 0x10

Local Const $wbemFlagForwardOnly = 0x20

Local $colItems = "", $objItem, $ret_status = -1

Local $a_status[25] = ["Success", "Not supported", "Access denied", "Dependent services running", _

"Invalid service control", "Service cannot accept control", "Service not active", "Service request timeout", _

"Unknown failure", "Path not found", "Service already stopped", "Service database locked", "Service dependency deleted", _

"Service dependency failure", "Service disabled", "Service logon failed", "Service marked for deletion", "Service no thread", _

"Status circular dependency", "Status duplicate name", "Status - invalid name", "Status - invalid parameter", _

"Status - invalid service account", "Status - service exists", "Service already paused" ]

If Ping($s_pc) Then

Local $objWMIService = ObjGet("winmgmts:\\" & $s_pc & "\root\CIMV2")

If @error Then

MsgBox(16, "_SetServiceState", "ObjGet Error: winmgmts")



$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Service", "WQL", _

$wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If @error Then

MsgBox(16, "_SetServiceState", "ExecQuery Error: SELECT * FROM Win32_Service")



If IsObj($colItems) Then

For $objItem In $colItems

If $objItem.Name = $service Then


Case $State = "Boot" Or $State = "System" Or $State = "Automatic" Or $State = "Manual" Or $State = "Disabled"

$ret_status = $objItem.ChangeStartMode($State)

Case $State = "Stop"

$ret_status = $objItem.StopService()

Case $State = "Start"

$ret_status = $objItem.StartService()

Case $State = "Pause"

$ret_status = $objItem.PauseService()

Case $State = "Resume"

$ret_status = $objItem.ResumeService()

Case $State = "Delete"

$ret_status = $objItem.Delete()







If $ret_status <> -1 Then

Return $a_status[$ret_status]



Return $ret_status


EndFunc ;==>_SetServiceState

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...