Solved

Need HTA to kill/reset terminal session or kill process

Posted on 2011-03-04
1
1,027 Views
Last Modified: 2012-05-11
Hi all!

I am struggeling with the next problem. We have 2 terminal servers, receiving ICA and RDP connections from our workers.

I need to get an HTA build where i can select a user from AD (lastname or username), then the script has to go look on the two servers if the user is active and present me on wich server the user is active. Then i need to have a menu, to reset the users session or to view the users processes and let me select what proces to kill.

I have some code to do the first step (let me select a user from AD), but i don't know from where to go there.
Sub Start_Search
	If txtSearchText.Value <> "" Then
	    For Each objOption In lstUsers.Options
	        lstUsers.Remove(objOption.Index)
    	Next
 
		' Determine DNS domain name.
		Set objRootDSE = GetObject("LDAP://RootDSE")
		strDNSDomain = objRootDSE.Get("defaultNamingContext")
		 
		' Use ADO to search Active Directory.
		Set objCommand = CreateObject("ADODB.Command")
		Set objConnection = CreateObject("ADODB.Connection")
		objConnection.Provider = "ADsDSOObject"
		objConnection.Open "Active Directory Provider"
		objCommand.ActiveConnection = objConnection
		strBase = "<LDAP://" & strDNSDomain & ">"
		 
		'Change this to the Netbios Domain Name
		Set objNetwork = CreateObject("WScript.Network")
		strNetBiOSDomain = objNetwork.UserDomain
	
		If optSearchType(0).Checked = True Then
			' Username is selected
	        strFilter = "(&(objectCategory=person)(objectClass=user)(samAccountName=" & txtSearchText.Value & "))"
		Else
			' Last name is selected
	        strFilter = "(&(objectCategory=person)(objectClass=user)(sn=" & txtSearchText.Value & "))"
		End If
		strAttributes = "givenName,sn,sAMAccountName,adsPath"
		strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
		objCommand.CommandText = strQuery
		objCommand.Properties("Page Size") = 1000
		objCommand.Properties("Timeout") = 30
		objCommand.Properties("Cache Results") = False
		Set objRecordSet = objCommand.Execute
		Set objRecordSetArr = objCommand.Execute
	
		If objRecordSet.EOF Then
			MsgBox "Er zijn geen gebruikers gevonden."
		Else
			While Not objRecordSet.EOF
				Set objOption = Document.CreateElement("OPTION")
				objOption.Text = objRecordSet.Fields("givenName").Value & " " & objRecordSet.Fields("sn").Value
				objOption.Value = objRecordSet.Fields("adsPath").Value
				lstUsers.Add objOption
				objRecordSet.MoveNext
			Wend
		End If
	Else
		MsgBox "Voer een zoekterm in."
	End If

Open in new window

0
Comment
Question by:RowaldLaterveer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 35065727
Hi, with the user selected from AD, you can use code like the following to see if that user has an active session on a computer:

strComputer = "RemotePC"
strUserLoginID = "auser"

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colProcessList = objWMIService.ExecQuery("Select Name From Win32_Process Where Name='explorer.exe'")
For Each objProcess In colProcessList
	colProperties = objProcess.GetOwner(strNameOfUser,strUserDomain)
	If LCase(strUserLoginID) = LCase(strNameOfUser) Then MsgBox "Active session"
Next

Open in new window


Then, you can practically run the same code to get the process list for that user, and decide what to terminate.

I don't know about resetting the session though.

Regards,

Rob.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question