Hi
Resolved this issue, changed the token name from Ses.SecureToken to the following:
Dim wi As WindowsIdentity = New WindowsIdentity(String.Concat(Ses.WindowsUsername & "@" & Ses.WindowsDomain))
And now instead of using 'IsInRole'
I loop through the WindowsIdentity.Groups, Translate the SID to a name and and do a case select to match the required groups, its as broad as it is long but it works.
For Each Ses As clsGetLoggedInSessions.LoggedInInfo In liSessions.Sessions
If Not (Ses.ConnectionState = WTS_CONNECTSTATE_CLASS.WTSActive) Then Continue For
Dim WI As New WindowsIdentity(Ses.WindowsUsername & "@" & Ses.WindowsDomain)
Dim tmpGrpName As String = ""
For Each Pip As IdentityReference In WI.Groups
Try : tmpGrpName &= Pip.Translate(GetType(NTAccount)).ToString & ","
Catch ex As Exception : Continue For : End Try
Next
Dim tmpDat As DataTable = WMIQueryDataset(String.Format("SELECT * FROM Win32_Process WHERE SessionId='{0}' And Name='{1}'", CUInt(Ses.SessionId).ToString, "calc.exe"))
If (tmpDat.Rows.Count = 0) Then
If (GroupPermissionCheck(tmpGrpName) = False) Then Call StartAppAsUser(Ses.SecurityToken, "C:\Windows\System32\calc.exe")
Else
End If
Next
End Sub
Private Function GroupPermissionCheck(ByVal Grps As String) As Boolean
Dim GroupsToCheck() As String = {"BUILTIN\ADMINISTRATORS", "BUILTIN\POWER USERS", "AKINIKA\DOMAIN ADMINS", "BUILTIN\BACKUP OPERATORS"}
Dim Returnval As Boolean = False
Array.ForEach(GroupsToCheck, Sub(val) If (Grps.IndexOf(val) > -1) Then Returnval = True)
Return True
End Function
Private Sub StartAppAsUser(ByVal SecureToken As IntPtr, CommandPath As String)
Dim ProcInfo As New WindowsApi.PROCESS_INFORMATION
Dim StartInfo As New WindowsApi.STARTUPINFOW
StartInfo.cb = CUInt(Runtime.InteropServices.Marshal.SizeOf(StartInfo))
WindowsApi.CreateProcessAsUser(SecureToken, CommandPath, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, False, 0, IntPtr.Zero, Nothing, StartInfo, ProcInfo)
If Not SecureToken = IntPtr.Zero Then
WindowsApi.CloseHandle(SecureToken)
End If
End Sub