找回密码
 加入
搜索
查看: 2831|回复: 4

[系统综合] 【请教】如何通过wmi卸载软件呢,内有详细代码和图。请各位大侠救命

[复制链接]
发表于 2011-12-21 14:10:27 | 显示全部楼层 |阅读模式
本帖最后由 einiter 于 2011-12-21 15:30 编辑
#region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_icon=C:\WINDOWS\system32\SHELL32.dll|-166
#endregion ;**** 参数创建于 ACNWrapper_GUI ****
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <ACN_NET.au3>
#include <GuiIPAddress.au3>
#include <File.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <WinAPIEx.au3>
#include <GuiMonthCal.au3>
#include <Process.au3>
#include <inet.au3>
#include <ListviewConstants.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>



Local $exStyles = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES) + $LVS_EX_CHECKBOXES
$CHECKS = GUICreate("软件检测", 661, 434, 209, 178)
GUISetIcon("C:\Windows\System32\user32.dll", -6)
$Find = GUICtrlCreateButton("搜索", 40, 24, 99, 25)
;$Uninstall = GUICtrlCreateButton("卸载", 227, 24, 99, 25)
;$ListView1 = _GUICtrlListView_Create($Find, "", 16, 72, 625, 297, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
;_GUICtrlListView_SetExtendedListViewStyle($ListView1, $exStyles)
$ListView1 = GUICtrlCreateListView("", 16, 72, 625, 297)
_GUICtrlListView_AddColumn($ListView1, "名称", 220)
_GUICtrlListView_AddColumn($ListView1, "安装时间", 200)
_GUICtrlListView_AddColumn($ListView1, "版本信息", 200)
_GUICtrlListView_SetExtendedListViewStyle($ListView1, $exStyles)

$progressCheck = GUICtrlCreateProgress(16, 392, 633, 25)
$ExitCheck = GUICtrlCreateButton("退出", 408, 24, 99, 25)

GUISetState(@SW_SHOW)


#endregion ### END Koda GUI section ###
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Find
                        _SHOW()
                Case $ExitCheck
                        ExitLoop
                        
        EndSwitch
WEnd
Func _SHOW()
        Local $wbemFlagReturnImmediately = 0x10
        Local $wbemFlagForwardOnly = 0x20
        Local $strcomputer = "localhost"
        Local $colItems = ""
        Local $objWMIService = ObjGet("winmgmts:\" & $strcomputer & "\root\CIMV2")
        Local $Output, $date, $version
        $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Product", "WQL", _
                        $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
        If IsObj($colItems) Then
                For $objItem In $colItems
                        $Output = $objItem.Caption
                        $date = WMIDateStringToDate($objItem.InstallDate2)
                        $version = $objItem.Version
                        _table($Output, $date, $version)
                        $Output = ""
                Next
        Else
                MsgBox(0, "WMI 输出", "没有在类 " & "Win32_Product" & "中找到WMI对象")
        EndIf
        
EndFunc   ;==>_SHOW

Func _table($NAME, $uname, $version)
        GUICtrlCreateListViewItem($NAME & "|" & $uname & "|" & $version, 4)
EndFunc   ;==>_table
Func WMIDateStringToDate($dtmDate)

        Return (StringMid($dtmDate, 5, 2) & "/" & _
                        StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
                         & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate, 13, 2))
EndFunc   ;==>WMIDateStringToDate
我已经知道使用
$strComputer = "."
$objWMIService = ObjGet("winmgmts:" _
& "!\" _
& $strComputer & "\root\cimv2")
$colSoftware = $objWMIService.ExecQuery _
("Select * from Win32_Product " _
& "Where Name = 'Personnel database'")
For $objSoftware in $colSoftware
$objSoftware.Uninstall()
Next
这种方法可以卸载,但是如何实现卸载一个软件!而且在选中某个软件的时候点击卸载就卸载某个软件。
跪求请教,!!!还望各位大侠帮忙!!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2011-12-22 13:09:59 | 显示全部楼层
天了没有人回复。
发表于 2012-1-6 22:07:01 | 显示全部楼层
不会,帮助顶一下,希望高手看见。
发表于 2012-1-7 11:35:17 | 显示全部楼层
帮助顶一下,希望高手看见
发表于 2012-1-7 15:54:40 | 显示全部楼层
本帖最后由 502762378 于 2012-1-7 16:17 编辑

首先说一下:你给的那个卸载的码有误,是俩双斜杠
WMI获取这个效率貌似不是很高,获取的好像也不是很全,测试卸载了个2007兼容包成功,看看OK否
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Local $wbemFlagReturnImmediately = 0x10
Local $wbemFlagForwardOnly = 0x20
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 426, 419, 192, 124)
$laber1 = GUICtrlCreateLabel("请输入IP", 24, 48, 50, 17)
$Input1 = GUICtrlCreateInput("", 112, 48, 105, 21)
$Button1 = GUICtrlCreateButton("确定", 264, 40, 65, 25)
$ListView1 = GUICtrlCreateListView("名称|版本信息", 16, 80, 393, 321)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 150)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 150)
$listmenu1 = GUICtrlCreateContextMenu($ListView1);给一个控件建上下文菜单(右键菜单)
$menu1 = GUICtrlCreateMenuItem("卸载程序", $listmenu1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        If Ping(GUICtrlRead($Input1),250) Then
                            _SHOW(GUICtrlRead($Input1))
                        Else
                                MsgBox(4096,"你确定对要访问的电脑要权限?","请输入个像样的IP或者电脑名")
                        EndIf
                Case $menu1
                        $chenxu = StringSplit(GUICtrlRead(GUICtrlRead($ListView1)),"|")
                        _uninstall(GUICtrlRead($Input1),$chenxu[1])
                        GUICtrlSetData($ListView1,"")
                        _SHOW(GUICtrlRead($Input1))
        EndSwitch
WEnd

Func _SHOW($ip)
        Local $objWMIService = ObjGet("winmgmts:\" & $ip & "\root\CIMV2")
        $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Product", "WQL", _
                        $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
                For $objItem In $colItems
                        GUICtrlCreateListViewItem($objItem.Caption& "|" & $objItem.Version , $ListView1)
                Next
EndFunc   ;==>_SHOW

Func _uninstall($ip,$name)
$objWMIService = ObjGet("winmgmts:" _ 
& "\" _ 
& $ip & "\root\cimv2") 
$colSoftware = $objWMIService.ExecQuery _ 
("Select * from Win32_Product " _ 
& "Where Name = '"&$name&"'") 
For $objSoftware in $colSoftware 
$objSoftware.Uninstall() 
Next
EndFunc
又测试了下,远程卸载普通权限下user登录下的电脑程序,测试成功,这难道是传说的静默卸载?如果能解决卸载时程序时卡死、show出程序不全就更完美了。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-15 14:10 , Processed in 0.146768 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表