Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Issue with GETENV('UserName')
Message
 
To
09/04/2020 02:40:20
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01674019
Message ID:
01674021
Views:
80
This message has been marked as a message which has helped to the initial question of the thread.
>Your understanding is correct. Environment variables are part of the COMMAND.COM/CMD.EXE shells starting with PC/MS-DOS, designed to enhance batch file programming. GETENV() was (if memory serves) introduced in one of the DOS-based Foxen (FoxBASE+ or FPD).
>
>As your code illustrates, there's no protection for environment variables. Windows distinguishes between "System" and "User" environment variables, but neither are protected. The former are present and set when the system boots, and the latter are set when a user logs on.

I think is worth mentioning that the change will only be valid for the command.com/cmd.exe session where the change was applied, if you start your program from a different command/cmd session or by running the exe, the change in the environment will not apply, but if you think (I mean OP) that is not enough, you can use Win32API
local lcUserName, lnBufferLen
declare GetUserNameA in win32api as GetUserName string   @lpBuffer, integer @pcbBuffer

lcUserName			= SPACE(255)
lnBufferLen			= 255

GetUserName(@lcUserName, @lnBufferLen)

? lcUserName, lnBufferLen
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform