
Running a Visual Basic Script During Logon
You may be running it absolutely fine; and you do need to run it from a bacth
file or something else.
There are 2 potential problems with WSH on Win9x clients; since you say it runs
fine when clicked, you probably are having problems with the fact that the
network info for a Win9x client doesn't get populated immediately. If you try
to use WScript.Network immediately at logon, the UserName property for example
may be empty on a Win9x client. Here's a function you can call to make the
script loop until the properties are ready:
Sub WaitFor9xWshNetwork
Set Net = CreateObject("WScript.Network")
Do while Net.Username = "": WScript.Sleep 50: Loop
End Sub
The other problem you may encounter is that the Domain property is *never*
properly filled in. Here's a function that will correctly give you the name of
the workstation's domain:
Function Domain
Dim Domain, oNet, oSh, oEnv
regDom ="HKLM\SYSTEM\CurrentControlSet\Services\" _
& "MSNP32\ NetworkProvider\AuthenticatingAgent"
regWrkgrp = "HKLM\SYSTEM\CurrentControlSet\Services\" _
& "VxD\VNETSUP\Workgroup"
Set oNet = CreateObject("Wscript.Network")
Set oSh = CreateObject("Wscript.Shell")
Set oEnv = oSh.Environment
If (oEnv("OS") = "Windows_NT") Then
Domain = oNet.UserDomain
Else
Domain = oSh.RegRead(regDom)
If (Domain = "") Then
Domain = oSh.RegRead(regWrkgrp)
End If
End If
End Function
note that both of these have been written so that they will work in scripts run
on either Win9x or NTish systems.
Quote:
> I'm a Network Admin who's very new to VBS. I've written a Visual Basic
> Script I want to run during logon. The question is, now how do I get it to
> run. I don't see anyway to run it from KixTart. I also don't see a way to
> run it from a batch file, with CScript or WScript. I can get it to execute
> with these without any errors but the script doesn't do what it's supposed
> to. I can run the script by double clicking on it and it runs fin, no errors
> and does exactly what I want it to do. Surely there has to be a way to do
> it. The clients I need to run the script are mostly Win9x. I can use some
> help, from those of you who know scripting better than I obviously do.
> Thanks.
> --Will