locked
MY CONTRIBUTION #2 TO THIS FORUM: How to launch a URL in Private Browsing/Incognito Mode using VFP RRS feed

  • Question

  • Like I have promised you all that I will be sharing my knowledge that I will be getting while learning Visual Foxpro 9 Professional Edition SP2 so that everyone who is new to VFP or who didn't know about a particular thing which I came to know about while learning VFP Programming will benefit from my posts.

    In my previous question in this forum (which I had asked on February 1, 2016) I had asked 2 Questions regarding launching browser. Although my first question was answered by Tom Borgmann who was kind enough to provide me with a software code in VFP that we can all use to launch a browser he fell short of answering my 2nd Question. But, doing my own research on the web by using Google I learnt about how we can use certain switches or Flags to launch a browser  in a InPrivate or Incognito Mode from the command line. And then started experimenting  as to where we can put these command line switches in the SHELLEXECUTE Code that Tom Borgmann had given as an answer to my aforesaid question in this forum.

    Problem I was facing was: How To launch a Browser like Internet Explorer in InPrivate Browsing Mode or Google Chrome in Incognito Mode and then also have those browsers take us to a particular URL (or Web Address) programmatically thru VFP. So to do it programmatically from within Visual Foxpro I had altered the code provided by Tom Borgmann and made a PROCEDURE (or you can even make a  LAUNCHBROWSER.PRG of it). The first parameter that is passed to this launchbrowser procedure is numeric (either 1 or 2). 1 stands for launching Internet Explorer as your browser and launching it in InPrivate Browsing Mode and if you pass 2 as parameter than Google Chrome will be launched in its Incognito Mode (if IE/Google Chrome are not present in particular directories as mentioned in my launchbrowser procedure given below then my procedure may crash). In fact, till now I have not become knowledgeable enough to know how programmatically (thru VFP) we can know what browsers user have on their PC or even what is the default browser or even where all the browsers could be located. Again, although I have Mozilla Firefox also on my PC and I had learnt that same switch that is used for Internet Explorer can be used for FireFox it failed on my PC. That is, although Firefox is launching itself and taking it to the URL it is not launching itself in "New Private Window" mode of it (which is similar to InPrivate Browsing or Incognito of IE and Chrome respectively). So I removed CASE nBrowserCode=3 (that was meant for FireFox) from my launchbrowser procedure below.

    The second parameter is the URL which you want to open in InPrivate or Incognito Mode.

    If no parameters are passed to launchbrowser it opens Internet Explorer in InPrivate Browsing Mode and takes you to this VFP  Forum's URL.

    But, in the example below I am taking you to my Blog Site on the net by launching IE or Chrome in InPrivate Browsing or Incognito Mode and then taking you to my blog site. As I would continue to get more Knowledgeable about VFP Programming I would continue to post my Contributions in this Forum (and I expect others to do the same so that by sharing our Knowledge we will all benefit. Besides, sharing of code will also benefit in form of saving THOUSANDS OF VALUABLE MAN HOURS. For example, earlier I had asked in this forum (on January 25, 2016) about my problem with GETDIR function (I wanted an option as given by ADIR function which returns a File Name in the CASE it is on the HARD DISK or PenDrive or whatever). But, unfortunately, GETDIR only returns the Directory Name chosen by Users in UPPER CASE. It doesn't have a parameter like ADIR FUNCTION has given. Olaf Doschke gave a very generalized idea (about ADIR function as an answer to my question. But, I had already known about ADIR "1" Switch and I had mentioned it in that question itself). Although Tom Borgmann was kind enough to tell me to try other Non GETDIR approaches and I selected his answer I still faced a severe problem in using his non GETDIR approach of Shell Application. So what I did was I slogged for 1 hour and wrote my own Code of GETDIRECTORY which uses GETDIR function but later converts the result into one which gives you the CASE of the DIRECTORY in AS IS BASIS (that is, the way it is on your Hard Disk, Pen Drive or whatever storage medium). Now, if I share this Software Code of my GETDIRECTORY function over here (IN THIS MSDN VFP FORUM) then all of you will benefit. IT IS NOT THAT TOM BORGMANN OR ENGLISHBOB2 OR OLAF DOSCHKE OR TAMAR E. GRANOR OR  ANYONE OF YOU ARE NOT TALENTED ENOUGH TO WRITE A FUNCTION LIKE GETDIRECTORY WHICH I WROTE SPENDING 1 HOUR OF MINE. YOU TOO CAN EASILY DO IT. BUT, MY POINT IS WHY REINVENT THE WHEEL? WHEN I HAVE ALREADY SPENT 1 HOUR WHY MUST THOUSANDS OF VISUAL FOXPRO PROGRAMMERS ALL OVER THE WORLD SPEND 1 HOUR EACH TO WRITE SUCH A FUNCTION SHOULD THERE BE A NEED FOR THEM TO WRITE SUCH A FUNCTION. AND WE NEVER KNOW WE MAY COME ACROSS THE NEED TO WRITE A PARTICULAR FUNCTION WHICH WE MAY FIND USELESS RIGHT NOW (BUT MAY BE WE WILL NEED THAT PARTICULAR FUNCTION BADLY (LIKE I NEEDED IT IN CASE OF GETDIR NOT RETURNING VALUE OF A DIRECTORY CHOSEN BY USER ON "AS IT IS" BASIS AS PER THE CASE THE DIRECTORY WAS PRESENT ON THE DISK). SO MY SIMPLE POINT THAT I WANT TO PUT ACROSS IS WE ALL WRITE HUNDREDS OF VISUAL FOXPRO FUNCTIONS FOR OUR OWN NEED. BUT, IF WE ARE KIND ENOUGH TO PUBLISH THESE FUNCTIONS IN THIS FORUM (OR IN OUR BLOG) THEN THESE FUNCTIONS (ONCE WRITTEN BY US FOR OUR OWN PURPOSE) WILL BENEFIT TO SAVE THOUSANDS OF MAN HOURS WORLDWIDE. WHY DO EVERY VISUAL FOXPRO PROGRAMMER SPEND TIME IN WRITING A FEW LINES OF CODE WHEN ALREADY SOME OTHER VISUAL FOXPRO PROGRAMMER HAS PUT IN EFFORTS TO MAKE THE SAME CODE FOR HIS/HER PURPOSE.

    IT IS TRUE THAT RIGHT NOW (LIKE OLAF DOSCHKE FELT) YOU MAY FEEL "WHY IS THERE A NEED FOR SOMEONE TO KNOW THE EXACT CASE OF A DIRECTORY CHOSEN BY USER BY USING GETDIR() FUNCTION. AFTER ALL, DOES CASE MATTER? VERY TRUE. FOR MOST OF OUR VISUAL FOXPRO APPLICATIONS CASE OF A DIRECTORY (HOW IT HAS BEEN MADE AS PER CASE SENSITIVITY) DOESN'T MATTER. BUT, FOR SOME APPLICATIONS IT MAY MATTER. KINDLY DON'T UNDERESTIMATE ME TO BE A FOOL WHO WOULD SPEND 10 MINUTES TYPING AND ASKING FOR A SOLUTION TO A PROBLEM IN THIS FORUM FOR NO GOOD PURPOSE. SO KINDLY UNDERSTAND THAT ALTHOUGH YOU MAY NOT FEEL THE NEED FOR KNOWING CASE SENSITIVITY OF A DIRECTORY ON A USER'S PC RIGHT NOW; IN FUTURE YOU MAY FIND MY GETDIRECTORY FUNCTION (WHICH RETURNS THE VALUE (AS PER THE WAY THE DIRECTORY EXISTS ON YOUR USER'S PC) USEFUL! I WOULDN'T HAVE SPENT 1 HOUR OF MY TIME TYPING ALL THAT SOFTWARE CODE WRITTEN IN VISUAL FOXPRO TO ACHIEVE THIS PURPOSE IF I HAD NOT FACED PROBLEM USING SHELL.APPLICATION CODE GIVEN TO ME AS ONE OF THE SEVERAL ANSWERS (WHOSE LINK HAS BEEN GIVEN AS ANSWER TO MY QUESTION BY MR. TOM BORGMANN AS AN ANSWER TO THAT QUESTION OF MINE ON GETDIR() CASE SENSITIVITY PROBLEM). I AM SURE THAT IF MICROSOFT WERE TO MAKE VISUAL FOXPRO 10 OR HIGHER THEY MIGHT HAVE GIVEN DUE THOUGHT TO MY GETDIR() REQUIREMENT OF GETTING A CASE SENSITIVE DIRECTORY NAME.

    Kindly read this article http://telecom.economictimes.indiatimes.com/news/microsoft-likes-youths-virus-app-offers-him-56-lakh-job-offer/50835404

    This youth from a small town in India wrote a software code and sent it to Microsoft's HeadQuarters and got a job offer from Microsoft. THIS NEWS ITEM TELLS US THAT MICROSOFT DOES GIVE A LENDING EAR AND HEARS AND TAKES THINGS SERIOUSLY! So if Microsoft were to launch VFP 10 or higher why wouldn't it take note of user's need. After all, even the ADIR Switch "1" that Microsoft introduced from VFP 7 onwards (if I am not mistaken) may have come into existence because many users might have either given Microsoft a Feedback or a Complaint that a normal ADIR() function which was in existence since Foxpro 2.0 for DOS was just returning file names or directory names in UPPER CASE only and people using VFP had the need to have an ADIR() which return names of Files/Folders in CASE SENSITIVE manner. IN FACT, I WOULD ALWAYS MAINTAIN THAT IT WAS NOT A RIGHT DECISION OF MICROSOFT TO STOP VISUAL FOXPRO NEWER VERSIONS WHICH LEFT MILLIONS OF VISUAL FOXPRO PROGRAMMERS ORPHANED AND DEVOID THEM OF THEIR LIVELIHOOD. AND SIMPLY ASKING THEM TO REWRITE THEIR APPLICATIONS IN VISUAL BASIC OR LEARN VISUAL BASIC (WITH A STEEP LEARNING CURVE) MAY NOT HAVE BEEN PROPER ON PART OF MICROSOFT. I WOULD SAY EVEN IF MICROSOFT WAS NOT INTERESTED IN MAKING ANY NEW VERSIONS OF VISUAL FOXPRO AS THEY FELT THAT IT DIDN'T HAVE ANY FUTURE OR VISUAL FOXPRO DIDN'T HAVE POTENTIAL TO FETCH THEM BILLIONS OF DOLLARS OR FORMED MINISCULE PORTION OF THEIR REVENUES THEN EVEN IN SUCH A CASE MICROSOFT MUST HAVE SOLD VISUAL FOXPRO SOURCE CODE TO SOME OTHER SMALL COMPANY OR MUST HAVE HAD THE GRACE TO MAKE VISUAL FOXPRO SOURCE CODE PUBLIC (LIKE OPEN SOURCE) AS MICROSOFT HAD ALREADY MADE MILLIONS OF DOLLARS (IF NOT BILLIONS) BY SELLING PREVIOUS VERSIONS OF VISUAL FOXPRO SINCE IT TOOK FOXPRO FROM FOX HOLDINGS. BOTH INDIA AND UNITED STATES ARE DEMOCRACIES AND MY AFORESAID OPINION MUST BE RESPECTED AS CONSTITUTION OF BOTH COUNTRIES GIVE US RIGHT FOR "FREEDOM OF SPEECH". SO I JUST VOICED MY VIEWS ABOUT WHY WHY I FEEL MICROSOFT MUST HAVE SOLD OUT VISUAL FOXPRO TO SOME OTHER COMPANY OR MADE IT OPEN SOURCE (SO THAT MANY OTHER TALENTED PROGRAMMERS WHO MAY KNOW C++ AS WELL COULD IMPROVE VISUAL FOXPRO AND MAY LAUNCH VISUAL FOXPRO 10 OR HIGHER JUST LIKE SOMEONE MADE REDHAT LINUX AND THINGS LIKE THAT.

    I feel that many good Visual Foxpro Programmers must write nice applications using Visual Foxpro and send it over to Microsoft HeadQuarters like the above boy did and plead Microsoft to make either new versions of Visual Foxpro or sell it off to some other companies so that they can make new versions of Visual Foxpro or make Visual Foxpro Source code OpenSource (as it is Microsoft would anyways not get any revenues whatsoever from Visual Foxpro if it kills it! Then, why not show the grace to make its source code public so that independent C++ programmers may maintain it and release their own Future versions of Visual Foxpro like RedHat Linux was made. MICROSOFT MUST THINK OVER MY SUGGESTION.

    VISUAL FOXPRO PROGRAMMERS WHO VISIT THIS FORUM MUST ALSO THINK OVER MY SUGGESTION OF MAKING PUBLIC THEIR VARIOUS FUNCTIONS (THAT THEY MIGHT HAVE MADE FOR THEIR OWN PURPOSE) SO THAT THOUSANDS OF MAN HOURS COULD BE SAVED WORLDWIDE.

    Anyways, here's my source code for launching a browser in InPrivate Browsing Mode or Incognito Mode and taking the user to a particular URL:


    DO launchbrowser WITH 1,"https://anitamallyamumbai.wordpress.com/"

    DO launchbrowser WITH 2,"https://anitamallyamumbai.wordpress.com/"

    PROC launchbrowser
    PARAMETERS nBrowserCode,lcUrl

    *lcUrl = [https://social.msdn.microsoft.com/Forums/en-US/home?forum=visualfoxprogeneral]

    IF EMPTY(nBrowserCode) OR nBrowserCode<1 OR nBrowserCode>2
    nBrowserCode=1
    ENDIF

    IF EMPTY(lcUrl)
    lcUrl = [https://social.msdn.microsoft.com/Forums/en-US/home?category=visualfoxpro]
    ENDIF


    * declare API-function 'ShellExecute'

    DECLARE ShellExecute IN shell32.dll Integer, String, String, String, String, Integer

    * let windows decide, which app computes URLs
    *ShellExecute( 0 , [open] , lcUrl , [] , [] , 1 )

    DO case
    CASE nBrowserCode=1

    ShellExecute( 0 , [open] , "C:\Program Files\Internet Explorer\iexplore.exe" , " -private "+lcUrl ,[] , 1 )

    CASE nBrowserCode=2
    ShellExecute( 0 , [open] , "C:\Program Files\Google\Chrome\Application\chrome.exe" , " -incognito "+lcUrl ,[] , 1 )

    ENDCASE

    * undeclare API-function
    CLEAR DLLS [ShellExecute]

    Thursday, February 4, 2016 10:04 AM

Answers

  • > it is true that right now (like olaf doschke felt) you may feel "why is there a need for someone to know the exact case of a directory chosen by user by using getdir() function.

    Could you please take the time to read through what I wrote in that other thread?

    Overall you come over as a helpful contributor, actually you are too worried to be of value here and to amortize your debt of asking questions by contributing answers, don't be worried, even just asking contributes a question - ideally with a solution - which others may find later and profit from.

    First of all, you give a roundup of the answers you were given and we know these answers by following your threads. Then you don't need to contribute anything not asked for, if you feel the urge, rather write in a blog and refer to its new article.

    There are many contributions others here make in VFPX at codeplex and in the download section of UT (universal thread), besides blog articles and others. You could have found all this and more, at least some of it before saying you see no contributions here. Every answer is a contribution. The main concept of this (and any) forum is to answer questions, don't feel you need to contribute your solutions, just because you can't answer other questions right now. It's fully understandable you're at the stage of the learning curve being rather steep, we help you climb this and you can contribute back later.

    Bye, Olaf.


    Olaf Doschke - TMN Systemberatung GmbH

    http://www.tmn-systemberatung.de


    Friday, February 5, 2016 6:45 PM

All replies

  • Anita,

    Are you aware that typing in CAPITALS on a community site (especially for long periods) is taken as shouting! And is considered impolite.


    The English Bob

    Thursday, February 4, 2016 12:19 PM
    Answerer
  • Bob,

    I am sorry about typing a lot of things in CAPITALS. And sometimes I go on typing with flow of my thoughts and forget about changing the case. Again, I am also quite illiterate about Online Forum/Community Norms. In fact, I am even unaware about Western Culture as such. So I am not even aware about Western manners, Etiquette, etc. And I am really sorry if any of you are finding me troublesome or something like that. Or some of you may even find me funny or weird (like Tamar E. Granor once said). But, I would like to make it quite clear that I am not here to offend anyone. I am here to get help and help others in the truest sense. So I am really sorry if some of you felt that I am shouting or I am impolite. I didn't meant to be impolite as such.

    Please do read my questions and answer them and PLEASE DO NOT DISCRIMINATE ME OR SOCIALLY BAN ME FROM THIS FORUM. I am looking forward to all of you to help me out while I am trying to understand how to accomplish things using Visual Foxpro 9 Professional Edition.

    Anita.

    Thursday, February 4, 2016 5:21 PM
  • Anita, that's interesting information about opening the browser in private mode.  You might make a few changes, though, which would make your launchbrowser function more general.  First, you might want to add the ability to use browsers other than Explorer and Chrome.  You might want to add Opera, Firefox, Safari, and Edge for example.  Second, you don't really know for sure what the directory to an executable file will be.  I'm pretty sure that you can launch a browser and website by "opening" the web address rather than opening the browser itself.  What would be really nice to do is detect the user's default browser, and then construct the correct string to open that browser in private mode.

    Kevin Clark

    Thursday, February 4, 2016 9:04 PM
  • Anita,

    We all at this forum salute your helping and inspiring spirit.

    Have you tried the Microsoft Web Browser Activex Control?

    But I don't know if it supports inprivate browsing.

    Friday, February 5, 2016 8:47 AM
    Answerer
  • > it is true that right now (like olaf doschke felt) you may feel "why is there a need for someone to know the exact case of a directory chosen by user by using getdir() function.

    Could you please take the time to read through what I wrote in that other thread?

    Overall you come over as a helpful contributor, actually you are too worried to be of value here and to amortize your debt of asking questions by contributing answers, don't be worried, even just asking contributes a question - ideally with a solution - which others may find later and profit from.

    First of all, you give a roundup of the answers you were given and we know these answers by following your threads. Then you don't need to contribute anything not asked for, if you feel the urge, rather write in a blog and refer to its new article.

    There are many contributions others here make in VFPX at codeplex and in the download section of UT (universal thread), besides blog articles and others. You could have found all this and more, at least some of it before saying you see no contributions here. Every answer is a contribution. The main concept of this (and any) forum is to answer questions, don't feel you need to contribute your solutions, just because you can't answer other questions right now. It's fully understandable you're at the stage of the learning curve being rather steep, we help you climb this and you can contribute back later.

    Bye, Olaf.


    Olaf Doschke - TMN Systemberatung GmbH

    http://www.tmn-systemberatung.de


    Friday, February 5, 2016 6:45 PM