Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need help with writing wrapper for WTSQuerySessionInformationW using WTSSessionInfoEx #86

Open
avaidhyajc opened this issue Jan 27, 2023 · 8 comments

Comments

@avaidhyajc
Copy link

Hi, I am creating an app which requires me to check system lock/unlock state . I cannot use system events as i need to know the current state.I came across https://learn.microsoft.com/en-us/windows/win32/api/wtsapi32/nf-wtsapi32-wtsquerysessioninformationw which when used with WTSSessionInfoEx(25) helps to get session state using sessionFlags.

Given that it's not implemented , i tried my hand to implement SessionInfoEx ; But unfortunately i am not able to do it as i'm quiet new to golang paradigm.

Any help on this with code will be of greater value to me.Thanks in Advance

@dgolub
Copy link
Member

dgolub commented Jan 27, 2023

Is this issue intended as a feature request or a request for help as a contributor? If it's the latter, are there any specific questions that I can answer?

@avaidhyajc
Copy link
Author

@dgolub Thanks for looking into this. For this struct , i implemented an equivalent in go

	type WTSInfoexlevel1 struct {
		SessionId               uint32
		SessionState            uint32
		SessionFlags            int64
		WinStationName          *uint16
		UserName                *uint16
		DomainName              *uint16
		LogonTime               int64
		ConnectTime             int64
		DisconnectTime          int64
		LastInputTime           int64
		CurrentTime             int64
		IncomingBytes           uint32
		OutgoingBytes           uint32
		IncomingFrames          uint32
		OutgoingFrames          uint32
		IncomingCompressedBytes uint32
		OutgoingCompressedBytes uint32
	}
	type WTSInfoEX struct {
		level uint32
		Data  WTSInfoexlevel1
	}

Can you please confirm if this is correct ? Also , if you could convert it into a new feature request , it will be really helpful!

@avaidhyajc
Copy link
Author

I am not sure how should i read SessionFlags . Irrespective of screen lock/unlock events , i always get the value 31244010177691649

@dgolub
Copy link
Member

dgolub commented Jan 27, 2023

So, the strings in this structure are fixed-length strings, not pointers to strings. So, you'd need to do it like this:

WinStationName [WINSTATIONNAME_LENGTH + 1]uint16

@avaidhyajc
Copy link
Author

Would this cause a problem in reading SessionFlags . ? Can you please share the complete struct which you would use to get the values .

@dgolub
Copy link
Member

dgolub commented Jan 27, 2023

No, that's the correct structure to match what you receive from Windows. You'd just need to change those three string fields.

@avaidhyajc
Copy link
Author

It will be great if you could take this as a Feature Request.

Also , i need to launch an application in user context from service for which i need to impersonate token. Can you please point me to the wrapper that will help me to achieve this.

@dgolub
Copy link
Member

dgolub commented Jan 27, 2023

I'll take a look at some point when I've got some time over a weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants