Run External application from webpage

Discussions of applications and operating systems and any problems, tips or suggestions. Win XP, 9x/2k, Linux, NT, photo editing, Virus/Spyware help
Post Reply
pyro_1
Genuine Member
Posts: 77
Joined: Thu Nov 23, 2000 6:56 pm

Run External application from webpage

Post by pyro_1 »

I need to run an external local application from a webpage. right now when i put in the link to the application a box comes up asking if i want to run it from the current location or save it. What i need to have happen is for it to just start the application. Any sujjestions on how i would be able to do this?

bayden
jah
Genuine Member
Posts: 44
Joined: Wed May 23, 2001 8:55 am

Post by jah »

-------initial thoughts-------

If you are using Windows and can call VB functions from your development environment (a la ASP, ?maybe ColdFusion?), then you can do this a couple ways.

None of this applies if you can't run VBScript. AND all the code that follows is VB; it will need heavy tweaking to run as a script (for example, variable types must be taken out so that you just do 'Dim x' instead of 'Dim x As Long')

1) If you need to open just MS Office documents

Dim objE As Object, objD As Object

'--comment---can use "Access.Application", etc.
Set objE = CreateObject("Excel.Application")

Set objD = objE.Application.Workbooks.Open "c:\docs\Client\IpLicenseTracker\bugs\All\bugs_digest.xls")

objE.Visible = True

2) Mmm, k. You can also use the VB shell command to execute any Windows command line from within VB, or possibly VBScript (dunno, never tried it, but probably it will work).

'--comment---RetVal is program's task id, if you need it! '1' is the window style (optional)
Dim RetVal
RetVal = Shell("C:\WINDOWS\CALC.EXE", 1)

'---comment---could also just do:
Shell "C:\Windows\Calc.exe", 1 to execute as Sub with no return val

3. I didn't write this; it is from an Access 2000 development manual. Defines VB ShellExecute function to run a program based on its file extension in the registry. So then you can just write code like this from VB:

fHandleFile("c:\MyApp\MyAppFile.ext", WIN_NORMAL)

which opens MyAppFile as long as there is an entry for .ext in the registry (most common filetypes are autoregisted when programs are installed).

---------START VB CODE-------------------
Option Compare Database

'************ Code Start **********
Private Declare Function apiShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" _
(ByVal hWnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) _
As Long

'***App Window Constants***
Public Const WIN_NORMAL = 1 'Open Normal
Public Const WIN_MAX = 3 'Open Maximized
Public Const WIN_MIN = 2 'Open Minimized

'***Error Codes***
Private Const ERROR_SUCCESS = 32&
Private Const ERROR_NO_ASSOC = 31&
Private Const ERROR_OUT_OF_MEM = 0&
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&
Private Const ERROR_BAD_FORMAT = 11&

'***************Usage Examples***********************
'Open a folder: ?fHandleFile("C:\TEMP\",WIN_NORMAL)
'Call Email app: ?fHandleFile("mailto :d ash10@hotmail.com",WIN_NORMAL)
'Open URL: ?fHandleFile("http://home.att.net/~dashish", WIN_NORMAL)
'Handle Unknown extensions (call Open With Dialog):
' ?fHandleFile("C:\TEMP\TestThis",Win_Normal)
'Start Access instance:
' ?fHandleFile("I:\mdbs\CodeNStuff.mdb", Win_NORMAL)
'****************************************************

Function fHandleFile(stFile As String, lShowHow As Long)
Dim lRet As Long, varTaskID As Variant
Dim stRet As String
'First try ShellExecute
lRet = apiShellExecute(hWndAccessApp, vbNullString, _
stFile, vbNullString, vbNullString, lShowHow)

If lRet > ERROR_SUCCESS Then
stRet = vbNullString
lRet = -1
Else
Select Case lRet
Case ERROR_NO_ASSOC:
'Try the OpenWith dialog
varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " _
& stFile, WIN_NORMAL)
lRet = (varTaskID <> 0)
Case ERROR_OUT_OF_MEM:
stRet = "Error: Out of Memory/Resources. Couldn't Execute!"
Case ERROR_FILE_NOT_FOUND:
stRet = "Error: File not found. Couldn't Execute!"
Case ERROR_PATH_NOT_FOUND:
stRet = "Error: Path not found. Couldn't Execute!"
Case ERROR_BAD_FORMAT:
stRet = "Error: Bad File Format. Couldn't Execute!"
Case Else:
End Select
End If
fHandleFile = lRet & _
IIf(stRet = "", vbNullString, ", " & stRet)
End Function
'************ Code End **********

4. If you are running webpage from Unix / Linux OS, then I don't know. Maybe if you can go to Perl and execute a call to a system shell or something. Dunno, I don't program Unix yet.

If you can't run VB or C ++ code (like to make a Windows API call) I don't know! I don't think there is any way to call an external app using just html. You have to use VBScript or JavaScript.

:D
jah
Genuine Member
Posts: 44
Joined: Wed May 23, 2001 8:55 am

Post by jah »

Goddam smilies!!!!!

Anyways, here's the non-smilied version of that shellexecute code (As you'll notice, the program makes a call to vb Shell() function if ShellExecute doesn't work!)

Option Compare Database

'************ Code Start **********
Private Declare Function apiShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" _
(ByVal hWnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) _
As Long

'***App Window Constants***
Public Const WIN_NORMAL = 1 'Open Normal
Public Const WIN_MAX = 3 'Open Maximized
Public Const WIN_MIN = 2 'Open Minimized

'***Error Codes***
Private Const ERROR_SUCCESS = 32&
Private Const ERROR_NO_ASSOC = 31&
Private Const ERROR_OUT_OF_MEM = 0&
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&
Private Const ERROR_BAD_FORMAT = 11&

'***************Usage Examples***********************
'Open a folder: ?fHandleFile("C:\TEMP\",WIN_NORMAL)
'Call Email app: ?fHandleFile("mailto:dash10@hotmail.com",WIN_NORMAL)
'Open URL: ?fHandleFile("http://home.att.net/~dashish", WIN_NORMAL)
'Handle Unknown extensions (call Open With Dialog):
' ?fHandleFile("C:\TEMP\TestThis",Win_Normal)
'Start Access instance:
' ?fHandleFile("I:\mdbs\CodeNStuff.mdb", Win_NORMAL)
'****************************************************

Function fHandleFile(stFile As String, lShowHow As Long)
Dim lRet As Long, varTaskID As Variant
Dim stRet As String
'First try ShellExecute
lRet = apiShellExecute(hWndAccessApp, vbNullString, _
stFile, vbNullString, vbNullString, lShowHow)

If lRet > ERROR_SUCCESS Then
stRet = vbNullString
lRet = -1
Else
Select Case lRet
Case ERROR_NO_ASSOC:
'Try the OpenWith dialog
varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " _
& stFile, WIN_NORMAL)
lRet = (varTaskID <> 0)
Case ERROR_OUT_OF_MEM:
stRet = "Error: Out of Memory/Resources. Couldn't Execute!"
Case ERROR_FILE_NOT_FOUND:
stRet = "Error: File not found. Couldn't Execute!"
Case ERROR_PATH_NOT_FOUND:
stRet = "Error: Path not found. Couldn't Execute!"
Case ERROR_BAD_FORMAT:
stRet = "Error: Bad File Format. Couldn't Execute!"
Case Else:
End Select
End If
fHandleFile = lRet & _
IIf(stRet = "", vbNullString, ", " & stRet)
End Function
'************ Code End **********
Post Reply