Who's Logged In?

Blitz3D Forums/Blitz3D Beginners Area/Who's Logged In?

Oldefoxx(Posted 2003) [#1]
Question is, suppose you want to know which user is currently logged into the PC? This is important if you
want to look along the correct path to that person's
Desktop or My Document folder, for instance, or if you
want to call up custom settings for that player in a
game setting. I'm sure with research I will find an
answer, but I bet someone already knows.


deletemeplease(Posted 2003) [#2]
** DELETED **


soja(Posted 2003) [#3]
For example, the current user's desktop:
DesktopPath$ = GetEnv("USERPROFILE")+"\Desktop"

Of course this only works for NT machines. For 9x machines, you'll have to check the default system variables to see what's available. Maybe you'd just have to manually figure it out.

For more info, run a command line shell (cmd.exe or command.com) and type "set". Or, you can go into Control Panel -> System Properties -> Advanced -> Environment Variables.


BlitzSupport(Posted 2003) [#4]
With a userlib, you might want to look at the Win32 command SHGetSpecialFolderLocation, as it'll return the path to the requested folder (My Documents, Program Files, etc) according to the current user, though it's a bit of a weird one (has some odd structures and stuff), so I'm not sure if it'll work as things stand...


BlitzSupport(Posted 2003) [#5]
Doh... or try GetUserName, though as Soja points out, the paths are going to be different on 9x...


Oldefoxx(Posted 2003) [#6]
Using the GetEnv$() function can prove to be the key to
finding out something about the environment set up for
the user. For instance, some of the environmental values
are derived from the current user's profile, so if you have
left these at their default values, you might find that GetEnv$("TEMP") or GetEnv$("TMP") provides a path to something like:

"c:\Documents and Settings\Default User\Local Settings\Temp"

or that the GetEnv$("USERPROFILE") might return:

"C:\Documents and Settings\Default User\"

Of course, instead of "Default User", you would expect to see the name of the person who is currently logged in. And as pointed out, going to Start/Run and entering "Cmd" (or entering "Command /k" on Win9x/ME machines) and then entering "SET" will display all the environmental variables and their settings. You can use the Alt+Enter (or Alt+Carrage Return) to change the Command Line Window to full screen, then use it again to toggle back to a normal screen in order to close it (or just type "Exit" to leave).


soja(Posted 2003) [#7]
...or entering "Command /k" on Win9x/ME machines


Oldefoxx, you don't need the /k switch.


Oldefoxx(Posted 2003) [#8]
Actually, you do if you want to keep some of the Command Windows open. Not every Windows version behaves the same, and some close as soon as the given command is executed. For instance, if you did a DIR command, the directory would get listed and the windows then closes so fast you could not see the results. For other windows, the Command /K is not needed, but the /k remains for compatability. I am merely attempting to avoid some conflict here by going with the lowest common denominator.


soja(Posted 2003) [#9]
There is no version of Windows in which command.com closes itself immediately after being run (with no parameters). All you need to do is run "command", then type "set".

In fact, the /k switch does not exist in all versions of command.com.


Oldefoxx(Posted 2003) [#10]
Please note the following:


COMMAND

Starts a new instance of the MS-DOS command interpreter.

A command interpreter is a program that lets you type commands. Use the EXIT
command to stop the new command interpreter and return control to the old
one.

Syntax
COMMAND [[drive:]path] [device] [/E:nnnnn] [/Y [/C command|/K command]]

In your CONFIG.SYS file, use the following syntax:

SHELL=[[dos-drive:]dos-path]COMMAND.COM [[drive:]path][device]
[/E:nnnn] [/P [/MSG]]

Parameters

[drive:]path
Specifies the directory in which the command interpreter is to look for
the COMMAND.COM file when the transient part of the program needs to be
reloaded. This parameter must be included when loading COMMAND.COM for
the first time if the COMMAND.COM file is not located in the root
directory. This parameter is used to set the COMSPEC environment
variable. For more information, see Transient and Resident Memory in
<COMMAND--Notes>.

device
Specifies a different device for command input and output. For more
information about this parameter, see the <CTTY> command.

[dos-drive:]dos-path
Specifies the location of the COMMAND.COM file.

Switches

/C command
Specifies that the command interpreter is to perform the specified
command and then exit. This switch must be the last switch on the
command line.

/E:nnnnn
Specifies the environment size, where nnnnn is the size in bytes. The
value of nnnnn must be in the range 160 through 32768. MS-DOS rounds
this number up to a multiple of 16 bytes. The default value is 256.

/K command
Runs the specified command, program, or batch program and then displays
the MS-DOS command prompt. This switch must be the last switch on the
COMMAND command line.

This switch is particularly useful for specifying a startup batch file
for the MS-DOS Prompt in Windows (much like AUTOEXEC.BAT for MS-DOS). To
do this, open the DOSPRMPT.PIF file using the PIF Editor, and type the
/K switch in the Optional Parameters box. It is not recommended to use
the /K switch on the SHELL command line in your CONFIG.SYS file; doing
so can cause problems with applications and installation programs that
make changes to your AUTOEXEC.BAT file.

/P
Should be used only when COMMAND is used with the SHELL command in the
CONFIG.SYS file. The /P switch makes the new copy of the command
interpreter permanent. In this case, the EXIT command cannot be used to
stop the command interpreter. If you specify /P, MS-DOS runs your
AUTOEXEC.BAT file before displaying the command prompt. If there is no
AUTOEXEC.BAT file in the root directory of the startup drive, MS-DOS
carries out the DATE and TIME commands instead. If you do not have a
SHELL command in your CONFIG.SYS file, COMMAND.COM is automatically
loaded from the root directory with the /P switch.

/MSG
Specifies that all error messages should be stored in memory. Usually,
some messages are stored only on disk. This switch is useful only if you
are running MS-DOS from floppy disks. You must specify the /P switch
when you use the /MSG switch. For more information about using the /MSG
switch, see <COMMAND--Notes>.
/Y
Directs COMMAND.COM to step through the batch file specified by the /C
or /K switches. This switch is useful for debugging batch files. For
example, to step through the TEST.BAT batch file line by line, you would
type COMMAND /Y /C TEST. The /Y switch requires either the /C or the /K
switch.

Related Command

The <SHELL> command is the preferred method of using COMMAND to permanently
increase space for the environment table.


soja(Posted 2003) [#11]
Right. I said
...you don't need the /k switch.

Try it.
Start->run->"Command"

And still, I also said:
There is no version of Windows in which command.com closes itself immediately after being run (with no parameters).


Maybe I'm not seeing what you're trying to say.