Jump to content

Recommended Posts

Posted (edited)

Hello all,

I'm attempting to create a simple hta that displays the system processes in an option box and then create a button on the same page that will eventually kill th process selected. I just cant the button to work and do anything. Could anyone give me some advice on how to do it. The following is what i have thus far:

<html>
<head>
<title>HTA Test</title>
<HTA:APPLICATION
ID="objTest"
APPLICATIONNAME="HTA Test"
SCROLL="auto"
SINGLEINSTANCE="yes"
>
</head>

<script LANGUAGE="VBScript">

Option Explicit

Dim dblQuotes, strHTML, strComputer, strOption,objWMIService, colProcesses, iTimerID, optionvalue, strSize, strName
Dim strButton, strKillProcess, strKillProcTitle, strCloseOption, objProcess, colProcess
dblQuotes = chr(34)
strHTML = ""
strComputer = "."
strButton = "button"
strKillProcess = "KillProcess"
strKillProcTitle = "Kill Process"
'The following will get a list of the current running processes on the host machine and output them to the HTA window
Sub RefreshList

'strOption = "<option value=" & dblQuotes & optionvalue & dblQuotes & ">" & objProcess.value & "</option>"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process")

'For Each objProcess in colProcesses
' strHTML = strHTML & objProcess.Name & "<BR>"
'Next
'ProcessList.InnerHTML = strOption


optionvalue = 0
strSize = dblQuotes & "3" & dblQuotes
strName = dblQuotes & "MultiListbox" & dblQuotes
document.write("<select size=" & strSize & " name=" & strName &" multiple>")

For Each objProcess in colProcesses
strOption = "<option value=" & dblQuotes & optionvalue & dblQuotes & ">" & objProcess.Name
strCloseOption = "</option>"
optionvalue = optionvalue + 1
document.write(strOption)
document.write(strCloseOption)
Next
document.write("</select>")
document.write("<input id=killbutton type=" & dblQuotes & strButton & dblQuotes &" value=" & dblQuotes & strKillProcTitle & dblQuotes & " name=" & dblQuotes & strKillProcess & dblQuotes & " onClick=" & dblQuotes & strKillProcess & dblQuotes)
document.write(">")

End Sub

'The following will cause the window to refresh itself at a set interval of miliseconds
'refreshList is a sub routine to be called and reloaded every 30000 miliseconds (30 sec)
Sub Window_OnLoad
'RefreshList
iTimerID = window.setInterval("RefreshList", 300)
End Sub

Sub KillProcess
If optionvalue <> 0 Then
Msgbox "You selected Option " & optionvalue & "."
Else
Msgbox "Nothing to display!"
End If
End Sub
</SCRIPT>
<body>
</body>
</html>

Edited by IcemanND
added code tags

Posted

is there a particular reason you are creating the web page dynamically instead of creating it in the body and referencing the objects? I believe that is what is creating your problem.

Posted

How about something like this.

I don't have it refreshing the list because it refreshes as you are trying to select something and you have to start over.

<html>
<head>
<title>HTA Test</title>
<HTA:APPLICATION
ID="objTest"
APPLICATIONNAME="HTA Test"
SCROLL="auto"
SINGLEINSTANCE="yes"
>
</head>

<script LANGUAGE="VBScript">

Option Explicit

Dim dblQuotes, strHTML, strComputer, strOption,objWMIService, colProcesses, iTimerID, optionvalue, strSize, strName
Dim strButton, strKillProcess, strKillProcTitle, strCloseOption, objProcess, colProcess, objOption, objItem
dblQuotes = chr(34)
strHTML = ""
strComputer = "."
strButton = "button"
strKillProcess = "KillProcess"
strKillProcTitle = "Kill Process"

Sub KillProcess
'use the selectindex of the listbox not your optionvalue variable. selectedindex is a 0 based array.
If mainform.MultiListBox.selectedIndex <> 0 Then
Msgbox "You selected Option " & mainform.multilistbox.selectedIndex & "."
Else
Msgbox "Nothing to display!"
End If
End Sub

Sub RefreshList

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process")

'For Each objProcess in colProcesses
' strHTML = strHTML & objProcess.Name & "<BR>"
'Next
'ProcessList.InnerHTML = strOption

optionvalue = 0
'clears the option box of it's list
for each objOption in mainform.item("MultiListBox").Options
if objOption.value<>"" then objOption.RemoveNode
next
'adds the current processes to the option dialog
For Each objProcess in colProcesses
set objOption = Document.createElement("OPTION")
objOption.Text = objProcess.Name
objOption.Value = optionvalue
mainform.item("MultiListBox").add(objOption)
optionvalue=optionvalue+1
Next

End Sub

'The following will cause the window to refresh itself at a set interval of miliseconds
'refreshList is a sub routine to be called and reloaded every 30000 miliseconds (30 sec)
Sub Window_OnLoad
RefreshList
End Sub

</SCRIPT>
<body>
<form name="mainform">
<select size="15" name="MultiListBox"></select>
<button id="killbutton" title="Click to Kill Process" onClick="KillProcess">Kill Process</button>
</form>
</body>
</html>

Posted

Here is a Hta that list all the process running, you can kill any process that it lists.

This refreshen itself every 300 of a second, so it always is updating it display.

Save As ListProcess.hta

 <HEAD><TITLE>   Gsm_List Process</TITLE>
<HTA:APPLICATION ID= "Gsm_List Process"
SCROLL= "Yes"
SCROLLFLAT ="No"
SingleInstance= "Yes"
ShowInTaskbar="Yes"
SysMenu= " No "
Border= " Thin "
BORDERSTYLE = "complex"
INNERBORDER ="No"
Caption="Yes"
WindowState="Normal"
APPLICATIONNAME="Gsm_List Process"
Icon="%Windir%\explorer.exe">
<!-- ================================================ -->
<style>
Body
{
Font-Size:8.25pt;
Font-Weight:Bold;
Font-Family:segoeui,helvetica,verdana,arial;
Color:#000080;
BackGround-Color:Transparent;
filter:progid:DXImageTransform.Microsoft.Gradient
(StartColorStr='#e8e4de', EndColorStr='#c7c3be');
Text-Align:Center;
Vertical-Align:Top;
}
.TKT2
{
width:425px;
Font-Size:8.75pt;
Font-Weight:Bold;
Font-Family:segoeui,helvetica,verdana,arial;
Color:#0926dc;
BackGround-Color:Transparent;
filter:progid:DXImageTransform.Microsoft.Gradient
(StartColorStr='#c7c3be',endColorStr='#e8e4de');
padding-top:1;
padding-bottom:1;
}
.B1
{
Cursor:Hand;
Height:22px;width:45px;
Font-Size:7.95pt;
Font-Weight:Bold;
Font-Family:segoeui,helvetica,verdana,arial;
Color:#006400;
BackGround-Color:Transparent;
filter:progid:DXImageTransform.Microsoft.Gradient
(StartColorStr='#F9F5EF',endColorStr='#B6B2AD');
padding-top:2;
padding-bottom:2;
padding-left:2;
padding-right:2;
margin-right:2;
Border-Top:0px Transparent;
Border-Bottom:1px Transparent;
Border-Left:0px Transparent;
Border-Right:0px Transparent;
}
.B2
{
Cursor:Hand;
Height:22px;width:45px;
Font-Size:7.95pt;
Font-Weight:Bold;
Font-Family:segoeui,helvetica,verdana,arial;
Color:#003264;
BackGround-Color:Transparent;
filter:progid:DXImageTransform.Microsoft.Gradient
(StartColorStr='#F9FAEF',endColorStr='#A5C39C');
padding-top:2;
padding-bottom:2;
padding-left:2;
padding-right:2;
margin-right:2;
Border-Top:0px Transparent;
Border-Bottom:1px Transparent;
Border-Left:0px Transparent;
Border-Right:0px Transparent;
}
TD.BTN2
{
Font-Size:7.95pt;
Font-Weight:Bold;
Font-Family:segoeui,helvetica,verdana,arial;
Color:#006400;
BackGround-Color:Transparent;
filter:progid:DXImageTransform.Microsoft.Gradient
(StartColorStr='#e8e4de',endColorStr='#c7c3be');
padding-top:3;
padding-bottom:3;
padding-left:5;
padding-right:5;
margin-Left:5;
margin-right:5;
}
</style>
<!-- ================================================ -->
<script LANGUAGE='JScript'>window.resizeTo (525,715), window.moveTo (250,75);</SCRIPT>
<script LANGUAGE ="VBScript">
Dim Hta, MB, Mem, Tkill, Uname
Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Wmi :Set Wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Hta = Act.ExpandEnvironmentStrings("%SystemDrive%") & "\ListProcess.hta"
Uname = Act.ExpandEnvironmentStrings("%UserName%")
MB = 1024 * 1024
Function window_onLoad
GetInfo : iTimerID = window.setInterval( " GetInfo" , 300, "VBScript")
Txt1.InnerHtml = Uname & ", Process Running"
Txt2.InnerHtml = Uname & ", Process Running"
End Function
Function GetInfo
For i = (objTable.Rows.Length - 1) to 0 Step -1
myNewRow = document.all.objTable.deleteRow(i)
Next
Set objRow = objTableBody.InsertRow() : objRow.Style.fontWeight ="Bold"
Set objRow = objTable.InsertRow() : objRow.Style.Color ="#9C1111"
Set objCell = objRow.InsertCell() : objCell.InnerText =chr(160) & "Process ID"
Set objCell = objRow.InsertCell() : objCell.InnerText =chr(160) & "Process Name"
Set objCell = objRow.InsertCell() : objCell.InnerText =chr(160) & "Memory Usage"
Set colProcesses = Wmi.ExecQuery("SELECT * FROM Win32_Process")
For Each strProcess in colProcesses
Set objRow = objTableBody.InsertRow()
Set objCell = objRow.InsertCell()
objRow.Style.Color ="#0000C8"
objRow.Style.fontWeight ="Bold"
objCell.InnerText = chr(160) & strProcess.ProcessID
Set objCell = objRow.InsertCell()
objCell.InnerText = chr(160) & strProcess.Name
Set objCell = objRow.InsertCell()
Mem = FormatNumber(strProcess.WorkingSetSize,0,,,-1) / MB
Mem = Left(Mem,4)
objCell.InnerText = chr(160) & Mem & " Mb"
Next
End Function
Function KillTask()
Tkill = InputBox( "Type In The Full Name Of The Process To Kill" ,"Task Kill Process",,5500,4800)
If Tkill <> "" Then
Set colProcessList = Wmi.ExecQuery("Select * from Win32_Process Where Name = '" & Tkill & "'")
For Each objProcess in colProcessList : objProcess.Terminate() : Next
End If
Exit Function
End Function
Function HTAEXIT()
If Fso.FileExists(Hta) Then : Fso.DeleteFile(Hta) : End If
Window.close
Exit Function
End Function
</SCRIPT></Head>
<!-- -->
<body SCROLL="Yes">
<!-- TOP BUTTONS -->
<Table WIDTH="97%" ALIGN="Center"><TD CLASS="BTN2"><TABLE WIDTH="95%" ALIGN="Center">
<TD Style='Margin-Left:3;Margin-Right:3;'>
<input TYPE="button" VALUE="Kill" CLASS="B1" ONCLICK="KillTask()"
OnMouseOver="this.className='B2'" OnMouseOut="this.className='B1'"></TD>
<TD CLASS="BTN2" WIDTH="275" ALIGN="Center"><SPAN ID="Txt1"></SPAN></TD>
<TD Style='Margin-Left:3;Margin-Right:3;'>
<input TYPE="button" VALUE="Exit" CLASS="B1" ONCLICK="HTAEXIT()"
OnMouseOver="this.className='B2'" OnMouseOut="this.className='B1'"></TD>
</Table></TD></Table>
<!-- DISPLAY -->
<TABLE ID ="objTable" Border='1' CLASS="TKT2"><TBODY ID ="objTableBody" CLASS="TKT2">
</TBODY></TABLE>
<!-- BOTTOM BUTTONS -->
<Table WIDTH="97%" ALIGN="Center"><TD CLASS="BTN2"><TABLE WIDTH="95%" ALIGN="Center">
<TD Style='Margin-Left:3;Margin-Right:3;'>
<input TYPE="button" VALUE="Kill" CLASS="B1" ONCLICK="KillTask()"
OnMouseOver="this.className='B2'" OnMouseOut="this.className='B1'"></TD>
<TD CLASS="BTN2" WIDTH="275" ALIGN="Center"><SPAN ID="Txt2"></SPAN></TD>
<TD Style='Margin-Left:3;Margin-Right:3;'>
<input TYPE="button" VALUE="Exit" CLASS="B1" ONCLICK="HTAEXIT()"
OnMouseOver="this.className='B2'" OnMouseOut="this.className='B1'"></TD>
</Table></TD></Table>
</Body>

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...