Stopping a Service or Killing a Process with VBScript and WMI in ASP 
Author Message
 Stopping a Service or Killing a Process with VBScript and WMI in ASP

I have an ASP page that displays a lot of info regarding processes and
services.  The value of varArray(2, i) in fWriteTableProcesses is the PID of
the Process, which I hope to use to kill the process.  The value of
varArray(8, i) in fWriteTableServices is the Service Name (not Service
Display name),
which I hope to use to stop/start the service.  As you can see the last <TD>
in each, fWriteTableServices and
fWriteTableProcesses =
http://url/path/server.asp?procHandle=PID&server=Nameoftargetserver or
http://url/path/server.asp?svcHandle=ServiceName&server=Nameoftargets....
How would I go about coding the Kill Process and Stop/Start functions?
I know next to nothing about ASP and am an amateur VBScripter.  Any help or
suggestion of a good ASP book would be appreciated.

-TIA
JM

query = "select displayname, state, startmode, servicetype, status,
startname, acceptpause, acceptstop, name " _
& "from win32_service"

'
' Execute the query and create the objInstance object
'
Set objInstance = objService.ExecQuery(query)

'
' Get the item count within ojbInstance and redimension the array
'
itemCount = objInstance.Count - 1
If itemCount > 1 Then
ReDim arrServices(8, CInt(itemCount))
Else
ReDim arrServices(8, 1)
End If
aCounter = 0

'
' Populate the array
'
For Each item In objInstance
arrServices(0, aCounter) = item.DisplayName
arrServices(1, aCounter) = item.State
arrServices(2, aCounter) = item.StartMode
arrServices(3, aCounter) = item.serviceType
arrServices(4, aCounter) = item.Status
arrServices(5, aCounter) = item.startname
arrServices(6, aCounter) = item.acceptPause
arrServices(7, aCounter) = item.acceptStop
arrServices(8, aCounter) = item.Name
aCounter = aCounter + 1
Next
Set objInstance = Nothing

'
' Write the Services heading and the column headings
'
fWriteHeading ("Services - " & ubound(arrServices, 2) + 1)
response.Write _
" <tr align=center bgcolor=#b6b6b6>" & vbCrLf & _
" <td class=category nowrap>Name</td>" & vbCrLf & _
" <td class=category nowrap>State</td>" & vbCrLf & _
" <td class=category nowrap>Start Mode</td>" & vbCrLf & _
" <td class=category nowrap>Type</td>" & vbCrLf & _
" <td class=category nowrap>Status</td>" & vbCrLf & _
" <td class=category nowrap>Start Name</td>" & vbCrLf & _
" <td class=category nowrap>Svc Mgmt</td>" & vbCrLf & _
" </tr>" & vbCrLf

I've added a cell to each row with a link to KILL a process or Stop/Start a
Service:

 Private Sub fWriteTableProcesses(varArray)

'
' Takes an array and writes the processes section of the page
'
For i = 0 To UBound(varArray, 2)
response.Write _
" <tr>" & vbCrLf & _
" <TD bgcolor=#cccccc align=left class=result><a href=" & scriptPath &
"?procHandle=" & varArray(2, i) _
& "&server=" & strServer & ">" & varArray(0, i) & "</a></TD>" & vbCrLf & _
" <TD bgcolor=#99ccff align=center class=result>" & varArray(1, i) & "</TD>"
& vbCrLf & _
" <TD bgcolor=#cccccc align=center class=result>" & varArray(2, i) & "</TD>"
& vbCrLf & _
" <TD bgcolor=#99ccff align=center class=result>" & varArray(3, i) & "</TD>"
& vbCrLf & _
" <TD bgcolor=#cccccc align=center class=result>" & varArray(4, i) & "</TD>"
& vbCrLf & _
" <TD bgcolor=#99ccff align=center class=result>" & varArray(5, i) & "</TD>"
& vbCrLf & _
" <TD bgcolor=#cccccc align=center class=result><a href=" & scriptPath2 &
"server.asp?procHandle=" & varArray(2, i) _    'The Link that kills a
process.
& "&server=" & strServer & ">Kill</a></TD>" & vbCrLf & _
" </tr>" & vbCrLf
Next

End Sub
'_________________________________________________________________________

Private Sub fWriteTableServices(varArray)

'
' Takes an array and writes the services section of the page
'
For i = 0 To UBound(varArray, 2)
response.Write _
" <tr>" & vbCrLf & _
" <TD bgcolor=#cccccc align=left class=result>" & varArray(0, i) & "</td>" &
vbCrLf & _
" <TD bgcolor=#99ccff align=center class=result>" & varArray(1, i) & "</TD>"
& vbCrLf & _
" <TD bgcolor=#cccccc align=center class=result>" & varArray(2, i) & "</TD>"
 & vbCrLf & _
" <TD bgcolor=#99ccff align=center class=result nowrap>" & varArray(3, i) &
"</TD>" & vbCrLf & _
" <TD bgcolor=#cccccc align=center class=result>" & varArray(4, i) & "</TD>"
& vbCrLf & _
" <TD bgcolor=#99ccff align=center class=result>" & varArray(5, i) & "</TD>"
& vbCrLf & _
" <TD bgcolor=#cccccc align=center class=result><a href=" & scriptPath2 &
"server.asp?svcHandle=" & cstr(varArray(8, i)) _  ' The link that stop/start
a Svc
& "&server=" & strServer & ">Stop/Start</a></TD>" & vbCrLf & _
" </tr>" & vbCrLf
Next

End Sub



Mon, 11 Aug 2003 22:09:00 GMT  
 Stopping a Service or Killing a Process with VBScript and WMI in ASP
I've been working on the my problem have finished the Process killing
function.  I will post the code when I'm done with Service stop/start.


Quote:
> I have an ASP page that displays a lot of info regarding processes and
> services.  The value of varArray(2, i) in fWriteTableProcesses is the PID
of
> the Process, which I hope to use to kill the process.  The value of
> varArray(8, i) in fWriteTableServices is the Service Name (not Service
> Display name),
> which I hope to use to stop/start the service.  As you can see the last
<TD>
> in each, fWriteTableServices and
> fWriteTableProcesses =
> http://url/path/server.asp?procHandle=PID&server=Nameoftargetserver or

http://url/path/server.asp?svcHandle=ServiceName&server=Nameoftargets....
Quote:
> How would I go about coding the Kill Process and Stop/Start functions?
> I know next to nothing about ASP and am an amateur VBScripter.  Any help
or
> suggestion of a good ASP book would be appreciated.

> -TIA
> JM

> query = "select displayname, state, startmode, servicetype, status,
> startname, acceptpause, acceptstop, name " _
> & "from win32_service"

> '
> ' Execute the query and create the objInstance object
> '
> Set objInstance = objService.ExecQuery(query)

> '
> ' Get the item count within ojbInstance and redimension the array
> '
> itemCount = objInstance.Count - 1
> If itemCount > 1 Then
> ReDim arrServices(8, CInt(itemCount))
> Else
> ReDim arrServices(8, 1)
> End If
> aCounter = 0

> '
> ' Populate the array
> '
> For Each item In objInstance
> arrServices(0, aCounter) = item.DisplayName
> arrServices(1, aCounter) = item.State
> arrServices(2, aCounter) = item.StartMode
> arrServices(3, aCounter) = item.serviceType
> arrServices(4, aCounter) = item.Status
> arrServices(5, aCounter) = item.startname
> arrServices(6, aCounter) = item.acceptPause
> arrServices(7, aCounter) = item.acceptStop
> arrServices(8, aCounter) = item.Name
> aCounter = aCounter + 1
> Next
> Set objInstance = Nothing

> '
> ' Write the Services heading and the column headings
> '
> fWriteHeading ("Services - " & ubound(arrServices, 2) + 1)
> response.Write _
> " <tr align=center bgcolor=#b6b6b6>" & vbCrLf & _
> " <td class=category nowrap>Name</td>" & vbCrLf & _
> " <td class=category nowrap>State</td>" & vbCrLf & _
> " <td class=category nowrap>Start Mode</td>" & vbCrLf & _
> " <td class=category nowrap>Type</td>" & vbCrLf & _
> " <td class=category nowrap>Status</td>" & vbCrLf & _
> " <td class=category nowrap>Start Name</td>" & vbCrLf & _
> " <td class=category nowrap>Svc Mgmt</td>" & vbCrLf & _
> " </tr>" & vbCrLf

> I've added a cell to each row with a link to KILL a process or Stop/Start
a
> Service:

>  Private Sub fWriteTableProcesses(varArray)

> '
> ' Takes an array and writes the processes section of the page
> '
> For i = 0 To UBound(varArray, 2)
> response.Write _
> " <tr>" & vbCrLf & _
> " <TD bgcolor=#cccccc align=left class=result><a href=" & scriptPath &
> "?procHandle=" & varArray(2, i) _
> & "&server=" & strServer & ">" & varArray(0, i) & "</a></TD>" & vbCrLf & _
> " <TD bgcolor=#99ccff align=center class=result>" & varArray(1, i) &
"</TD>"
> & vbCrLf & _
> " <TD bgcolor=#cccccc align=center class=result>" & varArray(2, i) &
"</TD>"
> & vbCrLf & _
> " <TD bgcolor=#99ccff align=center class=result>" & varArray(3, i) &
"</TD>"
> & vbCrLf & _
> " <TD bgcolor=#cccccc align=center class=result>" & varArray(4, i) &
"</TD>"
> & vbCrLf & _
> " <TD bgcolor=#99ccff align=center class=result>" & varArray(5, i) &
"</TD>"
> & vbCrLf & _
> " <TD bgcolor=#cccccc align=center class=result><a href=" & scriptPath2 &
> "server.asp?procHandle=" & varArray(2, i) _    'The Link that kills a
> process.
> & "&server=" & strServer & ">Kill</a></TD>" & vbCrLf & _
> " </tr>" & vbCrLf
> Next

> End Sub
> '_________________________________________________________________________

> Private Sub fWriteTableServices(varArray)

> '
> ' Takes an array and writes the services section of the page
> '
> For i = 0 To UBound(varArray, 2)
> response.Write _
> " <tr>" & vbCrLf & _
> " <TD bgcolor=#cccccc align=left class=result>" & varArray(0, i) & "</td>"
&
> vbCrLf & _
> " <TD bgcolor=#99ccff align=center class=result>" & varArray(1, i) &
"</TD>"
> & vbCrLf & _
> " <TD bgcolor=#cccccc align=center class=result>" & varArray(2, i) &
"</TD>"
>  & vbCrLf & _
> " <TD bgcolor=#99ccff align=center class=result nowrap>" & varArray(3, i)
&
> "</TD>" & vbCrLf & _
> " <TD bgcolor=#cccccc align=center class=result>" & varArray(4, i) &
"</TD>"
> & vbCrLf & _
> " <TD bgcolor=#99ccff align=center class=result>" & varArray(5, i) &
"</TD>"
> & vbCrLf & _
> " <TD bgcolor=#cccccc align=center class=result><a href=" & scriptPath2 &
> "server.asp?svcHandle=" & cstr(varArray(8, i)) _  ' The link that
stop/start
> a Svc
> & "&server=" & strServer & ">Stop/Start</a></TD>" & vbCrLf & _
> " </tr>" & vbCrLf
> Next

> End Sub



Wed, 13 Aug 2003 06:12:37 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. killing apps and stopping a service with a script

2. Killing a process in NT (without using WMI)

3. Use WMI to list running processes - Can't open Kill.vbs

4. Using WMI to obtain dependent services (restarting services and all dependent services)

5. Strange behavior of VBscript/WMI into ASP (compared to VBscript/WMI into client-side application)

6. Killing a process and all its children processes....

7. Killing a process and all its children processes....

8. VBScript Logon Script kills launched process!!!

9. Killing a process with vbscript

10. Need Help with killing a process using VBScript

11. Killing a Process using VBScript

12. Stop processing of ASP-script

 

 
Powered by phpBB® Forum Software