Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vbscript api 1

Status
Not open for further replies.

dubious

MIS
Nov 29, 2001
1
US
is it possible to declare api calls in vbscript? i am trying to call the FindWindowEx API. Is this possible?
 
I was wondering the same thing and i found my answer. Unfortunatly the answer to that question is no. but you can write your own DLL to handle it and call that through VBScript. I wrote one for shellexecute which i can post for you if you think it will be helpful.
 
this is the dll:
Code:
Option Explicit

'possible values for the showCmd parameter in shellexecute
Private Const SW_HIDE = 0
Private Const SW_SHOWNORMAL =1
Private Const SW_SHOWMINIMIZED = 2
Private Const SW_SHOWMAXIMIZED = 3
Private Const SW_MAXIMIZE = 3
Private Const SW_SHOWNOACTIVATE = 4
Private Const SW_SHOW = 5
Private Const SW_MINIMIZE = 6
Private Const SW_SHOWMINNOACTIVE = 7
Private Const SW_SHOWNA = 8
Private Const SW_RESTORE = 9
Private Const SW_SHOWDEFAULT = 10

'Return values of the shellexecute statement
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&
Private Const ERROR_BAD_FORMAT = 11&
Private Const SE_ERR_FNF = 2
Private Const SE_ERR_PNF = 3
Private Const SE_ERR_ACCESSDENIED = 5
Private Const SE_ERR_OOM = 8
Private Const SE_ERR_DLLNOTFOUND = 32
Private Const SE_ERR_SHARE = 26
Private Const SE_ERR_ASSOCINCOMPLETE = 27
Private Const SE_ERR_DDETIMEOUT = 28
Private Const SE_ERR_DDEFAIL = 29
Private Const SE_ERR_DDEBUSY = 30
Private Const SE_ERR_NOASSOC = 31

Private Declare Function ShellExecute 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

Public Sub Launch(filePath As String, hwnd As Long, _
                    Optional showCmd As Long, Optional strOption As String, _
                    Optional strParam As String, Optional defaultDir As String)
    
    Dim result As Long
    Dim strResultMessage As String
    strResultMessage = vbNullString
    
    'if showcmd is not specified it is automatically set to the default application settings
    If IsMissing(showCmd) Then
        showCmd = SW_SHOWDEFAULT
    End If
    
    'if showCmd is not valid then it is set to the default application settings
    If showCmd > 10 Or showCmd < 0 Then
        showCmd = SW_SHOWDEFAULT
    End If
    
    If IsMissing(strOption) Or strOption = &quot;&quot; Then
        strOption = &quot;open&quot;
    End If
    
    result = ShellExecute(hwnd, strOption, filePath, strParam, defaultDir, showCmd)
    
    'check the results of the shellexecute statement
End Sub

for size purposes I took out all the comments that say what the constansts are for but you can get that off MSDN help under shell execute and i also took out the select case statement checking the return value it just displayed a message box telling why it didn't open.

These are the script lines i use to call it.

Code:
    dim file1
    set file1 = CreateObject(&quot;LaunchWin.Launch&quot;)

    file1.Launch Cstr(fileName), CLng(hwnd), CLng(showCmd), Cstr(strOption), Cstr(strParam), Cstr(defaultDir)

any questions just ask :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top