Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

%username% In windows 98?

2 views
Skip to first unread message

William Allen

unread,
Jul 25, 2001, 3:08:32 AM7/25/01
to
Spinner wrote in message
> I am writing a batch file and need it to show a users login name to them. I
> used the %username% command for Windows NT, but this will not work in 98 or
> 95. Is there a subsitute for this %username% command or a way to make it
> work in 95 / 98.

The OS doesn't set the variable for you. You'll need to grab
the Username from the "User name" line of the output of the
command:

net config

So the operation is National Language specific. You can do the
name grab in any of a number of ways:

::====Inception with write access to current
@ECHO OFF
net config | find /i "User name">TEMP.BAT
ECHO. SET USERNAME=%%2>USER.BAT
CALL TEMP.BAT
ECHO. User name is: %USERNAME%
FOR %%F IN (TEMP.BAT USER.BAT) DO DEL %%F
::====

::====Inception without write access to current, but write access to TEMP
@ECHO OFF
:: Create return HOME script for current drive and folder
ECHO.EXIT|%COMSPEC% /e:993 /k PROMPT $N:$_CD $P$_$G>%TEMP%.\HOME.BAT

:: Operate in TEMP folder
%TEMP%.\
CD %TEMP%

net config | find /i "User name">TEMP.BAT
ECHO. SET USERNAME=%%2>USER.BAT
CALL TEMP.BAT
ECHO. User name is: %USERNAME%
FOR %%F IN (TEMP.BAT USER.BAT) DO DEL %%F

:: Go back to original folder
FOR %%F IN (CALL DEL) DO %%F %TEMP%.\HOME.BAT
::====

::====Universal prefixing method
@ECHO OFF
IF (GOTO:)==(%1) %1%2 (Subroutine handler)

:: Make Universal Prefix "SET UP=" (no terminal cr/lf)
ECHO.@PROMPT e0'SET UP='$_rcx$_7$_w0$_q>%TEMP%.\UP.BAT
%COMSPEC% /e:992 /c %TEMP%.\UP.BAT | debug %TEMP%.\UP.BAT>NUL
net config | find /i "User name">>%TEMP%.\UP.BAT

:: Grab the text in variable and delete workfile
FOR %%C IN (CALL DEL) DO %%C %TEMP%.\UP.BAT

CALL %0 GOTO: _USENAM %UP%

ECHO. User name is %USERNAME%
SET UP=

GOTO EOF (=Subroutine code follows=)
:_USENAM (Usage: CALL %0 GOTO: _USENAM User name line)

SET USERNAME=%5

:EOF (End of file)
::====


--
William Allen


Harvey Colwell

unread,
Jul 25, 2001, 9:37:17 AM7/25/01
to
> I am writing a batch file and need it to show a users login name to them. I
> used the %username% command for Windows NT, but this will not work in 98 or
> 95. Is there a subsitute for this %username% command or a way to make it
> work in 95 / 98.

For my clients that have with Win9x workstations, I use the following
in the logon script. This way I know that the saved varibles are
always available.

The first executable, PUT IN ENVironment, you get off the net, I
forget exactly where, do a search. The second, WINSET, you get off the
Win9x CR-ROM.


REM [Set Server Name]
set server=MY_SERVER

REM [GET NET VARIBLES]
if !%OS%! == !Windows_NT! goto :SKIP_NET_VARS
echo.
echo Saving LANMAN Varibles
echo.
\\%server%\netlogon\putinenv L
\\%server%\netlogon\winset username=%username%
\\%server%\netlogon\winset computername=%computername%
:SKIP_NET_VARS

Frank-Peter Schultze

unread,
Jul 25, 2001, 2:14:27 PM7/25/01
to
"Harvey Colwell" <HarCo...@hotmail.com> schrieb im Newsbeitrag news:92da29ec.01072...@posting.google.com...

The batch file below doesn't use 3rd party utilies. It gets the
username from the registry. It's a rather slow method, but it's
language independend.

:: ------------------------------------------------------------------
:: Batchfile : username.bat (Filename important!)
:: Purpose : Sets USERNAME variable to the username.
:: OS : Windows 95+
:: Updated : Frank-Peter Schultze <fpsch...@bigfoot.de>, 20010711
:: ------------------------------------------------------------------
@echo off
if %1/==/ goto Get
if NOT %1/==/?/ goto Set
echo Sets USERNAME variable to the username.
echo.
echo [CALL] username
for %%C in (echo. goto:End) do %%C

:Get - the username from the Registry -----------------------------
set | FIND "winbootdir=" > NUL
if errorlevel 1 for %%C in (echo goto:End) do %%C Win9x Batch File.
START /wait REGEDIT /e %TEMP%.\~tmp.bxt HKEY_LOCAL_MACHINE\Network\Logon
:: 2001-07-11: ignore NetWareUsername entry (if any)
FIND /i "username" < %TEMP%.\~tmp.bxt | FIND /i "NetWareUsername" > %TEMP%.\~tmp.bat
%TEMP%.\~tmp.bat

:Set - the username Variable w/o "" -------------------------------
for %%V in (%1) do set USERNAME=%%V
del %TEMP%.\~tmp.b?t
:End --------------------------------------------------------------

--
Frank-Peter Schultze <fpsch...@my-deja.com>, http://www.fpschultze.de

0 new messages