cvogt
asked on
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
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
try to use sleep function to delay your exe
did you try net name?
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
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
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.
ASKER
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).
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).
ASKER
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).
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).
ASKER
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).
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).
Have you tried
Environ("Username")
Environ("Username")
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\SOFTWAR E\Microsof t\Windows\ CurrentVer sion\Run\
Gary
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\SOFTWAR
Gary
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.
How about converting your exe to an NT Service?
What the...
NEVER POST AN ANSWER
newbies...
NEVER POST AN ANSWER
newbies...
ASKER
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?
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?
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.
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.
ASKER
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?
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?
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
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
Oops, mispelled Environ in the above comment
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
https://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. https://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.
https://www.experts-exchange.com/questions/Q.20137543.html
https://www.experts-exchange.com/questions/Q.20171666.html
https://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 https://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
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.
https://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. https://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.
https://www.experts-exchange.com/questions/Q.20137543.html
https://www.experts-exchange.com/questions/Q.20171666.html
https://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 https://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
....~~~~~:)-> Thanks for returning and finalizing this. <=(:~~~~~~~....
Complete the NEW USER SURVEY for additional points. Look here:
https://www.experts-exchange.com/jsp/memberEarnPoints.jsp
>>>>>>>> Moondancer - EE Moderator <<<<<<<<<
Complete the NEW USER SURVEY for additional points. Look here:
https://www.experts-exchange.com/jsp/memberEarnPoints.jsp
>>>>>>>> Moondancer - EE Moderator <<<<<<<<<