#include <GuiListView.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $mess
Global $item , $PID
$GUI=GUICreate("ProcessRemountMenegment(WMI)",500, 450, Default, Default,$GUI_SS_DEFAULT_GUI)
$Cuilistview = GUICtrlCreateListView("№|Name|PID ", 10, 10, 280, 350)
$GuiLabelComp = GUICtrlCreateLabel("Ip - addres",300,8,120,30)
$GuiInputComp = GUICtrlCreateInput("",300,30,150,30)
$GuiLabelName = GUICtrlCreateLabel("Name User",300,80,120,30)
$GuiInputName = GUICtrlCreateInput("",300,100,150,30)
$GuiLabelPass = GUICtrlCreateLabel("Pass User",300,150,120,30)
$GuiInputPass = GUICtrlCreateInput("",300,170,150,30)
$GuiLabelPass = GUICtrlCreateLabel("PID",300,200,120,30)
$GuiInputPid = GUICtrlCreateInput("",300,230,150,30)
$GuiButGetProc = GUICtrlCreateButton("Get Proc", 300,280,150,30)
$GuiButKillProc = GUICtrlCreateButton("Kill Proc", 300,330,150,30)
$GuiButStartProc = GUICtrlCreateButton("Start Proc", 10,380,120,30)
$GuiInputStartProc = GUICtrlCreateInput("",170,380,120,30)
ControlDisable($GUI,"",$GuiButKillProc )
ControlDisable($GUI,"",$GuiInputPid )
GUISetState()
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")
$msg = GUIGetMsg()
while $msg <> $GUI_EVENT_CLOSE
$msg = GUIGetMsg()
$iIndex = ControlListView($GUI, "ProcessClose", $Cuilistview, "GetSelected")
$Ret = ControlListView($Gui, "", $CuiListView, "GetText", $iIndex, 2)
if GUICtrlRead ( $CuiListView ) > 0 then
GUICtrlSetData ( $GuiInputPid,$Ret )
endif
Select
Case $msg = $GuiButGetProc
$Comp = GUICtrlRead ($GuiInputComp)
$Name = GUICtrlRead ($GuiInputName)
$Pass = GUICtrlRead ($GuiInputPass)
if $Comp = "." then
_GUICtrlListView_DeleteAllItems($Cuilistview)
_GetProc($Comp,$Name,$Pass)
ControlEnable($GUI,"",$GuiButKillProc)
else
If $Name = "" or $Pass = "" Then
MsgBox(64,"Не заполнены поля", "Не заполнены некоторые поля")
Else
If Ping ($Comp,400) Then
_GUICtrlListView_DeleteAllItems($Cuilistview)
_GetProc($Comp,$Name,$Pass)
ControlEnable($GUI,"",$GuiButKillProc)
Else
MsgBox(16,"Ошибка доступа к компьютеру","Компьютер не доступен. Ошибка №" & @error )
EndIf
EndIf
EndIf
Case $msg = $GuiButKillProc
$Comp = GUICtrlRead ($GuiInputComp)
$Name = GUICtrlRead ($GuiInputName)
$Pass = GUICtrlRead ($GuiInputPass)
$PID = GUICtrlRead ($GuiInputPid)
if $PID = "" then
MsgBox(64,"Не заполнено поле PID", "Не заполнено поле PID")
Else
_ProcClose ($Comp,$Name,$Pass, $PID)
_GUICtrlListView_DeleteAllItems($Cuilistview)
_GetProc($Comp,$Name,$Pass)
GUICtrlSetData($GuiInputPid,"")
EndIf
Case $msg = $GuiButStartProc
$Comp = GUICtrlRead ($GuiInputComp)
$Name = GUICtrlRead ($GuiInputName)
$Pass = GUICtrlRead ($GuiInputPass)
$StartProc = GUICtrlRead ($GuiInputStartProc)
if $Comp = "." then
_StartProc($Comp,$Name,$Pass,$StartProc)
Else
if $Name = "" or $Pass = "" or $StartProc ="" Then
MsgBox(64,"Не заполнены поля", "Не заполнены некоторые поля")
else
_StartProc($Comp,$Name,$Pass,$StartProc)
EndIf
EndIf
EndSelect
wend
Func _ProcClose ($strComputer,$strUser,$strPassword, $ProcName)
$strDomain = "DOMAIN"
$objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator")
if $strComputer = "." then
$objWMIServiceProc= $objSWbemLocator.ConnectServer(".", "Root\CIMV2")
Else
$objWMIServiceProc = $objSWbemLocator.ConnectServer( $strComputer,"root\CIMV2",$strUser,$strPassword,"", "ntlmdomain:" & $strDomain)
EndIf
if Not @error then
$objShare = $objWMIServiceProc.Get("Win32_Process.Handle=" & $ProcName)
$objInParam = $objShare.Methods_("Terminate").inParameters.SpawnInstance_()
$objOutParams = $objWMIServiceProc.ExecMethod("Win32_Process.Handle=" & $ProcName, "Terminate", $objInParam)
Else
EndIf
EndFunc
Func _GetProc($strComputer,$strUser,$strPassword)
$strDomain = "DOMAIN"
$objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator")
if $strComputer = "." then
$objWMIServiceProc= $objSWbemLocator.ConnectServer(".", "Root\CIMV2")
Else
$objWMIServiceProc = $objSWbemLocator.ConnectServer( $strComputer,"root\CIMV2",$strUser,$strPassword,"", "ntlmdomain:" & $strDomain)
EndIf
if Not @error then
$colItems = $objWMIServiceProc.ExecQuery ("SELECT * FROM Win32_Process")
$item1 = 0
For $objItem in $colItems
$item1 +=1
ConsoleWrite ($objItem.Caption & " " & $objItem.Handle & @CR)
$item = GUICtrlCreateListViewItem($item1 &"|" & $objItem.Caption &"|"& $objItem.Handle, $Cuilistview)
Next
Else
EndIf
EndFunc
Func _StartProc($strComputer,$strUser,$strPassword,$strProg)
$strDomain = "DOMAIN"
$objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator")
if $strComputer = "." then
$objWMIServiceProc= $objSWbemLocator.ConnectServer(".", "Root\CIMV2")
Else
$objWMIServiceProc = $objSWbemLocator.ConnectServer( $strComputer,"root\CIMV2",$strUser,$strPassword,"", "ntlmdomain:" & $strDomain)
EndIf
if Not @error then
$objShare = $objWMIServiceProc.Get("Win32_Process")
$objInParam = $objShare.Methods_("Create").inParameters.SpawnInstance_()
$objInParam.Properties_.Item("CommandLine") = $strProg
$objOutParams = $objWMIServiceProc.ExecMethod("Win32_Process", "Create", $objInParam)
Else
EndIf
EndFunc
Func _MacAdr($strComputer,$strUser,$strPassword)
$strDomain = "DOMAIN"
$objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator")
$objWMIServiceProc = $objSWbemLocator.ConnectServer( $strComputer,"root\CIMV2",$strUser,$strPassword,"", "ntlmdomain:" & $strDomain)
$colItems = $objWMIServiceProc.ExecQuery ("SELECT * FROM Win32_NetworkAdapter")
$item1 = 0
For $objItem in $colItems
$item1 +=1
$mess &= $item1 & " " & $objItem.MACAddress & @CR
ConsoleWrite ($item1 & " " & $objItem.MACAddress & " " & $objItem.ProductName & @CR)
Next
MsgBox(1,"",$mess)
EndFunc
Func MyErrFunc()
$HexNumber=hex($oMyError.number,8)
Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
"Number is: " & $HexNumber & @CRLF & _
"Windescription is: " & $oMyError.windescription & @CRLF & _
"Родитель ошибки: " & $oMyError.source )
SetError(1)
Endfunc