Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 07-25-2001, 08:19 AM
phear phear is offline
Senior Member
 
Join Date: Mar 2001
Posts: 325
Default Getting the current domain name

Hi all.
How can I get the current domain name (or workgroupname) of the user actually logged in ? I found out the way to get the user's login but not the domain name :

----------------------
uses
Windows, (....)

function UserName:string;
var
Buffer : array[0..255] of char;
BufferSize : DWORD;
begin
BufferSize := sizeOf(Buffer);
GetUserName(@buffer, BufferSize);
Result := Buffer;
end;
----------------------

Please don't give me a component, i don't want any. I'm sur there is a Delphi code out there that does it.

thanks in advance.
Reply With Quote
  #2  
Old 07-25-2001, 08:22 AM
LörAn LörAn is offline
Senior Member
 
Join Date: Mar 2001
Posts: 1,506
Default RE: Getting the current domain name

Try this one :

function fGetDomainName(): String;
var
vlDomainName : array[0..30] of char;
vlSize : ^DWORD;
begin
vlSize^ := 30;
ExpandEnvironmentStrings(PChar('%USERDOMAIN%'), vlDomainName, vlSize^);
Result := vlDomainName;
end;

(Hope this helps...)

LörAn.
ICQ #112714184
Reply With Quote
  #3  
Old 07-25-2001, 08:41 AM
phear phear is offline
Senior Member
 
Join Date: Mar 2001
Posts: 325
Default doesn't work

Just tried, doesn't work.
Access violation error.
Reply With Quote
  #4  
Old 07-25-2001, 08:45 AM
LörAn LörAn is offline
Senior Member
 
Join Date: Mar 2001
Posts: 1,506
Default RE: doesn't work

Sorry ! Forgot the initialization of the varaible vlSize :
Just put this code at the beginning of the function :

New(vlSize);


LörAn.
ICQ #112714184
Reply With Quote
  #5  
Old 07-26-2001, 12:17 AM
phear phear is offline
Senior Member
 
Join Date: Mar 2001
Posts: 325
Default still doesn't work !!

Thanx but it still doesn't work !!!
:-(
I still have a violation access error.
Reply With Quote
  #6  
Old 07-26-2001, 01:06 AM
LörAn LörAn is offline
Senior Member
 
Join Date: Mar 2001
Posts: 1,506
Default RE: still doesn't work !!

ARGHH ! I don't understand ! Here the code I wrote and that works with me : Just put an edit in a form :

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

function fGetDomainName(): String;
var
vlDomainName : array[0..30] of char;
vlSize : ^DWORD;
begin
New(vlSize);
vlSize^ := 30;
ExpandEnvironmentStrings(PChar('%USERDOMAIN%'), vlDomainName, vlSize^);
Dispose(vlSize);
Result := vlDomainName;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Edit1.Text := fGetDomainName();
end;

end.


LörAn.
ICQ #112714184
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 07:39 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.