Running a Visual Basic Script During Logon 
Author Message
 Running a Visual Basic Script During Logon

    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



Wed, 24 Nov 2004 13:54:49 GMT  
 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



Wed, 24 Nov 2004 14:25:11 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. How to run VB-Scripts in Visual Studio - Visual Basic 6

2. Running a VB Script during logon?

3. Writing comms logon scripts in Visual Basic ?

4. Running a VB Script from Visual Basic

5. Running Visual Basic Program from VB script

6. How to run VBScript in Visual Basic ???

7. Run a vbs file from Visual Basic

8. Running WSH VBScripts in Visual Basic

9. Logon Date/Time Script Won't Run

10. Application Update during Logon Script?

11. WSHNetwork.USerName not working during logon script

12. How can I get logon server name and IP address from logon script using wsh

 

 
Powered by phpBB® Forum Software