This might be what you are looking for: https://github.com/VFPX/Win32API/blob/master/samples/sample_554.md
-----Original Message----- From: ProfoxTech [mailto:profoxtech-bounces@leafe.com] On Behalf Of Fred Taylor Sent: Wednesday, October 28, 2020 10:36 AM To: profoxtech@leafe.com Subject: Re: Need way to change user to access protected folder
Hmm, vaguely remember doing this through the API more than 15+ years ago from a VFP app, but I did not take that code with me when I left as my work was ""owned" by my employer. I know it can be done, but I don't remember the details.
Fred
On Wed, Oct 28, 2020 at 2:09 AM Alan Bourke alanpbourke@fastmail.fm wrote:
There's no way to elevate an already running process, so you have to encapsulate that in a separate EXE and run that with elevated permissions.
This could be as simple as creating a batch file and in there use the 'runas' command.
runas /noprofile /user:mymachine\administrator myexe.exe
Then run the batch file from your main VFP executable.
The problem with this is that it's inelegant and prone to prompting for credentials.
You could try doing it in VFP code using the Windows API:
Download the Win32API project from https://github.com/VFPX/Win32API
Extract somewhere and run apiviewer.exe
Search for 'how to start a process as another user'
That should display a VFP program illustrating how to leverage the Windows API to do it. And you're in a world where you now have to worry about the password being stored in plaintext in your program :)
-- Alan Bourke alanpbourke (at) fastmail (dot) fm
On Tue, 27 Oct 2020, at 10:44 PM, Fred Taylor wrote:
Anybody have a way to change the user while an app is running so I can access a protected folder? Haven't done much Windows API in quite some time.
Fred
--- StripMime Report -- processed MIME parts --- multipart/alternative text/plain (text body -- kept) text/html
[excessive quoting removed by server]