Page 1 of 1 1
Topic Options
#183521 - 2007-12-12 01:11 PM %username% and @USERID sometimes not working
RachidH Offline
Fresh Scripter

Registered: 2006-05-04
Posts: 18
Loc: The Netherlands
When I have a batch file mapping a drive like this:
net use H: \\SERVER\HomeDirs\%username%

or a Kixscript mapping a drive like this:
use H: \\SERVER\HomeDirs\@UserId

Sometimes the username/userid isn't resolved properly.
I need the pre-Windows 2000 user logon name, but it seems that it sometimes uses the Active Directory user logon name, which is empty.
How can I make sure that definitly get the pre-Windows 2000 user logon name ? ;\)

Top
#183531 - 2007-12-12 02:38 PM Re: %username% and @USERID sometimes not working [Re: RachidH]
mikeemikee Offline
Fresh Scripter

Registered: 2007-06-12
Posts: 23
Loc: Germany, Hildesheim
I would do it this way

dim $username
$username=@wuserid

use h: \\server\homedirs\$username

Top
#183545 - 2007-12-12 04:51 PM Re: %username% and @USERID sometimes not working [Re: mikeemikee]
RachidH Offline
Fresh Scripter

Registered: 2006-05-04
Posts: 18
Loc: The Netherlands
hi,
wuserid might be a good idea yes, but why do you dim the variable first ?

Top
#183550 - 2007-12-12 05:14 PM Re: %username% and @USERID sometimes not working [Re: RachidH]
DStelz Offline
Getting the hang of it

Registered: 2007-01-26
Posts: 72
Loc: Green Bay, WI
It's just good practice to declare variables before they're used.
Top
#183561 - 2007-12-12 09:27 PM Re: %username% and @USERID sometimes not working [Re: DStelz]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
To continue on the best practice subject.

Putting quotes around the servername and the share will save you a lot of pain when somebody decides to use spaces. Also the @USERID macro should not be put between the quotes. The code below has always worked fine for me.

 Code:
Use H: "\\server\share\" + @USERID
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#183572 - 2007-12-12 11:26 PM Re: %username% and @USERID sometimes not working [Re: Mart]
RachidH Offline
Fresh Scripter

Registered: 2006-05-04
Posts: 18
Loc: The Netherlands
ah yes, the quotes i forgot in my sample, but they're there :-)
hopefully it'll fix the problem.
time will tell !

still strange that net use H: "\\SERVER\HomeDirs\%username"% sometimes doesn't work in batchfiles though...

Top
#183574 - 2007-12-12 11:53 PM Re: %username% and @USERID sometimes not working [Re: RachidH]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
I don't know why %username% sometimes does not work in batch files but if you use it in kix scripts you might want to take a look at the ExpandEnvironmentVariables function.

Oh, and I guess it's a typo but in your last example the ending quote is misplaced.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2924 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.063 seconds in which 0.03 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org