Skip to content

Conversation

Enrico204
Copy link

This pull request add ImpersonateSelf syscall: https://docs.microsoft.com/en-us/windows/win32/api/securitybaseapi/nf-securitybaseapi-impersonateself

This syscall is used in conjunction with others to refer to the current running user. For example:

// This is the new function. Without this call, OpenThreadToken will return an error on current thread
ImpersonateSelf(syscallex.SecurityImpersonation)

defer func() {
	syscallex.RevertToSelf()
}()

var impersonationToken syscall.Token
currentThread := syscallex.GetCurrentThread()
err := syscallex.OpenThreadToken(
	currentThread,
	syscall.TOKEN_ALL_ACCESS,
	1,
	&impersonationToken,
)
if err != nil {
	// handle error
}

permissionGranted, err := winox.UserHasPermission(impersonationToken, winox.RightsRead|winox.RightsWrite, path)

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

Successfully merging this pull request may close these issues.

1 participant