Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 9th, 2004, 06:48 AM
Authorized User
 
Join Date: Jun 2003
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default objNetwork.UserName

Hi,

I'vze got an issue with the following piece of code :

<script language="vbscript">
Dim strUsername, objNetwork
Set objNetwork = CreateObject("WScript.Network")
If trim(objNetwork.UserName) <> "" Then strUsername = objNetwork.Username
</script>

When I execute the code on a local PC [plain HTML], the variable gets populated with the current username logged on in Windows. When the code is located on the server, the variable gets the value of "Undefined". This worked before and seems to have changed since the servers got upgraded to Service Pack 4. Any ideas ? Or any alternative ways to get the Windows Username ? Thanks.

Sebastiaan.
 
Old August 9th, 2004, 11:10 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Sebastiaan,

I am not sure about the reason for that. But, see if this helps.

Code:
<script language="vbscript">
Dim strUsername, wshShell 
Set wshShell = CreateObject("WScript.Shell")
strUser = wshShell.ExpandEnvironmentStrings("%USERNAME%")
'This uses the Environment variable %USERNAME%
'Try Echo %USERNAME% in command prompt.
</script>
OR
Code:
<script language="vbscript">
Dim strUsername, adsNTSysInfo
Set adsNTSysInfo = CreateObject("WinNTSystemInfo")
strUsername = adsNTSysInfo.UserName
</script>
Cheers!
_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
Detect Username dparsons ASP.NET 1.0 and 1.1 Professional 2 April 12th, 2006 02:20 PM
Username Changes Ben Horne Forum and Wrox.com Feedback 2 March 12th, 2004 12:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.