Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Call VFP EXE and return value
Message
 
 
To
31/07/2020 22:13:53
General information
Forum:
C#
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01675453
Message ID:
01675467
Views:
53
I agree that for some people some settings work. But for me, on the customer server, so far, not one worked.
Note that I cannot have "Run as" for my project since my ASP.NET page will be opened by anybody in the organization. And my goal is that the code of the page "knows" the username of whoever opened it.
The customer assured me that all of their employees log into the PC/AD so there must be a valid username on each PC.

As far as FlashTrev's no. 4 approach that works. He put in the comment of this line that it relies on some ASP Log or something like this. I need my approach to work without any log in into the ASP.NET.

My page runs on their web server. I created a web site MyApp and run the page as :
http://servername/testad.aspx 
I may have to learn to create Console application in the VS (I have done it many years ago and of course forgot how to). And then I will test various values from a console app instead of a web app.

>>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 ?
The page runs under Windows authentication. And everybody in this organization can open this page. I actually test with a project manager when I ask her to open the testad.aspx page to compare to my values.

As far as VFP GETENV(), I didn't know that the username can be changed by user. But I am willing to take a chance on using VFP; unless I am lucky to make the ASP.NET work. Security is not a major issue. This page is used for facilities work orders.

If you have any other ideas, please let me know.

Thank you very much!

>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
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform