Hi all,
For those of you that are building OLE Automation servers with VFP
especially for use with FoxISAPI or Web Connection, but also
with Active Server Pages and use via DCOM here's a useful tip on
how to avoid the DCOMCnfg headaches that need to be attended to
everytime the server is rebuilt.
Spent a little time today tweaking with the DCOMCnfg settings
and finally managed to figure out how to set these settings in
the registry so that DCOMCnfg is not required after the initial
safety settings.
I've added a new function to wwUtils called DCOMCnfgServer:
(uses a Registry class you can download from:
http://www.west-wind.com/wwvfppd.htm )
************************************************************************
PROCEDURE DCOMCnfgServer
***********************
*** Function: Sets the security attributes of an Automation server
*** to Interactive User
*** Assume: Only works for Interactive user for now
*** Pass: lcProgId - Program ID for the server (wcdemo.wcdemoserver)
*** lcRunAs - User Account (Default: Interactive User)
*** Return: nothing
*************************************************************************
LPARAMETER lcProgId, lcRunAs
LOCAL lcProgId, loAPI, lcClassId, lcServerName
lcRunAs=IIF(type('lcRunAs')='C',lcRunAs,'Interactive User')
lcProgId = 'wcDemo.wcDemoServer'
loAPI = CREATE('wwAPI')
*** Retrieve ClassId and Server Name
lcClassId = loAPI.ReadRegistryString(HKEY_CLASSES_ROOT,;
lcProgId + '\CLSID',;
'')
lcServerName = loAPI.ReadRegistryString(HKEY_CLASSES_ROOT,;
lcProgId + '','')
wait window 'Configuring server security to Interactive User: ' + CR + ;
lcProgId + CR + lcServerName nowait
*** Now add AppId key to the ClsID entry
if !loAPI.WriteRegistryString(HKEY_LOCAL_MACHINE,;
'SOFTWARE\Classes\CLSID\'+lcClassId,'AppId',lcClassID,.t.)
wait window 'Unable to write AppID value...' nowait
RETURN
ENDIF
*** Create a AppID Entry if it doesn't exist
if !loAPI.WriteRegistryString(HKEY_CLASSES_ROOT,;
'AppID\'+lcClassId,CHR(0),CHR(0),.t.)
wait window 'Unable to write AppID key...' nowait
RETURN
ENDIF
*** Write the Server Name into the Default key
loAPI.WriteRegistryString(HKEY_CLASSES_ROOT,;
'AppID\'+lcClassId,'',;
lcServerName,;
.t.)
*** Write Interactive User (or user Accounts)
loAPI.WriteRegistryString(HKEY_CLASSES_ROOT,;
'AppID\'+lcClassId,'RunAs',;
lcRunAS,;
.t.)
wait window 'DCOM settings updated...' nowait
RETURN
This function takes a ProgId (such as wcdemo.wcdemoserver) as a parameter
and adds the required registry keys to make the user account Impersonate
the Interactive User. Note that I haven't tried this with other user
accounts. You can use 'RASMAIN\rstrahl' were RASMAIN is your local
machine name and rstrahl is your username, but I haven't tested this
properly (yet).
With this in place I thought you can now build a self contained Build
routine for your server:
PROCEDURE BldOle
LPARAMETER lcExe,lcClassId
LOCAL lcFile, lcTemplate, lcOLEFlag, lcNewFile
SET PROCEDURE TO
SET CLASSLIB TO
BUILD EXE (lcEXE) FROM (lcExe) recompile
DO DCOMCnfgServer with lcClassId
RETURN
Helps make my life ALOT easier saving more than a few mouseclicks on
each build.
+++ Rick ---