Difference between revisions of "RPC Broker Silent Login Example"
(Created page with " RPC Broker Help Home <h2>Silent Login Examples</h2> Silent Login <h3>Example 1: lmAVCodes</h3> Here is an example of how to use Silent Login by passing...") |
|||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
[[RPC_Broker_Help| RPC Broker Help Home]] | [[RPC_Broker_Help| RPC Broker Help Home]] | ||
<h2>Silent Login Examples</h2> | <h2>Silent Login Examples</h2> | ||
− | Silent Login | + | [[RPC_HELP_Silent_Login|Silent Login]] |
<h3>Example 1: lmAVCodes</h3> | <h3>Example 1: lmAVCodes</h3> | ||
Here is an example of how to use Silent Login by passing the Access and Verify codes to the TVistaLogin class. | Here is an example of how to use Silent Login by passing the Access and Verify codes to the TVistaLogin class. | ||
− | |||
<code> | <code> | ||
Line 26: | Line 25: | ||
NOTE: For a demonstration using the lmAVCodes, please run the lmAVCodes_Demo.EXE located in the ..\BDK32\Samples\SilentSignOn directory. | NOTE: For a demonstration using the lmAVCodes, please run the lmAVCodes_Demo.EXE located in the ..\BDK32\Samples\SilentSignOn directory. | ||
− | |||
− | |||
<h3>Example 2: lmAppHandle</h3> | <h3>Example 2: lmAppHandle</h3> | ||
Line 42: | Line 39: | ||
If the value for ConnectedBroker is nil, the application specified in ProgLine will be started and any command line included in ProgLine will be passed to the application. | If the value for ConnectedBroker is nil, the application specified in ProgLine will be started and any command line included in ProgLine will be passed to the application. | ||
− | In the second application, a call to the Broker should be made shortly after starting, since the LoginHandle passed in has a finite lifetime (approximately 20 seconds) during which it is valid for the Silent Login. | + | In the second application, a call to the Broker should be made shortly after starting, since the LoginHandle passed in has a finite lifetime (approximately 20 seconds) during which it is valid for the Silent Login. |
− | |||
<code> | <code> | ||
Line 70: | Line 66: | ||
'''end;''' | '''end;''' | ||
</code> | </code> | ||
+ | |||
+ | ''{btnStart is clicked to start the second application Test2.exe}'' | ||
<code> | <code> | ||
− | '' | + | '''procedure''' TForm1.btnStartClick(Sender: TObject); |
− | + | '''var''' | |
− | var | + | CurDir: string; |
− | + | '''begin''' | |
− | begin | + | ''{Use Test2.exe and expecting it to be in the startup directory for the current application}'' |
− | + | CurDir := ExtractFilePath(ParamStr(0)) + 'Test2.exe'; | |
− | + | ''{Now start application with Silent Login}'' | |
− | + | StartProgSLogin(CurDir, brkrRPCB1); | |
− | + | '''end;''' | |
− | end; | ||
</code> | </code> | ||
Line 98: | Line 95: | ||
The TRPCB and RpcSLogin units would need to be included in the USES clause. | The TRPCB and RpcSLogin units would need to be included in the USES clause. | ||
− | procedure CheckCmdLine(brkrRPCB: TRPCBroker); | + | '''procedure''' CheckCmdLine(brkrRPCB: TRPCBroker); |
var | var | ||
j: integer; | j: integer; | ||
− | begin | + | '''begin''' |
// Iterate through possible command line arguments | // Iterate through possible command line arguments | ||
− | for j := 0 to 15 do begin | + | '''for''' j := 0 to 15 '''do begin''' |
− | if ParamStr(j) <> '' then begin | + | '''if''' ParamStr(j) <> '' '''then begin''' |
Form1.Memo1.Lines.Add(IntToStr(j) + ' ' + ParamStr(j)); | Form1.Memo1.Lines.Add(IntToStr(j) + ' ' + ParamStr(j)); | ||
− | end; | + | '''end;''' |
− | if Pos('p=',ParamStr(j)) > 0 then begin | + | '''if''' Pos('p=',ParamStr(j)) > 0 '''then begin''' |
brkrRPCB.ListenerPort := StrToInt(Copy(ParamStr(j), (Pos('=',ParamStr(j))+1),length(ParamStr(j)))); | brkrRPCB.ListenerPort := StrToInt(Copy(ParamStr(j), (Pos('=',ParamStr(j))+1),length(ParamStr(j)))); | ||
− | end; | + | '''end;''' |
− | if Pos('s=',ParamStr(j)) > 0 then begin | + | '''if''' Pos('s=',ParamStr(j)) > 0 '''then begin''' |
brkrRPCB.Server := Copy(ParamStr(j),(Pos('=',ParamStr(j))+1),length(ParamStr(j))); | brkrRPCB.Server := Copy(ParamStr(j),(Pos('=',ParamStr(j))+1),length(ParamStr(j))); | ||
− | end; | + | '''end;''' |
− | if Pos('h=',ParamStr(j)) > 0 then begin | + | '''if''' Pos('h=',ParamStr(j)) > 0 '''then begin''' |
brkrRPCB.Login.LoginHandle := Copy(ParamStr(j),(Pos('=',ParamStr(j))+1),length(ParamStr(j))); | brkrRPCB.Login.LoginHandle := Copy(ParamStr(j),(Pos('=',ParamStr(j))+1),length(ParamStr(j))); | ||
− | if brkrRPCB.Login.LoginHandle <> '' then begin | + | '''if''' brkrRPCB.Login.LoginHandle <> '' '''then begin''' |
brkrRPCB.KernelLogIn := False; | brkrRPCB.KernelLogIn := False; | ||
brkrRPCB.Login.Mode := lmAppHandle; | brkrRPCB.Login.Mode := lmAppHandle; | ||
− | end; | + | '''end;''' |
− | end; | + | '''end;''' |
− | if Pos('d=',ParamStr(j)) > 0 then begin | + | '''if''' Pos('d=',ParamStr(j)) > 0 '''then begin''' |
brkrRPCB.Login.Division := Copy(ParamStr(j),(Pos('=',ParamStr(j))+1),length(ParamStr(j))); | brkrRPCB.Login.Division := Copy(ParamStr(j),(Pos('=',ParamStr(j))+1),length(ParamStr(j))); | ||
− | end; | + | '''end;''' |
− | end; | + | '''end; |
− | + | ''' | |
For a demonstration using the lmAppHandle, please run the lmAppHandle_Demo.EXE located in the ..\BDK32\Samples\SilentSignOn directory. | For a demonstration using the lmAppHandle, please run the lmAppHandle_Demo.EXE located in the ..\BDK32\Samples\SilentSignOn directory. |
Latest revision as of 21:24, 3 July 2015
Silent Login Examples
Example 1: lmAVCodes
Here is an example of how to use Silent Login by passing the Access and Verify codes to the TVistaLogin class.
brkrRPCBroker1.KernelLogIn := False;
brkrRPCBroker1.LogIn.Mode := lmAVCodes;
brkrRPCBroker1.LogIn.AccessCode := ********;
brkrRPCBroker1.LogIn.VerifyCodeCode := ********;
brkrRPCBroker1.LogIn.PromptDivison := True;
brkrRPCBroker1.LogIn.OnFailedLogin := myevent;
try
brkrRPCBroker1.Connected := True;
except
exit
end;
If brkrRPCBroker1.Connected is True, then Silent Login has worked.
NOTE: For a demonstration using the lmAVCodes, please run the lmAVCodes_Demo.EXE located in the ..\BDK32\Samples\SilentSignOn directory.
Example 2: lmAppHandle
Here is an example of how to use Silent Login by passing an Application Handle to the TVistaLogin class.
The lmAppHandle mode of the Silent Login is used when an application starts up a second application. If the second application tests for arguments on the command line, it is possible for this application to be started and make a connection to the VistA M Server without user interaction.
An example of a procedure for starting a second application with data on the command line to permit a Silent Login using the LoginHandle provided by the first application is shown below. This is followed by a procedure that can be called in the processing related to FormCreate to use this command line data to initialize the TRPCBroker component for Silent Login.
NOTE: It should be noted that the procedures shown here are included within the RpcSLogin unit, and can be used directly from there.
If the value for ConnectedBroker is nil, the application specified in ProgLine will be started and any command line included in ProgLine will be passed to the application.
In the second application, a call to the Broker should be made shortly after starting, since the LoginHandle passed in has a finite lifetime (approximately 20 seconds) during which it is valid for the Silent Login.
procedure StartProgSLogin(const ProgLine: String; ConnectedBroker: TRPCBroker);
var
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
AppHandle: String;
CmndLine: String;
begin
FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
with StartupInfo do begin
cb := SizeOf(TStartupInfo);
dwFlags := STARTF_USESHOWWINDOW;
wShowWindow := SW_SHOWNORMAL;
end;
CmndLine := ProgLine;
if ConnectedBroker <> nil then begin
AppHandle := GetAppHandle(ConnectedBroker);
CmndLine := CmndLine + ' s='+ConnectedBroker.Server + ' p='
+ IntToStr(ConnectedBroker.ListenerPort) + ' h='
+ AppHandle + ' d=' + ConnectedBroker.User.Division;
end;
CreateProcess(nil, Pchar(CmndLine), nil, nil, False,
NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo);
end;
{btnStart is clicked to start the second application Test2.exe}
procedure TForm1.btnStartClick(Sender: TObject);
var
CurDir: string;
begin
{Use Test2.exe and expecting it to be in the startup directory for the current application}
CurDir := ExtractFilePath(ParamStr(0)) + 'Test2.exe';
{Now start application with Silent Login}
StartProgSLogin(CurDir, brkrRPCB1);
end;
The following procedure (CheckCmdLine) would be called in the FormCreate code of the application being started to check for command line input, and if relevant to the Broker connection, to set it up.
This code assumes that s=, p=, d=, and h= are used in conjunction with the values for Server, ListenerPort, User.Division, and LoginHandle, respectively.
The command line might look like:
ProgramName.exe s=DHCPSERVER p=9200 d=692 h=~1XM34XYYZZQQ_X
The TRPCB and RpcSLogin units would need to be included in the USES clause.
procedure CheckCmdLine(brkrRPCB: TRPCBroker); var j: integer; begin // Iterate through possible command line arguments for j := 0 to 15 do begin if ParamStr(j) <> then begin Form1.Memo1.Lines.Add(IntToStr(j) + ' ' + ParamStr(j)); end; if Pos('p=',ParamStr(j)) > 0 then begin brkrRPCB.ListenerPort := StrToInt(Copy(ParamStr(j), (Pos('=',ParamStr(j))+1),length(ParamStr(j)))); end; if Pos('s=',ParamStr(j)) > 0 then begin brkrRPCB.Server := Copy(ParamStr(j),(Pos('=',ParamStr(j))+1),length(ParamStr(j))); end; if Pos('h=',ParamStr(j)) > 0 then begin brkrRPCB.Login.LoginHandle := Copy(ParamStr(j),(Pos('=',ParamStr(j))+1),length(ParamStr(j))); if brkrRPCB.Login.LoginHandle <> then begin brkrRPCB.KernelLogIn := False; brkrRPCB.Login.Mode := lmAppHandle; end; end; if Pos('d=',ParamStr(j)) > 0 then begin brkrRPCB.Login.Division := Copy(ParamStr(j),(Pos('=',ParamStr(j))+1),length(ParamStr(j))); end; end;
For a demonstration using the lmAppHandle, please run the lmAppHandle_Demo.EXE located in the ..\BDK32\Samples\SilentSignOn directory.