Solved

Need HTA to kill/reset terminal session or kill process

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now