Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Error using wscript.shell
Message
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Miscellaneous
Thread ID:
01666259
Message ID:
01666566
Views:
57
I would suggest replacing FindWindow(0,_SCREEN.caption) with _VFP.hWnd as OP is using VFP 9 and removes possible ambiguity

>You don't need the scripting shell for that. Just use the ShellExecute API call for that. Much easier, less resource intensive and without the flakey and often failing scripting shell component (which may not work depending on machine permissions).
>
>
>
>****************************************************
>FUNCTION GoUrl
>******************
>***    Author: Rick Strahl
>***            (c) West Wind Technologies, 1996
>***   Contact: rstrahl@west-wind.com
>***  Modified: 03/14/96
>***  Function: Starts associated Web Browser
>***            and goes to the specified URL.
>***            If Browser is already open it
>***            reloads the page.
>***    Assume: Works only on Win95 and NT 4.0
>***      Pass: tcUrl  - The URL of the site or
>***                     HTML page to bring up
>***                     in the Browser
>***    Return: 2  - Bad Association (invalid URL)
>***            31 - No application association
>***            29 - Failure to load application
>***            30 - Application is busy 
>***
>***            Values over 32 indicate success
>***            and return an instance handle for
>***            the application started (the browser) 
>****************************************************
>LPARAMETERS tcUrl, tcAction, tcDirectory, tcParms
>
>IF EMPTY(tcUrl)
>   RETURN -1
>ENDIF
>IF EMPTY(tcAction)
>   tcAction = "OPEN"
>ENDIF
>IF EMPTY(tcDirectory)
>   tcDirectory = SYS(2023) 
>ENDIF
>
>DECLARE INTEGER ShellExecute ;
>    IN SHELL32.dll ;
>    INTEGER nWinHandle,;
>    STRING cOperation,;
>    STRING cFileName,;
>    STRING cParameters,;
>    STRING cDirectory,;
>    INTEGER nShowWindow
>    
>IF EMPTY(tcParms)
>   tcParms = ""
>ENDIF
>
>DECLARE INTEGER FindWindow ;
>   IN WIN32API ;
>   STRING cNull,STRING cWinName
>
>RETURN ShellExecute(FindWindow(0,_SCREEN.caption),;
>                    tcAction,tcUrl,;
>                    tcParms,tcDirectory,1)
>
>
>I call this one GoUrl() because it works with URLs, but it works with any file you pass it. It'll open that file with the configured view same as what you're doing with the script shell.
>
>
>If you can avoid the scripting shell you definitely should. This is one of those places where it's not necessary.
>
>+++ Rick ---
>
>>Hi there,
>>
>>I am using this code to display pdf-files using the default viewer which is running on the system
>>
>>
>>      wsh = createobject("wscript.shell")
>>      wsh.run(cPDFFile,1,.T.) 
>>
>>
>>This opens the default viewer and waits until it is closed.
>>Nut when I use it on a win10-system, edge (which seems to be the
>>default viewer, if nothing else like the adobe reader ist installed) opens the pdf file but
>>an error occurs (translated from german):
>>
>>Error 1429 OLE IDispatch Exceptioncode 0 from wshshell.run
>>Waiting for process not possible
>>
>>Why does this happen? Because edge is more embedded than IE ever was and cannot finish?
>>Is there something I can do?
>>
>>Best regards
>>
>>Thomas
"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