Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Call VFP EXE and return value
Message
From
31/07/2020 22:13:53
 
General information
Forum:
C#
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01675453
Message ID:
01675461
Views:
57
Looking briefly at that thread it looks to me that some variables are in play:

- some methods depend on the context of the process trying to get the username
- some people are trying to get it when they're "Run as..."ing under other credentials
- some are trying from a process running on a web server
- some are connecting via VPN or Remote Desktop Services

People made those posts presumably because what they offered worked in their context(s).

You said you tried everything in that thread i.e. all of FlashTrev's plus the one at the end? Note that FlashTrev's code run as is will only return one of the 4 methods (the one that works for him/her).

If none of those methods work, what is the context of your app when it's trying to get that information? Is it running under a logged-in user account, as a service, or ?

*
Re using VFP: IIRC GETENV() is just reading environment variables, which can be changed after a user actually logs on (if you're concerned about security). If you have to use VFP I understand SYS( 0 ) doesn't have that problem, but you do have to parse out the user name portion of what it returns.

If VFP GETENV( ) is actually good enough for you, is there a .Net equivalent such as https://docs.microsoft.com/en-us/dotnet/api/system.environment.getenvironmentvariable?view=netcore-3.1 ?

>Look at the post by FlashTrev He/she put a code that clearly shows that not one of the suggestions work.
>Crazy.
>>UPDATE: within 30 seconds Googling [stackoverflow get windows user name c#] I found https://stackoverflow.com/questions/1240373/how-do-i-get-the-current-username-in-net-using-c
>>
>>>I read tons of threads in the stackoverflow and nobody has a clear answer, or just the answer, to how to get a user name in the C# code. VFP does it very simply. So, VFP is much better than C#. The only thing I like in C# is a compiler which checks the syntax and if a variable is used and how. Otherwise, VFP is better.
>>>
>>>I did think about writing the value in a txt file and then reading it from the C# code. But then I have to make sure that each txt file has a unique name (so that there is no conflict). And then delete the txt file.
>>>There has to be a way to return a value from a VFP exe. But if there is none, then writing to a txt file will be the approach.
>>>Thank you.
>>>
>>>>There's got to be a way to do this cleanly within C#, without needing to resort to this VFP kludge. I don't know the answer but it can't be that hard.
>>>>
>>>>If you really want to be enabled for this bad idea, you could write the value to a file with STRTOFILE() and then read it from C#.
>>>>
>>>>>Hi,
>>>>>
>>>>>I need to call a small VFP .EXE from a C#/.NET code. The VFP project has one .PRG with has just one line:
>>>>>
>>>>>RETURN (GetEnv("UserName")) 
>>>>>
>>>>>
>>>>>How do I call this .EXE from C# code?
>>>>>
>>>>>I called VFP EXE in my C# code before using the Proc syntax. Example:
>>>>>
>>>>>Process Proc = Process.Start(cVfpExeFullPath, "1");
>>>>>
>>>>>
>>>>>But before my VFP EXE didn't have to return anything. So, it was simple.
>>>>>
>>>>>Now I want the VFP EXE to return a value and capture this value in the C# code.
>>>>>
>>>>>How?
>>>>>
>>>>>TIA
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform