Results 1 to 5 of 5

Thread: Why is my shell not working? [RESOLVED]

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Location
    Chicago
    Posts
    136

    Question Why is my shell not working? [RESOLVED]

    In my quest to have multiple unique IExplore.exe processes I wrote some code that finds the application path for IE and launches it to a website.

    The code is below, it throws an error at the Shell line. The error is 'Run-time error '5': Invalid procedure call or argument'

    VB Code:
    1. Option Explicit
    2. Dim f_strResults As String
    3. Dim f_arrIESettings(1 To 8, 1 To 7) As Variant
    4. Dim f_flgGoAhead As Boolean
    5.     Const SubKey = 1
    6.     Const ValueName = 2
    7.     Const GoodVal = 3
    8.     Const ChkBoxNm = 4
    9.     Const ChkBoxSt = 5
    10.     Const DataType = 6
    11.     Const CurrVal = 7
    12.  
    13. Const HKEY_CLASSES_ROOT = &H80000000
    14. Const HKEY_CURRENT_USER = &H80000001
    15. Const HKEY_LOCAL_MACHINE = &H80000002
    16. Const HKEY_USERS = &H80000003
    17.  
    18.     ' Reg Key Security Options...
    19. Const READ_CONTROL = &H20000
    20. Const KEY_QUERY_VALUE = &H1
    21. Const KEY_SET_VALUE = &H2
    22. Const KEY_CREATE_SUB_KEY = &H4
    23. Const KEY_ENUMERATE_SUB_KEYS = &H8
    24. Const KEY_NOTIFY = &H10
    25. Const KEY_CREATE_LINK = &H20
    26. Const KEY_ALL_ACCESS = KEY_QUERY_VALUE + KEY_SET_VALUE + _
    27.                        KEY_CREATE_SUB_KEY + KEY_ENUMERATE_SUB_KEYS + _
    28.                        KEY_NOTIFY + KEY_CREATE_LINK + READ_CONTROL
    29.  
    30. Private Sub Form_Load()
    31.  
    32. Dim strSubKey As String
    33. Dim strValueName As String
    34. Dim AppPath As String
    35. Dim AppPathLen As Integer
    36. Dim IE As String
    37.  
    38. 'Registry value locations
    39. strSubKey = "SOFTWARE\Classes\Applications\iexplore.exe\shell\open\command"
    40. strValueName = ""
    41.  
    42. 'Returning the application path back from registry
    43. AppPath = RegGetValue$(HKEY_LOCAL_MACHINE, strSubKey, strValueName)
    44.  
    45. 'Determining the length of the path
    46. AppPathLen = Len(AppPath)
    47. 'Removing the " %1" from the end of the path
    48. AppPath = Left(AppPath, AppPathLen - 4)
    49. 'Adding the site to be navigated to
    50. IE = AppPath & " website"
    51.  
    52. 'Launching IE
    53. Shell IE, vbNormalFocus
    54.  
    55. End
    56. End Sub

    The Windows Registry module I'm using:

    VB Code:
    1. Declare Function RegCloseKey& Lib "advapi32.dll" (ByVal hKey&)
    2. Declare Function RegOpenKeyExA& Lib "advapi32.dll" (ByVal hKey&, ByVal lpszSubKey$, dwOptions&, ByVal samDesired&, lpHKey&)
    3. Declare Function RegQueryValueExA& Lib "advapi32.dll" (ByVal hKey&, ByVal lpszValueName$, ByVal lpdwRes&, lpdwType&, ByVal lpDataBuff$, nSize&)
    4. Declare Function RegQueryValueEx& Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey&, ByVal lpszValueName$, ByVal lpdwRes&, lpdwType&, lpDataBuff&, nSize&)
    5.  
    6. Const HKEY_CLASSES_ROOT = &H80000000
    7. Const HKEY_CURRENT_USER = &H80000001
    8. Const HKEY_LOCAL_MACHINE = &H80000002
    9. Const HKEY_USERS = &H80000003
    10.  
    11. Const ERROR_SUCCESS = 0&
    12. Const REG_SZ = 1&                          ' Unicode nul terminated string
    13. Const REG_DWORD = 4&                       ' 32-bit number
    14.  
    15. Const KEY_QUERY_VALUE = &H1&
    16. Const KEY_SET_VALUE = &H2&
    17. Const KEY_CREATE_SUB_KEY = &H4&
    18. Const KEY_ENUMERATE_SUB_KEYS = &H8&
    19. Const KEY_NOTIFY = &H10&
    20. Const KEY_CREATE_LINK = &H20&
    21. Const READ_CONTROL = &H20000
    22. Const WRITE_DAC = &H40000
    23. Const WRITE_OWNER = &H80000
    24. Const SYNCHRONIZE = &H100000
    25. Const STANDARD_RIGHTS_REQUIRED = &HF0000
    26. Const STANDARD_RIGHTS_READ = READ_CONTROL
    27. Const STANDARD_RIGHTS_WRITE = READ_CONTROL
    28. Const STANDARD_RIGHTS_EXECUTE = READ_CONTROL
    29. Const KEY_READ = STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY
    30. Const KEY_WRITE = STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY
    31. Const KEY_EXECUTE = KEY_READ
    32.  
    33.  
    34. Function RegGetValue$(MainKey&, SubKey$, value$)
    35.    ' MainKey must be one of the Publicly declared HKEY constants.
    36.    Dim sKeyType&       'to return the key type.  This function expects REG_SZ or REG_DWORD
    37.    Dim Ret&            'returned by registry functions, should be 0&
    38.    Dim lpHKey&         'return handle to opened key
    39.    Dim lpcbData&       'length of data in returned string
    40.    Dim ReturnedString$ 'returned string value
    41.    Dim ReturnedLong&   'returned long value
    42.    If MainKey >= &H80000000 And MainKey <= &H80000006 Then
    43.       ' Open key
    44.       Ret = RegOpenKeyExA(MainKey, SubKey, 0&, KEY_READ, lpHKey)
    45.       If Ret <> ERROR_SUCCESS Then
    46.          RegGetValue = ""
    47.          Exit Function     'No key open, so leave
    48.       End If
    49.      
    50.       ' Set up buffer for data to be returned in.
    51.       ' Adjust next value for larger buffers.
    52.       lpcbData = 255
    53.       ReturnedString = Space$(lpcbData)
    54.  
    55.       ' Read key
    56.       Ret& = RegQueryValueExA(lpHKey, value, ByVal 0&, sKeyType, ReturnedString, lpcbData)
    57.       If Ret <> ERROR_SUCCESS Then
    58.          RegGetValue = ""   'Value probably doesn't exist
    59.       Else
    60.         If sKeyType = REG_DWORD Then
    61.             Ret = RegQueryValueEx(lpHKey, value, ByVal 0&, sKeyType, ReturnedLong, 4)
    62.             If Ret = ERROR_SUCCESS Then RegGetValue = CStr(ReturnedLong)
    63.         Else
    64.             RegGetValue = Left$(ReturnedString, lpcbData - 1)
    65.         End If
    66.     End If
    67.       ' Always close opened keys.
    68.       Ret = RegCloseKey(lpHKey)
    69.    End If
    70. End Function
    Last edited by bat711; Apr 15th, 2005 at 11:04 AM.

  2. #2
    Addicted Member BIOSTALL's Avatar
    Join Date
    Apr 2005
    Location
    Northampton, UK
    Posts
    180

    Re: Why is my shell not working?

    try iexplore.exe instead of IE

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Why is my shell not working?

    Well on my machine that value reads
    Code:
    "C:\Program Files\Internet Explorer\iexplore.exe" %1
    My advice - try just
    VB Code:
    1. Shell AppPath, vbNormalFocus

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Location
    Chicago
    Posts
    136

    Re: Why is my shell not working?

    BIOSTALL:

    Well yeah, but that defeats the purpose of searching the registry for the location of IExplore.exe. IE in this case is just a string with the application path in it (plus the website address).

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Location
    Chicago
    Posts
    136

    Re: Why is my shell not working?

    Quote Originally Posted by penagate
    Well on my machine that value reads
    Code:
    "C:\Program Files\Internet Explorer\iexplore.exe" %1
    My advice - try just
    VB Code:
    1. Shell AppPath, vbNormalFocus
    Thanks, I realized the error was that I was taking 4 characters off the end instead of 3. Oops...


    Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width