Jump to content

Recommended Posts

Posted

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;

Posted

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.

Posted

This code works great!...But how could you get currently logged in user and not domain name? So no matter where user is it always return his user name.

Posted

No other solutions due to security issues. If you can control how user opens a browser like providing him a link to click or pressing a button in custom application, you can add parameters to URL and read them in unigui app.

Posted

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?

  • Administrators
Posted

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.
Posted

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!

Posted

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
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...