Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need some help - WSH

Status
Not open for further replies.

wbjones

MIS
Dec 21, 2002
1
US
I am using Windows Scripting Host to build a multi-platform virus update utility. Some of the computers it will be used on are Windows 98 and I need to check and see if the user is logged on or hit 'cancel' when prompted for username/password.

I am using the wscript.network.username property to determine if the username is null, but it errors no matter what on Windows 98. Does anyone know of any way to determine if a win98 user is logged on without crashing the WSH? By the way, I am using Javascript for this.

Any help would be much appreciated!
 
Windows 98SE has good example of getting current username:

// Windows Script Host Sample Script
//
// ------------------------------------------------------------------------
// Copyright (C) 1996 Microsoft Corporation
//
// You have a royalty-free right to use, modify, reproduce and distribute
// the Sample Application Files (and/or any modified version) in any way
// you find useful, provided that you agree that Microsoft has no warranty,
// obligations or liability for any Sample Application Files.
// ------------------------------------------------------------------------
//
// This sample demonstrates how to use the WSHNetwork object.
// It reads network properties (username and computername),
// connects, disconnects, and enumerates network drives.

var vbOKOnly = 0;
var vbOKCancel = 1;
var vbYesNo = 4;
var vbQuestion = 32;
var vbInformation = 64;
var vbCancel = 2;
var vbYes = 6;

var L_Welcome_MsgBox_Message_Text = "This script demonstrates how to use the WSHNetwork object.";
var L_Welcome_MsgBox_Title_Text = "Windows Scripting Host Sample";
Welcome();

//////////////////////////////////////////////////////////////////////////////////
//
// WSH Network Object.
//

var WSHShell = WScript.CreateObject("WScript.Shell");
var WSHNetwork = WScript.CreateObject("WScript.Network")
var colDrives, SharePoint



function Ask(strAction){
// This function asks the user whether to perform a specific "Action"
// and sets a return code or quits script execution depending on the
// button that the user presses. This function is called at various
// points in the script below.
}

//////////////////////////////////////////////////////////////////////////////////
//
// Show WSHNetwork object properties
//
//
WSHShell.Popup("UserDomain\t= " + WSHNetwork.UserDomain +
"\r\nUserName\t= " + WSHNetwork.UserName +
"\r\nComputerName\t= " + WSHNetwork.ComputerName,
0,
"WSHNetwork Properties",
vbInformation + vbOKOnly );

//////////////////////////////////////////////////////////////////////////////////
//
// WSHNetwork.EnumNetworkDrive
//
//
//Ask user whether to enumerate network drives
if (Ask("Do you want to enumerate connected network drives?")) {
//Enumerate network drives into a collection object of type WshCollection
var colDrives = WSHNetwork.EnumNetworkDrives();

//If no network drives were enumerated, then inform user, else display
//enumerated drives
if (colDrives.length == 0) {
WSHShell.Popup("There are no drives to enumerate.",
0,
L_Welcome_MsgBox_Title_Text,
vbInformation + vbOKOnly );
} else {
strMsg = "Current network drive connections: \r\n";
for (i = 0; i < colDrives.length; i += 2) {
strMsg = strMsg + &quot;\r\n&quot; + colDrives(i) + &quot;\t&quot; + colDrives(i + 1);
}

WSHShell.Popup(strMsg,
0,
L_Welcome_MsgBox_Title_Text,
vbInformation + vbOKOnly );
}
}

//////////////////////////////////////////////////////////////////////////////////
//
// Welcome
//
function Welcome() {
var WSHShell = WScript.CreateObject(&quot;WScript.Shell&quot;);
var intDoIt;

intDoIt = WSHShell.Popup(L_Welcome_MsgBox_Message_Text,
0,
L_Welcome_MsgBox_Title_Text,
vbOKCancel + vbInformation );
if (intDoIt == vbCancel) {
WScript.Quit();
}
}

One interesting thing:
If you will try to execute this script on startup step, most likly you will get nothing becouse you are not yet logged in at that time you are trying to execute it.
Solution: use the sleep method or loop
 
If you are doing this during the logon, 98 and Me set there username variables to late in the login process for you to get the username straight from the WSH.network. So you have to write a batch file that loads the script (Don't forget to use start &quot;yourscript&quot;) and that batch file will be what you execute (not the script).

And you have to make your script look like this:

Dim net
Dim strUserName

strUserName = &quot;&quot;
On Error resume next

set net = Wscript.CreateObject(&quot;Wscript.Network&quot;)

while strUserName = &quot;&quot;
strUserName = net.UserName
wend
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top