Solved

Need HTA to kill/reset terminal session or kill process

Posted on 2011-03-04
1
1,010 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
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

856 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