Solved

Need HTA to kill/reset terminal session or kill process

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

785 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