Get login name/user name

I can get the login name by using either:

Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" (ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long) As Long

or..

Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Both works fine when executed. My problem is that I want to execute my program (exe-file) from a login script (NT or Novell) and write the login name to a file.

All I get is an empty string. Looks like Windows can't return the info this early in the startup process.

The main reason for running the code from a login script, is that I don't have to install any program on the clients.

The program works fine if I launch it from the Startup-folder.

Any suggestions? Is there other ways to return the login name?

Regards,
Christopher
cvogtAsked:
Who is Participating?
 
gbarenCommented:
OK, if you're on a 9x client, you won't have those locally. Here's a table from a help file Logon Script topic:

Parameter Description
 
%HOMEDRIVE% The user's local workstation drive letter connected to the user's home directory

%HOMEPATH% The full path of the user's home directory

%OS% The operating system of the user's workstation

%PROCESSOR_ARCHITECTURE% The processor type (such as 80386) of the user's workstation

%PROCESSOR_LEVEL% The processor level of the user's workstation

%USERDOMAIN% The domain containing the user's account

%USERNAME% The user name


These are all supposed to be available from the Logon Script. I believe the Logon Script runs on the server itself, not on the client. Which is probably why SET name=%USERNAME% doesn't work -- you're setting another variable on the server

Use the parameter approach. Change your app to accept a parameter and call it with  "app.exe %USERNAME%"

0
 
rkot2000Commented:
try to use sleep function to delay your exe
0
 
rkot2000Commented:
did you try net name?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
gbarenCommented:
For NT, the username is available in an Environment variable USERNAME. There are also USERDOMAIN and USERDNSDOMAIN variables. You really don't need to use a VB program to get this information.


To use these from a batch file, just surround the variable name with %, like this:

echo off
echo %USERDOMAIN%\%USERNAME% >> C:\LOGFILE.LOG

Tell me a bit more about what you need to do with the user name.

Gary
0
 
gbarenCommented:
By the way, this information exists directly in Novell login scripts. It's been over six years since I administered a Novell server, though. Don't remember what the variables are called anymore.
0
 
cvogtAuthor Commented:
I know about the login script variables. I should have told you: This is part of a sysinfo program that log's all kind of information - memory size, free disc space, installed software etc. So I think I have to use an .exe file rather than a batch file.

The only thing I can't get at startup is the login name (and for some strange reasons: on some computers I can't get the network adapters MAC address or Ethernet address).
0
 
cvogtAuthor Commented:
I know about the login script variables. I should have told you: This is part of a sysinfo program that log's all kind of information - memory size, free disc space, installed software etc. So I think I have to use an .exe file rather than a batch file.

The only thing I can't get at startup is the login name (and for some strange reasons: on some computers I can't get the network adapters MAC address or Ethernet address).
0
 
cvogtAuthor Commented:
I know about the login script variables. I should have told you: This is part of a sysinfo program that log's all kind of information - memory size, free disc space, installed software etc. So I think I have to use an .exe file rather than a batch file.

The only thing I can't get at startup is the login name (and for some strange reasons: on some computers I can't get the network adapters MAC address or Ethernet address).
0
 
Hornet241Commented:
Have you tried

     Environ("Username")
0
 
gbarenCommented:
cv,

You can pass the userid on the command line. From the Novell login script, you can pass the MAC ID as well.

Alternatively, you can add your EXE to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\


Gary
0
 
jcgdCommented:
You can run a batch file in login script (NOVELL) that execute "whoami > c:\nnnnn.nn"? Read and parse this file. Put a whoami.exe in Login directory.
0
 
MBCommented:
How about converting your exe to an NT Service?
0
 
gbarenCommented:
What the...

NEVER POST AN ANSWER

newbies...
0
 
cvogtAuthor Commented:
Thanks for all comments. I am trying the login script approach and I have had some luck logging on a win9x PC on a Netware server, setting environment variables in the script and reading them in my prog using the Environ statement.

I am not that experienced with login scripts on NT. Note: I am logging win9x PC's onto a win NT/2000 server. How do I set environment variables in the login script? In Netware I use this statments:

Set name="%LOGIN_NAME"
Set MACaddress = "%P_STATION"

Can I do this in NT? I have tried writing something like:

Set name=%USERNAME% or Set name="%USERNAME%"
I have also tried the suggestion from gbaren: ECHO %USERNAME% (with and without the piping to a file), but it seems that the %USERNAME% variable is empty. I am logging in using the standard Client for Microsoft Networks.

Any comments on this matters?
0
 
gbarenCommented:
CV,

Open the command prompt and type SET. You'll get a list of all defined environment variables.

You don't need to set another environment variable, either:

1. Read the existing environment variable from your program like this: sUser = Environ("USERNAME")

2. Change your program to accept a parameter and pass the environment variable like this: YOURAPP.EXE %USERNAME%

Gary

By the way, you should reject the proposed answer because it has locked this thread and removed it from the open thread list.
0
 
cvogtAuthor Commented:
Gary

If I type Set on a dos prompt ON A WIN98 computer (logged on tho a NT 4.0 server) I see just a few variables (Path, sound card etc. not username or MAC address)

If I open a dos prompt ON THE NT SERVER itself I see them. But I am logging the WIN98 computer, not the Server. Is there something missing in the setup in the environment I am testing?

0
 
Hornet241Commented:
If you want to set all of the Environ parameters do this,

    for a = 1 to 30
        debug.print a & " - " & envrion(a)
    next a

This will give you a list with their corresponding number
The return will contain the parameter name. The format will be like this

    27 - USERNAME=hornet241
0
 
Hornet241Commented:
Oops, mispelled Environ in the above comment
0
 
MoondancerCommented:
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if still open in seven days.  Please post closing recommendations before that time.

Question(s) below appears to have been abandoned. Your options are:
 
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> You cannot delete a question with comments, special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click the Help Desk link on the left for Member Guidelines, Member Agreement and the Question/Answer process for further information, if needed.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues, to track all your open and locked questions at this site.  If you are an EE Pro user, use the Power Search option to find them.  Anytime you have questions which are LOCKED with a Proposed Answer but does not serve your needs, please reject it and add comments as to why.  In addition, when you do grade the question, if the grade is less than an A, please add a comment as to why.  This helps all involved, as well as future persons who may access this item in the future to seek help.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20137543.html
http://www.experts-exchange.com/questions/Q.20171666.html
http://www.experts-exchange.com/questions/Q.20274820.html




PLEASE DO NOT AWARD THE POINTS TO ME.  
 
------------>  EXPERTS:  Please leave any comments regarding your closing recommendations if this item remains inactive another seven (7) days.  Also, if you are interested in the cleanup effort, please click this link http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643

Moderators will finalize this question if still open in 7 days, by either moving this to the PAQ (Previously Asked Questions) at zero points, deleting it or awarding expert(s) when recommendations are made, or an independent determination can be made.  Expert input is always appreciated to determine the fair outcome.
 
Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange
0
 
MoondancerCommented:
 ....~~~~~:)-> Thanks for returning and finalizing this. <=(:~~~~~~~....

        Complete the NEW USER SURVEY for additional points.  Look here:
             http://www.experts-exchange.com/jsp/memberEarnPoints.jsp

                 >>>>>>>> Moondancer - EE Moderator <<<<<<<<<
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.