WTS_INFO_CLASS WTSApplication Name returns empty stringWhat is the difference between String and string in C#?How do you convert a byte array to a hexadecimal string, and vice versa?Proper use of 'yield return'String representation of an EnumCase insensitive 'Contains(string)'How do I get a consistent byte representation of strings in C# without manually specifying an encoding?Is it better to return null or empty collection?Returning IEnumerable<T> vs. IQueryable<T>Is it possible to determine the file name of a certificate's private key on a remote Windows server?C# Logon Script: RDP Remote Application get Application Name
Can you perfectly wrap a cube with this blocky shape?
Is it possible to cast two 9th level spells without taking a long rest in 5e?
Will it hurt my career to work as a graphic designer in a startup for beauty and skin care?
What do mathematicians mean when they say some conjecture can’t be proven using the current technology?
Video editor for YouTube
Why did Steve Rogers choose Sam in Endgame?
If a player tries to persuade somebody, what should that creature roll not to be persuaded?
Creating a character, is Noble a class or a background?
What are some symbols representing peasants/oppressed persons fighting back?
Doing research in academia and not liking competition
Can a pizza stone be fixed after soap has been used to clean it?
Should I be able to keep my company purchased standing desk when I leave my job?
Identification of an AC transformer
Why do legislative committees exist?
Mathematica function equivalent to Matlab's residue function (partial fraction expansion)
Is it rude to refer to janitors as 'floor people'?
When does Fisher's "go get more data" approach make sense?
What does it mean to fail a saving throw by 5 or more?
Why does FFmpeg choose 10+20+20 ms instead of an even 16 ms for 60 fps GIF images?
What is this old "lemon-squeezer" shaped pan
Can a Resident Assistant Be Told to Ignore a Lawful Order?
In special relativity is mass just a measure of all other energy than kinetic?
Index Uniqueness Overhead
Why doesn't philosophy have higher standards for its arguments?
WTS_INFO_CLASS WTSApplication Name returns empty string
What is the difference between String and string in C#?How do you convert a byte array to a hexadecimal string, and vice versa?Proper use of 'yield return'String representation of an EnumCase insensitive 'Contains(string)'How do I get a consistent byte representation of strings in C# without manually specifying an encoding?Is it better to return null or empty collection?Returning IEnumerable<T> vs. IQueryable<T>Is it possible to determine the file name of a certificate's private key on a remote Windows server?C# Logon Script: RDP Remote Application get Application Name
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a simple logon script on my Windows Server 2016, which writes data to a db whenever a client connects.
On this server i have published an application, lets say for example microsoft paint.
The client then can use this application remotely once he has set up the connection in Control Panel -> Remote App and Desktop Connections.
Remote app, in our case microsoft paint then shows up in the start menu.
If it is opened a normal remote desktop connection is established and microsoft paint opens remotely.
Now what i want is to get the name of the application, name of the client, time when application is opened and the time when the application is closed and write everything to a database.
The wtsapi32 should provide the functionality i need in retrieving the application name. Inside WTS_INFO_CLASS there is a property WTSApplicationName.
Unfortunately it always returns an empty string.
Other properties like WTSClientAdress return the expected results.
Is there any other way of retrieving the Application Name?
Any help would be greatly appreciated!
Thanks in advance.
public static List<SessionInfo> GetServerActiveSessions(string serverName)
IntPtr server = IntPtr.Zero;
List<SessionInfo> sessionInfos = new List<SessionInfo>();
server = OpenServer(serverName);
if (server != IntPtr.Zero)
try
IntPtr ppSessionInfo = IntPtr.Zero;
Int32 count = 0;
if (WTSEnumerateSessions(server, 0, 1, ref ppSessionInfo, ref count))
Int32 dataSize = Marshal.SizeOf(typeof(WTS_SESSION_INFO));
Int32 current = (int)ppSessionInfo;
for (int i = 0; i < count; i++)
SessionInfo sessionInfo = new SessionInfo();
WTS_SESSION_INFO si = (WTS_SESSION_INFO)Marshal.PtrToStructure((System.IntPtr)current, typeof(WTS_SESSION_INFO));
current += dataSize;
sessionInfo.ApplicationName = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSApplicationName);
sessionInfo.ClientAddress = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientAddress);
sessionInfo.ClientBuildNumber = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientBuildNumber);
sessionInfo.ClientDirectory = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientDirectory);
sessionInfo.ClientDisplay = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientDisplay);
sessionInfo.ClientDirectory = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientDirectory);
sessionInfo.ClientHardwareId = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientHardwareId);
sessionInfo.ClientName = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientName);
sessionInfo.ClientProductId = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientProductId);
sessionInfo.ClientProtocolType = getProtocolType(QuerySessionInfo<short>(server, si.SessionID, WTS_INFO_CLASS.WTSClientProtocolType));
sessionInfo.ConnectState = QuerySessionInfo<WTS_CONNECTSTATE_CLASS>(server, si.SessionID, WTS_INFO_CLASS.WTSConnectState);
sessionInfo.DomainName = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSDomainName);
sessionInfo.InitialProgram = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSInitialProgram);
sessionInfo.OEMId = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSOEMId);
sessionInfo.SessionId = si.SessionID;
sessionInfo.UserName = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSUserName);
sessionInfo.WinStationName = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSWinStationName);
sessionInfo.WorkingDirectory = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSWorkingDirectory);
sessionInfos.Add(sessionInfo);
WTSFreeMemory(ppSessionInfo);
finally
CloseServer(server);
return sessionInfos;
c# remote-desktop terminal-services wtsapi32
add a comment |
I have a simple logon script on my Windows Server 2016, which writes data to a db whenever a client connects.
On this server i have published an application, lets say for example microsoft paint.
The client then can use this application remotely once he has set up the connection in Control Panel -> Remote App and Desktop Connections.
Remote app, in our case microsoft paint then shows up in the start menu.
If it is opened a normal remote desktop connection is established and microsoft paint opens remotely.
Now what i want is to get the name of the application, name of the client, time when application is opened and the time when the application is closed and write everything to a database.
The wtsapi32 should provide the functionality i need in retrieving the application name. Inside WTS_INFO_CLASS there is a property WTSApplicationName.
Unfortunately it always returns an empty string.
Other properties like WTSClientAdress return the expected results.
Is there any other way of retrieving the Application Name?
Any help would be greatly appreciated!
Thanks in advance.
public static List<SessionInfo> GetServerActiveSessions(string serverName)
IntPtr server = IntPtr.Zero;
List<SessionInfo> sessionInfos = new List<SessionInfo>();
server = OpenServer(serverName);
if (server != IntPtr.Zero)
try
IntPtr ppSessionInfo = IntPtr.Zero;
Int32 count = 0;
if (WTSEnumerateSessions(server, 0, 1, ref ppSessionInfo, ref count))
Int32 dataSize = Marshal.SizeOf(typeof(WTS_SESSION_INFO));
Int32 current = (int)ppSessionInfo;
for (int i = 0; i < count; i++)
SessionInfo sessionInfo = new SessionInfo();
WTS_SESSION_INFO si = (WTS_SESSION_INFO)Marshal.PtrToStructure((System.IntPtr)current, typeof(WTS_SESSION_INFO));
current += dataSize;
sessionInfo.ApplicationName = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSApplicationName);
sessionInfo.ClientAddress = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientAddress);
sessionInfo.ClientBuildNumber = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientBuildNumber);
sessionInfo.ClientDirectory = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientDirectory);
sessionInfo.ClientDisplay = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientDisplay);
sessionInfo.ClientDirectory = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientDirectory);
sessionInfo.ClientHardwareId = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientHardwareId);
sessionInfo.ClientName = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientName);
sessionInfo.ClientProductId = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientProductId);
sessionInfo.ClientProtocolType = getProtocolType(QuerySessionInfo<short>(server, si.SessionID, WTS_INFO_CLASS.WTSClientProtocolType));
sessionInfo.ConnectState = QuerySessionInfo<WTS_CONNECTSTATE_CLASS>(server, si.SessionID, WTS_INFO_CLASS.WTSConnectState);
sessionInfo.DomainName = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSDomainName);
sessionInfo.InitialProgram = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSInitialProgram);
sessionInfo.OEMId = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSOEMId);
sessionInfo.SessionId = si.SessionID;
sessionInfo.UserName = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSUserName);
sessionInfo.WinStationName = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSWinStationName);
sessionInfo.WorkingDirectory = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSWorkingDirectory);
sessionInfos.Add(sessionInfo);
WTSFreeMemory(ppSessionInfo);
finally
CloseServer(server);
return sessionInfos;
c# remote-desktop terminal-services wtsapi32
add a comment |
I have a simple logon script on my Windows Server 2016, which writes data to a db whenever a client connects.
On this server i have published an application, lets say for example microsoft paint.
The client then can use this application remotely once he has set up the connection in Control Panel -> Remote App and Desktop Connections.
Remote app, in our case microsoft paint then shows up in the start menu.
If it is opened a normal remote desktop connection is established and microsoft paint opens remotely.
Now what i want is to get the name of the application, name of the client, time when application is opened and the time when the application is closed and write everything to a database.
The wtsapi32 should provide the functionality i need in retrieving the application name. Inside WTS_INFO_CLASS there is a property WTSApplicationName.
Unfortunately it always returns an empty string.
Other properties like WTSClientAdress return the expected results.
Is there any other way of retrieving the Application Name?
Any help would be greatly appreciated!
Thanks in advance.
public static List<SessionInfo> GetServerActiveSessions(string serverName)
IntPtr server = IntPtr.Zero;
List<SessionInfo> sessionInfos = new List<SessionInfo>();
server = OpenServer(serverName);
if (server != IntPtr.Zero)
try
IntPtr ppSessionInfo = IntPtr.Zero;
Int32 count = 0;
if (WTSEnumerateSessions(server, 0, 1, ref ppSessionInfo, ref count))
Int32 dataSize = Marshal.SizeOf(typeof(WTS_SESSION_INFO));
Int32 current = (int)ppSessionInfo;
for (int i = 0; i < count; i++)
SessionInfo sessionInfo = new SessionInfo();
WTS_SESSION_INFO si = (WTS_SESSION_INFO)Marshal.PtrToStructure((System.IntPtr)current, typeof(WTS_SESSION_INFO));
current += dataSize;
sessionInfo.ApplicationName = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSApplicationName);
sessionInfo.ClientAddress = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientAddress);
sessionInfo.ClientBuildNumber = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientBuildNumber);
sessionInfo.ClientDirectory = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientDirectory);
sessionInfo.ClientDisplay = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientDisplay);
sessionInfo.ClientDirectory = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientDirectory);
sessionInfo.ClientHardwareId = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientHardwareId);
sessionInfo.ClientName = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientName);
sessionInfo.ClientProductId = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientProductId);
sessionInfo.ClientProtocolType = getProtocolType(QuerySessionInfo<short>(server, si.SessionID, WTS_INFO_CLASS.WTSClientProtocolType));
sessionInfo.ConnectState = QuerySessionInfo<WTS_CONNECTSTATE_CLASS>(server, si.SessionID, WTS_INFO_CLASS.WTSConnectState);
sessionInfo.DomainName = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSDomainName);
sessionInfo.InitialProgram = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSInitialProgram);
sessionInfo.OEMId = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSOEMId);
sessionInfo.SessionId = si.SessionID;
sessionInfo.UserName = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSUserName);
sessionInfo.WinStationName = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSWinStationName);
sessionInfo.WorkingDirectory = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSWorkingDirectory);
sessionInfos.Add(sessionInfo);
WTSFreeMemory(ppSessionInfo);
finally
CloseServer(server);
return sessionInfos;
c# remote-desktop terminal-services wtsapi32
I have a simple logon script on my Windows Server 2016, which writes data to a db whenever a client connects.
On this server i have published an application, lets say for example microsoft paint.
The client then can use this application remotely once he has set up the connection in Control Panel -> Remote App and Desktop Connections.
Remote app, in our case microsoft paint then shows up in the start menu.
If it is opened a normal remote desktop connection is established and microsoft paint opens remotely.
Now what i want is to get the name of the application, name of the client, time when application is opened and the time when the application is closed and write everything to a database.
The wtsapi32 should provide the functionality i need in retrieving the application name. Inside WTS_INFO_CLASS there is a property WTSApplicationName.
Unfortunately it always returns an empty string.
Other properties like WTSClientAdress return the expected results.
Is there any other way of retrieving the Application Name?
Any help would be greatly appreciated!
Thanks in advance.
public static List<SessionInfo> GetServerActiveSessions(string serverName)
IntPtr server = IntPtr.Zero;
List<SessionInfo> sessionInfos = new List<SessionInfo>();
server = OpenServer(serverName);
if (server != IntPtr.Zero)
try
IntPtr ppSessionInfo = IntPtr.Zero;
Int32 count = 0;
if (WTSEnumerateSessions(server, 0, 1, ref ppSessionInfo, ref count))
Int32 dataSize = Marshal.SizeOf(typeof(WTS_SESSION_INFO));
Int32 current = (int)ppSessionInfo;
for (int i = 0; i < count; i++)
SessionInfo sessionInfo = new SessionInfo();
WTS_SESSION_INFO si = (WTS_SESSION_INFO)Marshal.PtrToStructure((System.IntPtr)current, typeof(WTS_SESSION_INFO));
current += dataSize;
sessionInfo.ApplicationName = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSApplicationName);
sessionInfo.ClientAddress = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientAddress);
sessionInfo.ClientBuildNumber = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientBuildNumber);
sessionInfo.ClientDirectory = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientDirectory);
sessionInfo.ClientDisplay = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientDisplay);
sessionInfo.ClientDirectory = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientDirectory);
sessionInfo.ClientHardwareId = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientHardwareId);
sessionInfo.ClientName = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientName);
sessionInfo.ClientProductId = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSClientProductId);
sessionInfo.ClientProtocolType = getProtocolType(QuerySessionInfo<short>(server, si.SessionID, WTS_INFO_CLASS.WTSClientProtocolType));
sessionInfo.ConnectState = QuerySessionInfo<WTS_CONNECTSTATE_CLASS>(server, si.SessionID, WTS_INFO_CLASS.WTSConnectState);
sessionInfo.DomainName = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSDomainName);
sessionInfo.InitialProgram = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSInitialProgram);
sessionInfo.OEMId = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSOEMId);
sessionInfo.SessionId = si.SessionID;
sessionInfo.UserName = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSUserName);
sessionInfo.WinStationName = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSWinStationName);
sessionInfo.WorkingDirectory = QuerySessionInfo(server, si.SessionID, WTS_INFO_CLASS.WTSWorkingDirectory);
sessionInfos.Add(sessionInfo);
WTSFreeMemory(ppSessionInfo);
finally
CloseServer(server);
return sessionInfos;
c# remote-desktop terminal-services wtsapi32
c# remote-desktop terminal-services wtsapi32
edited Mar 26 at 10:27
calgara12
asked Mar 26 at 7:31
calgara12calgara12
367 bronze badges
367 bronze badges
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55351836%2fwts-info-class-wtsapplication-name-returns-empty-string%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55351836%2fwts-info-class-wtsapplication-name-returns-empty-string%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown