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!

Logon Script in VBScript

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I wrote a little Logon Script in VBScript. The Script runs fine when called on the command line (Cscript SCRIPTNAME) no matter if it is called on a Win98 or NT machine.
I used a Logon.bat (used if %OS%==Windows_NT ....) to call the script via cscript at logon. The Script runs fine on NT but i get an error on the Win98 Computer.
The Error points to this line: "strUsername = WshNetwork.UserName"
Why is this working from command line and not while login? I searched the MS Knowlegebase and found that on 95 and 98 i have to use something like this:
While strUsername = ""
strUsername = WshNetwork.UserName
WEnd

I did it, but the error still points to the line where i want to get the Username. I tried the following:
"WScript.Echo "ComputerName = " & WshNetwork.ComputerName"
getting this line on the Screnn: "ComputerName = "
Is the WshNetwork Object not working on login? Is there another way to get the Username? I need it for a logon script for 95/98/NT.

Thanks

Martin
 
Give the system sufficient time to retrieve the UserName :

While strUsername = ""
strUsername = WshNetwork.UserName
WScript.Sleep 200
WEnd

In many different instances, this is necessary to ensure the proper working of a script.

ps. If you have worry to get caught in a infinite loop, add some time limit control to breakout gracefully. But this is usually not necessary.
 
Thanks for the help. I tried it, but i still get the same error. Even if I give the system more than enough time ( sleep 2000 before and after the statement should be enough).
I wrote down the exact error. here it is: script.vbs(11,5) 0x800704DD
the strUsername= is in line 11.
Maybe someone can tell me what to do? Or is it impossible on a 9x system to retrieve the Username/domain/computername while in Logon Process?
I tried a workaround and the script now puts itself into the Registry RunOnce section, that is executet after the logon scripts. Then it works fine and without any Error.

A Second thing: Is there a function to get the groupnames the user belongs to? On NT i know it works with some tools. Any idea for 9x? Would be great if it works with WSH.

Thanks

Martin
 
Hello MartinB123.

It does seem to be a limitation on Win9x, having to wait until a logon has run its due beforehand. Standard workarounds are either
[1] that to put the script to work with the command :
WScript.exe <script file>
in a value under the key HKLM\Software\Microsoft\Windows\CurrentVersion\Run (as you probably know);
or
[2] that to drop a shortcut of it to the Startup folder.

As to the verifying of groupname a user's account belongs to, you would have to take a look into the ADSI support :


and its free resources download :


ADSI Group methods support IsMember to check whether a user is a member under a groupname.

Cannot provide more help than this. Maybe somebody may intervene if you would like to raise precise problems.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top