Domino Code Fragment

Code Name*
API Call to Add Shortcuts to the Win95 Desktop
Date*
04/29/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.145.186.173
Description*
This script sample will add Shortcuts to the Win95 Desktop.
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
The constants and declarations should be put in the global declarations of
the form. The rest of the code goes in a button click event. The constants
& decs were copied from the 32bit VB4 API text folder. The parameter lpData
in RegQueryValueEx was changed to ' byVal so that the API routine could return a value here. This returned value also needs some manipulation (aka hacking) to convert it into a Notes string variable, see the code.
Files/Graphics attachments (if applicable): Code:
This script sample will add Shortcuts to the Win95 Desktop. To do this, it reads the registry to find the location of this
user's desktop folder, then copies a premade shortcut file (*.LNK or *.PIF) from a network directory to that folder.


************** Begin Script
***************** Global declarations
Public Const HKEY_CURRENT_USER = &H80000001
Public Const ERROR_SUCCESS = 0&
Public Const KEY_QUERY_VALUE = &H1


Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA"(Byval hKey As Long, Byval lpSubKey As String, Byval
ulOptions As Long, Byval samDesired As Long, phkResult As Long) As Long


Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (Byval hKey As Long, Byval lpValueName As String,
Byval lpReserved As Long, lpType As Long, Byval lpData As String, lpcbData As Long) As Long


Declare Function RegCloseKey Lib "advapi32.dll" Alias "RegCloseKey" (Byval hKey As Long) As Long

***************** Button click event
Sub Click(Source As Button)
Dim fname As String
Dim session As New NotesSession
Dim UIWsp As New NotesUIWorkSpace
Dim uiDoc As NotesUIDocument
Set uiDoc = uiWsp.CurrentDocument
Dim keyHandle As Long, ErrOpen As Long, errQuery As Long
Dim subkey As String, desktopPath As String, keyType As Long, tempString As String, a As String


' This only works on Windows 32 bit platforms
If session.platform <> "Windows/32" Then
Messagebox "Sorry, this function is only available on Windows 95 & NT workstations.", 16, "Function not available"
End
End If


tempString = Space$(255)

' Get the name of the link file
fName = Trim$(uiDoc.FieldGetText("LinkFileName"))


' Find the current user's desktop folder
subKey = "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
errOpen = RegOpenKeyEx( HKEY_CURRENT_USER, subKey, 0, KEY_QUERY_VALUE, keyHandle)
If errOpen = ERROR_SUCCESS Then
errQuery = RegQueryValueEx(keyHandle, "Desktop", 0, keyType, tempString, 255)
If errQuery = ERROR_SUCCESS Then


' the following funky stuff needed because the string value returned by RegQueryValueEx in tempString
' is not properly terminated, find the first non-blank char backwards in the string to determine it's real
length.
tempString = tempString & "a" ' add something to end of string
For i = Len(tempString)-2 To 1 Step -1
If Asc(Mid$(tempString, i, 1)) > 32 Then Exit For
Next
desktopPath = Left$(tempString, i)
' end funkiness


RegCloseKey(keyHandle)
Filecopy "\\NHQD01\J0901\LINKS\" & fName, desktopPath & "\" & fName
Else
Messagebox "Couldn't query registry value, Error: " & Str$(errQuery), 0, "Script Error"
End If
Else
Messagebox "Couldn't open registry key, Error: " & errOpen, 0, "Script Error"
End If


End Sub
***************** End script