Ignore below post -read this one

Hi all,
I was wondering if you could help me out?
What I need to do is get the name of a logged in user on a windows computer and then either store it into a file/batch file or store as a variable.

We have more than one domain that we need to log onto, but the 2 domains have a different naming convention.

For example if your name is Guest User, on the one domain you would log in as guser and on the other you would log in as guest.user .

I want to get the current logged on username and then say "if username = guser then newusername = guest.user

Trouble is my understanding of batch files is limited. I know i can do a %username% in a batch file, but i done know how to get the responce from the batch file to the program.

Hope that makes sence, any help would be VERY much appreciated.

Stuaer

Comments

  • [b][red]This message was edited by zibadian at 2004-2-14 3:13:44[/red][/b][hr]
    : Hi all,
    : I was wondering if you could help me out?
    : What I need to do is get the name of a logged in user on a windows computer and then either store it into a file/batch file or store as a variable.
    :
    : We have more than one domain that we need to log onto, but the 2 domains have a different naming convention.
    :
    : For example if your name is Guest User, on the one domain you would log in as guser and on the other you would log in as guest.user .
    :
    : I want to get the current logged on username and then say "if username = guser then newusername = guest.user
    :
    : Trouble is my understanding of batch files is limited. I know i can do a %username% in a batch file, but i done know how to get the responce from the batch file to the program.
    :
    : Hope that makes sence, any help would be VERY much appreciated.
    :
    : Stuaer
    :
    Here is a code of a batchfile, which stores the username in a file called "user.txt":
    [code]
    echo %username% > user.txt
    [/code]
    You can then wait until the file "user.text" exists, before continuing your program.

    Note: you can also delete your own messages on this board. Read your own message, and there will be several commands around it to edit and delete it.
  • : Hi all,
    : I was wondering if you could help me out?
    : What I need to do is get the name of a logged in user on a windows computer and then either store it into a file/batch file or store as a variable.
    :
    : We have more than one domain that we need to log onto, but the 2 domains have a different naming convention.
    :
    : For example if your name is Guest User, on the one domain you would log in as guser and on the other you would log in as guest.user .
    :
    : I want to get the current logged on username and then say "if username = guser then newusername = guest.user
    :
    : Trouble is my understanding of batch files is limited. I know i can do a %username% in a batch file, but i done know how to get the responce from the batch file to the program.
    :
    : Hope that makes sence, any help would be VERY much appreciated.
    :
    : Stuaer
    :
    In Delphi it can be done like:
    [code]
    function LoginUserName: string;
    var
    NameBuffer: PChar;
    NameBufferSize: Cardinal; // Integer for < delphi 5 ?
    begin
    NameBufferSize := 30;
    SetLength(Result, NameBufferSize);
    if not GetUserName(Pointer(Result), NameBufferSize) then
    begin
    case GetLastError of
    ERROR_INSUFFICIENT_BUFFER, ERROR_MORE_DATA:
    begin
    SetLength(Result, NameBufferSize);
    if not GetUserName(Pointer(Result), NameBufferSize) then
    RaiseLastOSError;
    end;
    else
    RaiseLastOSError;
    end;
    end
    else
    SetLength(Result, NameBufferSize);
    end;
    [/code]


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories