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
  #7  
Old 07-26-2001, 05:04 AM
phear phear is offline
Senior Member
 
Join Date: Mar 2001
Posts: 325
Default RE: RE: still doesn't work !!

this one works.
you forgot to put this in the first code :

Dispose(vlSize);

if you don't put this, you get a violation access error.
Reply With Quote
  #8  
Old 07-26-2001, 05:08 AM
LörAn LörAn is offline
Senior Member
 
Join Date: Mar 2001
Posts: 1,506
Default At least !!!

Thanx to you my friend !
I was really thinking my code is a personnal one, just working correctly on MY computer and when I am connected ! :P
Next time I'll try my code before giving my answer, not to lose my credibility !


LörAn.
ICQ #112714184
Reply With Quote
  #9  
Old 07-27-2001, 03:22 AM
phear phear is offline
Senior Member
 
Join Date: Mar 2001
Posts: 325
Default RE: At least !!!

I'm the one who should be thanking you
)

PS : you have a lovely name
Reply With Quote
  #10  
Old 07-27-2001, 04:41 AM
LörAn LörAn is offline
Senior Member
 
Join Date: Mar 2001
Posts: 1,506
Default RE: RE: At least !!!

Hey man, be careful, LörAn is not the abreviation of 'Laure-Anne' nor 'Ann-Laure' or anything like this. My name's Laurent, which is a french MALE name.
So please don't try anything with me...

:P

PS: And I'm not GAY ! :P

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 08:03 AM.


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