home *** CD-ROM | disk | FTP | other *** search
/ Computer Buyer 1998 November / Dpcb1198.bin / Office / LOTUS / FLG / LOTHOME.LSS < prev    next >
Text File  |  1996-08-07  |  5KB  |  167 lines

  1. Option Public
  2. 'Option Declare
  3.  
  4. Declare Public Function RegOpenKeyExA Lib "advapi32"  Alias "RegOpenKeyExA" (Byval HKEY As Long,Byval lpszSubKey As String,Byval dwreserved As Integer,Byval samDesired As Long, keyresult As Long) As Long
  5. Declare Public Function RegQueryValueExA Lib "advapi32" _
  6.     Alias "RegQueryValueExA" _
  7.     (Byval HKEY As Long,_
  8.     Byval lpszValueName As String,_
  9.     Byval dwreserved As Integer, _
  10.     lpdwtype As Long, _
  11.     Byval lpData As String, _
  12.     readbytes As Long) As Long
  13. Declare Public Function RegCloseKey Lib "advapi32" _
  14.     Alias "RegCloseKey" (Byval HKEY As Long) As Long
  15. Declare Public Function GetPrivateProfileStringA Lib "kernel32" _
  16.     Alias "GetPrivateProfileStringA"_
  17.     (Byval AppName As String,_
  18.     Byval KName As Any, _
  19.     Byval Def As String, _
  20.     Byval RStr As String, _
  21.     Byval nSize As Integer, _
  22.     Byval FName As String) As Integer
  23.  
  24.  
  25. Function GetKey (myKey As String) As String
  26.     
  27.     Dim HKEY_LOCAL_MACHINE As Long
  28.     Dim KEY_READ As Long
  29.     Dim HKEY_CURRENT_USER As Long
  30.     Dim HKEY_CLASSES_ROOT As Long
  31.     Dim KEY_QUERY_VALUE As Integer
  32.     Dim KEY_ENUMERATE_SUBKEYS As Integer
  33.     Dim KEY_NOTIFY As Integer
  34.     
  35.     
  36.     HKEY_CLASSES_ROOT= &H80000000
  37.     HKEY_CURRENT_USER= &H80000001
  38.     HKEY_LOCAL_MACHINE= &H80000002
  39.     
  40.     KEY_QUERY_VALUE=1
  41.     KEY_ENUMERATE_SUBKEYS=8
  42.     KEY_NOTIFY=16
  43.     KEY_READ=KEY_QUERY_VALUE Or KEY_ENUMERATE_SUBKEYS Or KEY_NOTIFY
  44.     
  45.     Dim lstat As Long    
  46.     Dim KeyVal As Long
  47.     Dim KeyReadBytes As Long
  48.     Dim ValueType As Long
  49.     Dim ValueName As String
  50.     Dim ReturnedKeyContents As String * 255
  51.     ReturnedKeyContents=String$(255,Chr$(32))
  52.     
  53.     'Open the registry and get the key address (myKey)
  54.     lstat=RegOpenKeyExA(HKEY_CLASSES_ROOT,myKey,0,KEY_READ,KeyVal)
  55.     KeyReadBytes = 255
  56.     'Get the value of the key at that address (ReturnedKeyContents)
  57.     lstat=RegQueryValueExA(KeyVal,ValueName,0,ValueType, _
  58.     ReturnedKeyContents,KeyReadBytes)
  59.     'Close the registry, thank you (you wouldn't want the keys to escape!)
  60.     regclosekey(KeyVal)
  61.     
  62.     'Get rid of the extra characters in the keystring
  63.     ReturnedKeyContents = Rtrim$(ReturnedKeyContents)
  64.     ReturnedKeyContents = Left$(ReturnedKeyContents,(Len(ReturnedKeyContents)-1))
  65.     
  66.     GetKey = ReturnedKeyContents
  67. End Function
  68.  
  69.  
  70.  
  71. Sub Main
  72.     %Include "Inistrs.lss"
  73. Dim URL As String
  74.     URL$=" http://www.lotus.com"    'The URL to open
  75.     
  76.     ' ** Define the search key list **
  77.     ' ********************************
  78.     Dim strKeylist(3) As String
  79.     strKeylist(0) = "http"    'http
  80.     strKeylist(1) = "htmlfile"    'htmlfile
  81.     strKeylist(2) = ".htm"    '.htm
  82.     strKeylist(3) = ".html"    '.html
  83.     
  84.     ' ** Declare the variables needed **
  85.     ' ****************************************
  86.     Dim ReturnedKey As String * 255
  87.     'Dim DDEAppKey As String
  88.     'Dim DDETopicKey As String
  89.     'Dim ReturnedDDEAppKey As String
  90.     'Dim ReturnedDDETopicKey As String
  91.     Dim strSKey As String
  92.     Dim SeekKey As String
  93.     Dim BrowserPath As String
  94.     Dim LaunchPath As String
  95.     Dim stat As Variant
  96.     
  97.     Dim QuotePos As Integer
  98.     Dim ExePos As Integer
  99.     
  100.     
  101.     ' ** Iterate through the list of keyvalues until a valid one is found **
  102.     ' **********************************************************************
  103.     Forall strPKey In strKeylist
  104.         ReturnedKey = GetKey(strPKey)        
  105.         If ReturnedKey<>"" Then
  106.             'We got something.  Were we looking for a file extension...?
  107.             If Left$(strPKey, 1) = "." Then
  108.                 'Set the DDE command to nothing
  109.                 SeekKey = Trim$(ReturnedKey)
  110.                 'Strip out excess nulls
  111.                 While InStr(SeekKey, Chr$(0)) > 0
  112.                     SeekKey=Left$(SeekKey, InStr(SeekKey, Chr$(0)) -1)
  113.                 Wend
  114.             Else
  115.                 'We weren't looking for a file extension, so get DDE keys (to
  116.                 'send message to app if running) and command key (to launch app
  117.                 'if not already running)
  118.                 'DDEAppKey = strPKey+"\shell\open\ddeexec\Application"
  119.                 'DDETopicKey = strPKey+"\shell\open\ddeexec\Topic"
  120.                 'ReturnedDDEAppKey = GetKey (DDEAppKey)
  121.                 'ReturnedDDETopicKey = GetKey (DDETopicKey)
  122.                 SeekKey = strPKey
  123.             End If    
  124.             'Get the app key pointed to
  125.             strSKey= SeekKey+"\shell\open\command"
  126.             'Get the browser path
  127.             BrowserPath = GetKey (strSKey)
  128.              'Delete all command line params:
  129.             ExePos=Instr(1,BrowserPath,".exe",1)
  130.             If ExePos<>0 Then
  131.                 BrowserPath=Left$(BrowserPath,ExePos+4)
  132.             End If
  133.             'Return path without leading quote, if there is one:
  134.             QuotePos=Instr(BrowserPath,Chr$(34))
  135.             If QuotePos<>0 Then
  136.                 BrowserPath=Mid$(BrowserPath,QuotePos+1)
  137.                 QuotePos=Instr(BrowserPath, CHR$(34))
  138.                 If QuotePos<>0 Then
  139.                     Mid$(BrowserPath,QuotePos)=" "
  140.                 End If
  141.             End If
  142.             'Create the command to send to the shell
  143.             LaunchPath=BrowserPath+" "+URL
  144.             Err=0
  145.             On Error Resume Next
  146.             
  147.             ' ** Send the appropriate commands to the shell **
  148.             ' *********************************************************
  149.             'Send the command to application to change to a new URL
  150.             '(Hah!  Wishful thinking, that I could send a DDE command from Script.  Oh well.)
  151.  
  152.             'Send the command to the shell to launch a new browser
  153.             stat=Shell(LaunchPath, 1)
  154.             'If you successfully launched, you're done
  155.             If stat = 33 Then
  156.                 Exit Sub
  157.             End If
  158.             On Error Goto 0
  159.         End If    
  160.     End Forall
  161.     'None of the registry keys pointed to valid browsers, so send an error
  162.     Msgbox NOBROWSER
  163.     
  164. End Sub
  165.  
  166.  
  167.