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

How do I get wshNetwork.UserName within a Windows 95 logon script

11 views
Skip to first unread message

Stephen Speirs

unread,
Oct 19, 1999, 3:00:00 AM10/19/99
to
Hi,

I am writing a network logon script using VBScript and am trying to retreive
the current users logon name using the wshNetwork.UserName property....

Sub GetUser
Dim wshNetwork

Set wshNetwork = WScript.CreateObject("WScript.Network")
UserName = ""
Do
UserName = wshNetwork.UserName
Loop while UserName = ""
Set wshNetwork = Nothing
End Sub

The problem is that when the above code is called from the network logon DOS
batch file, it stops with the error "The operation being requested was not
performed because the user has not logged on to the network."

How do I get round this?

Regards,

Stephen

Todd A. Scalzott

unread,
Oct 19, 1999, 3:00:00 AM10/19/99
to
You need to use a little bit of error handling to insure your routine
keeps running. I've added two lines below:

In article <eJJwz1hG$GA....@cppssbbsa02.microsoft.com>,
stephen...@sgsgroup.com says...


> Hi,
>
> I am writing a network logon script using VBScript and am trying to retreive
> the current users logon name using the wshNetwork.UserName property....
>
> Sub GetUser
> Dim wshNetwork
>
> Set wshNetwork = WScript.CreateObject("WScript.Network")
> UserName = ""

on error resume next


> Do
> UserName = wshNetwork.UserName
> Loop while UserName = ""
> Set wshNetwork = Nothing

on error goto 0


> End Sub
>
> The problem is that when the above code is called from the network logon DOS
> batch file, it stops with the error "The operation being requested was not
> performed because the user has not logged on to the network."
>
> How do I get round this?
>
> Regards,
>
> Stephen
>
>
>

--
Todd A. Scalzott to...@kastle.com
Director, Information Technology Kastle Systems, LLC
(703) 528-8800

Stephen Speirs

unread,
Oct 19, 1999, 3:00:00 AM10/19/99
to
Thanks Todd, but I'm afraid it still doesn't work - it just sits in a loop
indefinetely. Also, I don't think "On Error Goto 0" is valid in VBScript (VB
yes, VBScript no).

Todd A. Scalzott <to...@kastle.com> wrote in message
news:MPG.12763c46b...@msnews.microsoft.com...

Manfred Braun

unread,
Oct 19, 1999, 3:00:00 AM10/19/99
to
Hi Stephen,

this discussion has a long history now. I got it never working on
W95(A!!!!!), even with all posted tricks. The most importent tip for me,
comes some days ago, where someone (???) in this groups posted to use the
old "PUTINENV.EXE" to get the username while running the logon (.BAT) script
and after this, read the environment variable by WSH (PUTINENV.EXE put's
it's results in the environment). I made only one first step to see, that
PUTINENV.EXE will really work with W95A and it did. So it should be possible
to read the username (and other network settings - PUTINENV.EXE is a very
small but powerful tool).

Best regards,
Manfred Braun

(Private)
Lange Roetterstrasse 7
D68167 Mannheim
Germany

mailto:_mbr...@manfred.mannheim-netz.de
(Remove the anti-spam-underscore to mail me!)

Stephen Speirs <stephen...@sgsgroup.com> schrieb in im Newsbeitrag:
uqSVjwjG$GA....@cppssbbsa02.microsoft.com...

Mike Whalen (MS)

unread,
Oct 19, 1999, 3:00:00 AM10/19/99
to

Just a note - On Error Goto 0 is legal in VBScript. It isn't documented, an
unintended omission.

Mike Whalen
Windows Script Dev


Stephen Speirs <stephen...@sgsgroup.com> wrote in message
news:uqSVjwjG$GA....@cppssbbsa02.microsoft.com...

Todd A. Scalzott

unread,
Oct 20, 1999, 3:00:00 AM10/20/99
to
Search dejanews for a prior post of mine on this issue. Some Win95
machines that utilize cscript will never complete. I have posted a
routine a couple weeks back that obtains it from the registry after a
period of retries.

On error goto 0, while not documented, works just great in VBScript and
is very useful.

In article <uqSVjwjG$GA....@cppssbbsa02.microsoft.com>,
stephen...@sgsgroup.com says...

Stephen Speirs

unread,
Oct 21, 1999, 3:00:00 AM10/21/99
to
Todd,

Do you have a URL for dejanews - it is a new one to me. And yes you're
right, 'On Error Goto 0' does work - my appologies.

Thanks again,

Stephen


Todd A. Scalzott <to...@kastle.com> wrote in message

news:MPG.1277c797a...@msnews.microsoft.com...

Bill James

unread,
Oct 21, 1999, 3:00:00 AM10/21/99
to
It's a tough one <g> - www.dejanews.com.

Bill James

Stephen Speirs <stephen...@sgsgroup.com> wrote in message

news:##p2Xo6G$GA.250@cppssbbsa04...

Jim Ley

unread,
Oct 21, 1999, 3:00:00 AM10/21/99
to

Bill James <wgj...@NOSPAMearthlink.net> wrote in message
news:#JkJz96G$GA.249@cppssbbsa05...

> It's a tough one <g> - www.dejanews.com

It is but they've rebranded and are now just deja.com so http://deja.com is
the one they now encourage (I imagine dejanews.com won't disappear ever
though.

Jim.

Todd A. Scalzott

unread,
Oct 21, 1999, 3:00:00 AM10/21/99
to
If I keep calling it DejaNews, perhaps I'll forget how downhill the site
has gone over the past 8 months. :)

--
Todd A. Scalzott to...@kastle.com
Director, Information Technology Kastle Systems, LLC
(703) 528-8800

In article <Ox7$QI7G$GA...@cppssbbsa02.microsoft.com>, J...@jibbering.com
says...

Tom Lavedas

unread,
Oct 21, 1999, 3:00:00 AM10/21/99
to
If you mean "more commercial", I agree. But even .COM businesses have
to make money someday. There eventually has to be SOME justification
for their soaring stock values.

Regrettably, there really is no such thing as a free lunch (nor a free
web resource). Either the archive needs to be subscription based,
handled by a 'not-for-profit' (such as with the W3 consortium) or,
unfortunately, we will have to put up with the ads to keep it in
business.

Tom Lavedas
-----------
http://www.pressroom.com/~tglbatch/

Jesper Tim Jacobsen

unread,
Oct 23, 1999, 3:00:00 AM10/23/99
to
Hej "Stephen Speirs" <stephen...@sgsgroup.com>

Den Tue, 19 Oct 1999 15:13:54 +0100, skrev du:

>Thanks Todd, but I'm afraid it still doesn't work - it just sits in a loop
>indefinetely. Also, I don't think "On Error Goto 0" is valid in VBScript (VB
>yes, VBScript no).

Use wscript instead of cscript.

0 new messages