Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using CreateProcess (inside a Notes form)

Status
Not open for further replies.

deros68

Programmer
Oct 28, 2005
12
0
0
US
I am trying to call a Windows API from a Notes script. I want to use the CreateProcess API to run a program and pass it parameters. I have used this in C++ & X86 ASM. Now I want to learn how to do so in a Lotus form (VB style syntax ?). I have everything working except this section. I stripped out all the Notes form code, verified that it works fine. I then tried the code below - standalone - and
I get the "Type Mismatch" pop-up.

sumamry:
call createprocess passing it the program name (full path with no long filenames) and a parameter list, several flags
including the SW_HIDE flag - keep process from showing on the desk top ( I also varied the SW_HIDE flag to see if I got a msg or DOS pop-up - nyet)

I think that I need to declare the following parameters as long pointer items: Commandline d1 & d2
But Notes will not allow any of the above items as "Long" -

example

Dim d1 as Long

and

d1 ="some parms to be passed"

gives me a red highlight "Type mismatch" on the d1 ="some parms to be passed" line


commandline - is a program in c:\windows\system32
d1 - is one set of parms
d2 - is a different set of parms

The code that Notes will accept is shown below - no errors until run time - "Type Mismatch"

Sections as follows:
Code:
Declarations Sections
Type STARTUPINFO
	cb              As Long
	lpReserved      As Long
	lpDesktop       As Long
	lpTitle         As Long
	dwX             As Long
	dwY             As Long
	dwXSize         As Long
	dwYSize         As Long
	dwXCountChars   As Long
	dwYCountChars   As Long
	dwFillAttribute As Long
	dwFlags         As Long
	wShowWindow     As Integer
	cbReserved2     As Integer
	lpReserved2     As Long
	hStdInput       As Long
	hStdOutput      As Long
	hStdError       As Long
End Type

Type PROCESS_INFORMATION
	hProcess    As Long
	hThread     As Long
	dwProcessID As Long
	dwThreadID  As Long
End Type

Declare Function CreateProcess Lib "Kernel32" (Byval lpApplicationName As Long, Byval lpCommandLine As String,_ 
Byval lpProcessAttributes As Long, Byval lpThreadAttributes As Long, Byval bInheritHandles As Long,_ 
Byval dwCreationFlags As Long, Byval lpEnvironment As Long, Byval lpCurrentDirectory As Long,_ 
lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long


Sub Queryopen(Source As Notesuiview, Continue As Variant)
	
	Dim proc As PROCESS_INFORMATION
	Dim Start As STARTUPINFO
	Dim CommandLine As String
	
	Commandline = "c:\windows\system32\anyfile.exe "  (no long file names - ever) always as shown
	
	Dim d1  As String 
	d1  = "p1 p2 p3 p4 p5 "                       where p1 -p8 are parms to be passed
	Dim  d2 As String
	d2 = "p1 p2 p3 p4 p5p p6 p7 p8"

       'Initialize the STARTUPINFO structure:
	Start.cb = Len(Start)
	Start.dwFlags = &H1
	Start.wShowWindow = 0&
	
    'run pgm 1
	CreateProcess CommandLine, d1, 0&, 0&, 1&, _ 
	&H8000&,  0&, 0&, Start, proc
	
    'run same pgm with different parms
	CreateProcess CommandLine, d2, 0&, 0&, 1&, _ 
	&H80000&, 0&, 0&, Start, proc
End Sub
After I get this code working - once - I will add some error handling routines. Right now I know that program I am trying to run exists in the path that I show above. I have admin privileges on the Windows OS and on the Notes form.

Any help appreciated - I find this hard to debug - I need to learn how to use the Notes debugger, using the Windows debugger is extremely tedious ( it works well for simpler things like attaching to simple programs - and my lack of experience in using it -:) )

deros68
 
Concerning the Notes debugger : just go to File/Tools/Debug LotusScript in Notes and click to enable. You will get a popup telling you that LS debugging is active. Then, when you run a script of any kind, you get the debug window.
You want to disable debugging when you're finished, because LS is in a lot of Notes apps and, for example, opening your mail with the debugger is an exercise in frustration.

For the Type Mismatch, I admit I'm a bit stumped. I put your code in an agent and it did compile fine, but even when I put all the argument variables on the same line I still got the Type Mismatch error on the CreateProcess line.

Then I checked the Design Help db and I found something wierder : there is no CreateProcess method in Script. There is a CreateProcessingInstructionNode method, part of the NotesDOMDocumentNode object. What I find wierd is that the code compiles anyway, when it should raise an error on an instruction it is not supposed to know.

Where did you find that method ?

Pascal.


I've got nothing to hide, and I'd very much like to keep that away from prying eyes.
 
Pascal,

thanks - I now know when/how to kick in the Lotus debugger -that may help. There are a number of places where I found references to calling WInapi functions from Lotus script. This function is one I am trying to use based upon my using it in C++ & X86 asm. I did review the following URLs to try and see what format/syntax is needed since Lotus script is very VBA like.






Thanks - I note that you have many good replies on this forum.

deros68
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top