vb.net - GetTokenInformation returns invalid SID? -
while following this ran problem.
<dllimport("advapi32.dll", setlasterror:=true)> _ private shared function openprocesstoken(byval processhandle intptr, byval desiredaccess integer, byref tokenhandle intptr) boolean end function <dllimport("advapi32.dll", setlasterror:=true)> _ private shared function gettokeninformation(tokenhandle intptr, tokeninformationclass token_information_class, tokeninformation intptr, tokeninformationlength uinteger, byref returnlength uinteger) boolean end function <dllimport("advapi32.dll", setlasterror:=true)> _ private shared function isvalidsid(sid byte()) boolean end function each p process in process.getprocesses dim processhandle intptr = openprocess(process_query_limited_information, false, p.id) if not processhandle = nothing dim tokenhandle intptr = nothing dim bool boolean = openprocesstoken(processhandle, token_read, tokenhandle) if bool = false dim win32error string = new win32exception(marshal.getlastwin32error).message messagebox.show(win32error) else dim sidlength uinteger = nothing dim sidbyte byte() = nothing dim somebool boolean = gettokeninformation(tokenhandle, token_information_class.tokenuser, nothing, 0, sidlength) if not somebool dim win32error string = new win32exception(marshal.getlastwin32error).message messagebox.show(win32error) ''returns "the data area passed system call small" error. end if redim sidbyte(35) '' hardcoded '35' because it's i'm getting sidlength. somebool = gettokeninformation(tokenhandle, token_information_class.tokenuser, sidbyte, sidbyte.length, sidlength) ''returns true second time. if not somebool dim win32error string = new win32exception(marshal.getlastwin32error).message messagebox.show(win32error) end if if isvalidsid(sidbyte) messagebox.show("valid") else messagebox.show("not valid") end if ''returns invalid sid. (fails)
the first call gettokeninformation fails it's supposed guess... returning "sidlength" value of 36. second call succeeds , sid byte() gets populated, call "isvalidsid" returns false... , can't figure out why, if sidbytes populated successfully, what's problem?
Comments
Post a Comment