Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Lotus NotesSession -- Possible to test for an open sessi
Message
 
 
To
20/01/2003 15:07:11
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00743545
Message ID:
00748267
Views:
20
This message has been marked as the solution to the initial question of the thread.
>Hi Larry (or any other NOTES gurus),
>
>I have already used some code from other threads to automatic using Lotus to send email. My snag comes in that I don't want to hard code a password into the program I'm running which is creating a spreadsheet and then using Notes to distribute it. The report should be distributed by the user that's creating it. I don't want the program to hang if the Notes isn't open and it opens for the first time and waits for password entry. It would be better if the program could test for an open session and then branch based on whether it could use Notes to distribute the file.
>
>Is there any way to test for a session already being open? Is there another way around this problem?

Margaret,
Sorry for the delay. It took me awhile to get access to my Notes system again.

It sounds as though you are using some version of Notes prior to 5.0.3. In previous versions, you had to use the following:
losession = createobject('Notes.NotesSession')
This caused the Notes client to launch, if it already wasn't, displaying the password dialog. Starting with version 5.0.3, you could use:
losession = createobject('Lotus.NotesSession')
This is the new COM class. The session instantiates. You can then call the Initialize method with the password as a parameter.

Do you have access to this version? If not, there really a Notes way. You can loop through the active processes and see if NLNOTES.EXE is running. If so, a Notes session is active.

Here is some code:
clear
clear dlls
#define PROCESS_QUERY_INFORMATION	0x400
#define PROCESS_VM_READ				0x10
#define PROCESS_MASK				BITOR(PROCESS_QUERY_INFORMATION,PROCESS_VM_READ)

set procedure to clsheap additive

declare integer GetLastError in win32api
declare integer EnumProcesses in PSAPI string@, integer, integer@
declare integer EnumProcessModules in PSAPI integer, string@, integer, integer@
declare integer GetModuleFileNameEx in PSAPI integer, integer, string@, integer
declare integer OpenProcess in kernel32 integer, integer, integer
declare integer CloseHandle in kernel32 integer
declare string GetCommandLine in kernel32 integer

local oheap, lpPIDarray, lpModarray, lnsize, lpneeded, lcarrstr, lnMod
local llprocess
oheap = createobject('heap')
lpPIDarray = replicate(chr(0),4096)
lnsize = 200
lpneeded = 0
lpneeded1 = 0
if EnumProcesses(@lpPIDarray,lnsize,@lpneeded) <> 0 then
	lpPIDarray = left(lpPIDarray,lpneeded)

	local lxx, lnPDI, lnhproc, lyy, lcModname
	for lxx = 1 to lpneeded step 4
		lnPID = DWordtoNum(substr(lpPIDarray,lxx,4))
		if lnPID <> 0 then
			lnhproc = OpenProcess(PROCESS_MASK,0,lnPID)
			if lnhproc <> 0 then
				lpModarray = replicate(chr(0),8192)
				if EnumProcessModules(lnhproc,@lpModarray,lnsize,@lpneeded1) <> 0 then
					llprocess = .F.
					for lyy = 1 to 1 step 4
						lnMod = DWordtoNum(substr(lpModarray,lyy,4))
						if lnMod <> 0 then
							lcModname = replicate(chr(0),128)
							GetModuleFileNameEx(lnhproc,lnMod,@lcModname,128)
							if !llprocess and (lyy = 1 and !("VFP" $ upper(lcmodname))) then
								llprocess = .T.
							endif
							if !llprocess then
								exit
							endif
							? justfname(left(lcModname,at(chr(0),lcModname)-1))
						endif
					endfor
				else
					* do nothing
				endif
				CloseHandle(lnhproc)
			else
				* do nothing
			endif
		endif
	endfor
else
	? 'Error occurred: ' + transform(GetLastError())
ENDIF
It requires you download Ed Rauh's CLSHEAP class in the Download section. DWordtoNum is a function in it. You can also use Windows Management Instrumentation (WMI). Here is an example:
clear
local loloc, lomgr, loproccol, loproc
loloc = createobject('WBemScripting.SWbemLocator')

lomgr = loloc.ConnectServer()
loproccol = lomgr.InstancesOf('Win32_Process')
for each loproc in loproccol
	? upper(loProc.Properties_("Name").Value)
next

store .NULL. to loproccol, lomgr, loloc
This works by default on Win2K and XP. You can download WMI for NT and 98.

HTH.
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform