Jump to content

Client username


skafy

Recommended Posts

I've put next function in MainModule but no success:

 

function TUniMainModule.GetCurrentUserName: string;
const
  cnMaxUserNameLen = 254;
var
  sUserName     : string;
  dwUserNameLen : DWORD;
begin
  dwUserNameLen := cnMaxUserNameLen-1;
  SetLength( sUserName, cnMaxUserNameLen );
  GetUserName(PChar( sUserName ),
    dwUserNameLen );
  SetLength( sUserName, dwUserNameLen );
  SetLength(sUserName, sUserName.Length - 1);
  Result := UpperCase(sUserName);
end;

Link to comment
Share on other sites

Hi,

 

Try:

unit uNbLookup;

 

 

unit uNbLookup;

interface

(************************************************************

  06-02-2007 - Petricca Antonio (antonio.petricca@gmail.com)

  Free for any purpose...

  Thanks to:

    Jim Halfpenny
    http://directory.fsf.org/security/misc/nbtstat.pl.html

************************************************************)

uses
  IdComponent,
  IdGlobal,
  IdUDPClient,
  SysUtils,
  Windows;

function NetBiosLookup(AAddress: PChar; AHostName: PChar; ATimeOut: Integer): BOOL; stdcall;

implementation

const
  NB_REQUEST = #$A2#$48#$00#$00#$00#$01#$00#$00 +
               #$00#$00#$00#$00#$20#$43#$4b#$41 +
               #$41#$41#$41#$41#$41#$41#$41#$41 +
               #$41#$41#$41#$41#$41#$41#$41#$41 +
               #$41#$41#$41#$41#$41#$41#$41#$41 +
               #$41#$41#$41#$41#$41#$00#$00#$21 +
               #$00#$01;

  NB_PORT    = 137;
  NB_BUFSIZE = 8192;

function NetBiosLookup(AAddress: PChar; AHostName: PChar; ATimeOut: Integer): BOOL; stdcall;
var
  Buffer    : TIdBytes;
  I         : Integer;
  RepName   : String;
  UDPClient : TIdUDPClient;
begin
  RepName   := '';
  Result    := False;
  UDPClient := nil;

  if not Assigned(AHostName) then
    Exit;

  try
    UDPClient := TIdUDPClient.Create(nil);
    with UDPClient do begin
      Host := Trim(AAddress);
      Port := NB_PORT;
      
      Send(NB_REQUEST);
    end;

    SetLength(Buffer, NB_BUFSIZE);
    if (0 < UDPClient.ReceiveBuffer(Buffer, ATimeOut)) then begin

      for I := 1 to 15 do
        RepName := RepName + Chr(Buffer[56 + I]);

      RepName := Trim(RepName);
      StrPCopy(AHostName, RepName);

      Result := True;
    end;

  except
    Result := False;
  end;

  if Assigned(UDPClient) then
    FreeAndNil(UDPClient);
end;

end.

 

 

 

How to use:

uses ... uNbLookup;

procedure TMainForm.UniButton1Click(Sender: TObject);
var
  HostName : array[0 .. MAX_PATH] of Char;
begin
  
  if NetBiosLookup(PChar('111.111.111.111'), HostName, 5000) then
    ShowMessage(HostName);

end;

Best regards.

Link to comment
Share on other sites

Ok. This is solved.

 

procedure TMain.UniFormCreate(Sender: TObject);
begin
  UniSession.AddJS('var WinNetwork = new ActiveXObject("WScript.Network");');
  UniSession.AddJS('alert(WinNetwork.UserName);');

end;

 

This pops up domain name of currently logged in user. Now I wonder how to get this WinNetwork.Username in a variable in outside JS. Eny ideas?

Link to comment
Share on other sites

  • Administrators

Ok. This is solved.

 

procedure TMain.UniFormCreate(Sender: TObject);

begin

UniSession.AddJS('var WinNetwork = new ActiveXObject("WScript.Network");');

UniSession.AddJS('alert(WinNetwork.UserName);');

end;

 

This pops up domain name of currently logged in user. Now I wonder how to get this WinNetwork.Username in a variable in outside JS. Eny ideas?

This will only work in IE.
Link to comment
Share on other sites

This will only work in IE.

Correct. Since IE is default browser in our company this doesn't bother me.

 

ajaxRequest(DestinationObject, 'UserDetailsEvent', ['UserName='+WinNetwork.UserName]);

Where do I put this code?. Where set form variable?

Thank you very much!

Link to comment
Share on other sites

in client code "MainForm.ClientEvents.ExtEvents.Show" (for example)

function window.show(sender, eOpts)
{
  var WinNetwork = new ActiveXObject("WScript.Network");
  ajaxRequest(sender, 'UserDetailsEvent', ['UserName='+WinNetwork.UserName]);
}

in server code:

procedure TMainForm.UniFormAjaxEvent(Sender: TComponent; EventName: string; Params: TStrings);
begin
  if EventName='UserDetailsEvent' then begin
    UniEdit1.Text:=Params.Values['UserName'];
  end;
end;

  • Upvote 1
Link to comment
Share on other sites

Hi,

 

You can also analyze the demo projects:

C:\Program Files (x86)\FMSoft\Framework\uniGUI\Demos\Desktop\LoginForm
C:\Program Files (x86)\FMSoft\Framework\uniGUI\Demos\Desktop\LoginForm Cookies...

I think maybe there is a better place that would pass such parameters...

 

Best regards.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...