WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: Thekub on July 19, 2016, 08:14:00 AM

Title: More 'secure' way of getting current user.
Post by: Thekub on July 19, 2016, 08:14:00 AM
For a while now I have been merely using Environment("UserName") to identify the person running a given script.  This can be spoofed fairly easily and I'm looking for a more definitive means of getting the user name for the person running the script.

In messing around with this and doing some generic searches I found that calling the Kernel32.dll "GetCurrentProcessID" to get the current PID of the script then using the GetOwner method of Win32_Process appears to be a reliable means.

Just wondering if this is as reliable as it appears or if perhaps there might be a similarly reliable means with less code.   
Title: Re: More 'secure' way of getting current user.
Post by: td on July 19, 2016, 08:46:00 AM
There are multiple ways to get the current user account name.  Here is but one taken form the Tech Database:

Code (winbatch) Select
AddExtender("wwwnt34I.dll")
user =wntGetUser(@default)
Message("I am",user)