Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with WMI Service

Status
Not open for further replies.

malaygal

IS-IT--Management
Feb 22, 2006
192
US
I have this ASP page that lists the jobs(scripts) that are currently running on our web servers
and allows ADMIN users to remotely cancel/abort these jobs (wscript).

Some client machine displays the page correctly, but are not able to remotely cancel the job.
The line (highlighted in red) is raising an error "The remote server machine does not exist or is unavailable: "GetObject"".

Any help will be greatly appreciated.

'********************Start of Code*******************************

<%@ Language=VBScript %>
<% Response.Buffer=False %>
<%'Option Explicit
Response.Expires = -5000
Server.ScriptTimeout =10800

%>

<html>
<head>
<title></title>
<script language="VBScript">

Sub ProcessInfo(PID)

Dim objWMIService, objItem, colItems
Dim strComputer, strProcessKill
Dim intPID

'strComputer = "." 'this did not work

strComputer = "myserver"
strProcessKill = "'wscript.exe'"

intPID = PID

'On Error Resume Next

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & strComputer & "/root/cimv2")
Set colItems = objWMIService.ExecQuery ("Select * from Win32_Process Where ProcessID = " & intPID)

For Each objItem in colItems

strJobName = replace(replace(mid(objItem.CommandLine,instr(objItem.CommandLine,objItem.ExecutablePath)+len(objItem.ExecutablePath)+2,len(objItem.CommandLine)),chr(34),""),"\","/")
strShortJobName = trim(mid(strJobName,instrrev(strJobName,"/") + 1,len(strJobName)))

answer = MsgBox("Abort " & strShortJobName + vbCRlf + "Click ok to proceed. Cancel to abort",vbokCancel,"Abort Process")

if answer = vbCancel then

else
objItem.terminate()
end if
next
end sub

</script>
</head>

<body>
<center>

<%

Dim objWMIService, objItem, colItems
Dim strComputer, strProcessKill
Dim strJobName, strShortJobName
Dim strUserName, strUserDomain

strComputer = "."
strProcessKill = "'wscript.exe'"

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = " & strProcessKill)

For Each objItem in colItems

objItem.GetOwner strUserName, strUserDomain

if instr(objItem.CommandLine,"/") <> 0 or instr(objItem.CommandLine,"\") <> 0 then

strJobName = replace(replace(mid(objItem.CommandLine,instr(objItem.CommandLine,objItem.ExecutablePath)+len(objItem.ExecutablePath)+2,len(objItem.CommandLine)),chr(34),""),"\","/")
strShortJobName = trim(mid(strJobName,instrrev(strJobName,"/") + 1,len(strJobName)))

else
strShortJobName = replace(mid(objItem.CommandLine,instr(objItem.CommandLine," ")+1,len(objItem.CommandLine)),chr(34),"")

end if

%>
</table>
<tr>
<TD ALIGN=CENTER><FONT FACE="Arial" SIZE=1><%=objItem.ProcessID%></FONT></TD>
<TD ALIGN=CENTER><FONT FACE="Arial" SIZE=1><%=objItem.Name%></FONT></TD>-->
<TD ALIGN=CENTER><FONT FACE="Arial" SIZE=1><%=ucase(strShortJobName)%></FONT></TD>
<TD ALIGN=CENTER><FONT FACE="Arial" SIZE=1><%=ucase(strUserName)%></FONT></TD>
<TD ALIGN=CENTER><INPUT TYPE = "BUTTON" value = "ABORT" name="run_button" onClick="ProcessInfo(<%=objItem.ProcessID%>)"></TD>
</TR>
<%

Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top