skafy Posted December 19, 2015 Share Posted December 19, 2015 How could I get computer name/domain name of a current client ? Quote Link to comment Share on other sites More sharing options...
mhmda Posted December 20, 2015 Share Posted December 20, 2015 Hi, I think you cannot do that due to security reasons, the browser will not allow such that activity, beside that why do you want to get the client 'computer name'? more info here: http://stackoverflow.com/questions/2825221/how-to-get-computer-name-or-ip-from-javascript Quote Link to comment Share on other sites More sharing options...
skafy Posted December 20, 2015 Author Share Posted December 20, 2015 How about domain name? Program will be running only for company employee. Quote Link to comment Share on other sites More sharing options...
rgreat Posted December 20, 2015 Share Posted December 20, 2015 Create and install ActiveX control for unusual stuff. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted December 20, 2015 Share Posted December 20, 2015 Hi, For now maybe it will help: http://forums.unigui.com/index.php?/topic/3220-allowediplist/&do=findComment&comment=16541 Best regards. Quote Link to comment Share on other sites More sharing options...
skafy Posted December 21, 2015 Author Share Posted December 21, 2015 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; Quote Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted December 21, 2015 Administrators Share Posted December 21, 2015 Is your client PC in a LAN or in the internet? Quote Link to comment Share on other sites More sharing options...
skafy Posted December 21, 2015 Author Share Posted December 21, 2015 Client PC is in trusted Intranet Quote Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted December 21, 2015 Administrators Share Posted December 21, 2015 You can use IP Reverse Lookup to resolve his IP address to a Name. Quote Link to comment Share on other sites More sharing options...
skafy Posted December 21, 2015 Author Share Posted December 21, 2015 How can I accomplish that? Quote Link to comment Share on other sites More sharing options...
skafy Posted December 22, 2015 Author Share Posted December 22, 2015 You can use IP Reverse Lookup to resolve his IP address to a Name. I've tried that but it doesn't working 100%. Any other idea? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted December 22, 2015 Share Posted December 22, 2015 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. Quote Link to comment Share on other sites More sharing options...
skafy Posted December 22, 2015 Author Share Posted December 22, 2015 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. Quote Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted December 22, 2015 Administrators Share Posted December 22, 2015 I don't think you can get it. A browser has a limited access to local PC resources. Quote Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted December 22, 2015 Administrators Share Posted December 22, 2015 You shouldn'T normally need this. User can login with his uname/pwd which will give you all you need. Quote Link to comment Share on other sites More sharing options...
skafy Posted December 22, 2015 Author Share Posted December 22, 2015 User should get to his page automaticlly with Windows user name and doesn't need to log in again with same credentials. Quote Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted December 22, 2015 Administrators Share Posted December 22, 2015 You can use cookies to save user credentials on client PC. 1 Quote Link to comment Share on other sites More sharing options...
skafy Posted December 22, 2015 Author Share Posted December 22, 2015 But if i choose that option user will have to enter credentials the first time he visit page right? Any other solutions? Quote Link to comment Share on other sites More sharing options...
zilav Posted December 22, 2015 Share Posted December 22, 2015 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. Quote Link to comment Share on other sites More sharing options...
skafy Posted December 22, 2015 Author Share Posted December 22, 2015 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? Quote Link to comment Share on other sites More sharing options...
rgreat Posted December 22, 2015 Share Posted December 22, 2015 ajaxRequest(DestinationObject, 'UserDetailsEvent', ['UserName='+WinNetwork.UserName]); Quote Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted December 22, 2015 Administrators Share Posted December 22, 2015 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. Quote Link to comment Share on other sites More sharing options...
skafy Posted December 22, 2015 Author Share Posted December 22, 2015 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! Quote Link to comment Share on other sites More sharing options...
rgreat Posted December 22, 2015 Share Posted December 22, 2015 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; 1 Quote Link to comment Share on other sites More sharing options...
Sherzod Posted December 23, 2015 Share Posted December 23, 2015 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.