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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I make this script run from the logon.bat file

Status
Not open for further replies.

Scruby

IS-IT--Management
Jul 16, 2003
143
US
I have wrote a VBScript that is call out from a .BAT file. The script creates a folder and file, writes the user name and computer name to this file. The script will not run when called from the .BAT file, however when I go to explorer and double click on this .VBS file the script runs just fine. Has anyone seen this before? How can I make this script run from the logon.bat file. See Below.

*************.BAT file**********************
REM logon.bat 09-??-2003
REM script created to logon to win 9x boxes, 2000, and xp

REM Everyone gets this


if (%OS%) == (Windows_NT) goto end

rem 9x doesn't auto mount the home dirs..?

net use u: /home

REM net time %SERVER% /set /yes

:end

start wscript \\moose\netlogon\AddUser.vbs (This is the .vbs file that will not run)

start wscript \\moose\netlogon\bblogon.vbs
*********************end*******************************
****************AddUser.vbs*****************************
Option Explicit

Dim WshShell, WshNetwork, WProcessEnv, DriveObj, UserLog, UserLogObj, FileServer
Dim FileSysObj, Share, EnvWinDir, EnvTempDir, EnvLogonServer, WshprocessEnv

'Set up some objects for use later
Set FileSysObj = CreateObject("Scripting.FileSystemObject")
Set WshNetwork = Wscript.CreateObject("Wscript.Network")
Set WshShell = Wscript.CreateObject("Wscript.Shell")
Set WshprocessEnv = Wshshell.Environment ("Process")

EnvWinDir = WshprocessEnv("windir")
EnvTempDir = WshProcessEnv ("Temp")
EnvLogonServer = WshProcessEnv("LogonServer")

'Make sure a folder exist to put the event log into.
If FileSysObj.FolderExists(EnvTempDir) = False Then _
FileSysObj.CreateFolder (EnvTempDir)

If FileSysObj.FolderExists("C:\LogonEvent") = False _
Then FileSysObj.CreateFolder ("C:\LogonEvent\")

'Get the log of events file, and check to see if it is too big
If FileSysObj.FileExists("C:\LogonEvent\Events.Log") = True Then
Set UserLogObj = FileSysObj.GetFile("C:\LogonEvent\Events.log")

If UserLogObj.Size > 128000 Then _
FileSysObj.DeleteFile("C:\LogonEvent\Events.log")
Else
End If

'Open the log of events file for appending
Set UserLog = FileSysObj.OpenTextFile("C:\LogonEvent\Events.log", _
8, True)


'Envoke the event logging process
Call OpenLogFile


UserLog.WriteBlankLines (2)
UserLog.Close

Function MapDrive (Drive)
on error resume next
If FilesysObj.DriveExists(FileServer & Share) = True Then
UserLog.WriteLine ("Server and Share Exist " & FileServer & Share)
WshNetwork.RemoveNetworkDrive Drive
WshNetwork.MapNetworkDrive Drive, FileServer & Share
UserLog.Writeline ("Drive re-Mapping was successful" _
& UCase(Drive) & " to " & FileServer & Share)
Else
WshNetwork.MapNetworkDrive Drive, FileServer & Share
UserLog.WriteLine ("Drive mapping was successful" & UCase(Drive)) _
& " to " & FileServer & Share


MsgBox "The Logon Script was unable to Map " & FileServer & Share & " to " & vbCrLf
UserLog.WriteLine ("Drive mapping Failed " & FileServer & Share & " to Drive " & UCase (Drive))
End If
End Function

Sub OpenLogFile()
UserLog.WriteLine ("-----------------------------------------")
UserLog.WriteLine (Date & " " & Time)
UserLog.WriteLine ("Logon Domain: " & WshNetwork.UserDomain)
UserLog.WriteLine ("Computer: " & WshNetwork.ComputerName)
UserLog.WriteLine ("User: " & WshNetwork.UserName)
UserLog.WriteBlankLines (1)
End Sub
 
What do you get when the batch file runs? Any error at all?

I'm not familiar with the "start wscript" syntax. I've usually called VBScript from .BAT files by using "cscript.exe scriptname.vbs". I don't see why you shouldn't be able to do the same thing with wscript.exe.

Also, is it possible that the system that you are running it on doesn't have Windows Script Host installed?

Just a couple thoughts.
 
Kmcferrin,
Had to add this to the script, must have been a timing issue with the older 95/98 boxes.

strNTName = ""
On Error Resume Next
Err.Clear
Do While strNTName = ""
strNTName = WshNetwork.UserName
Err.Clear
If WScript.Version > 5 Then
WScript.Sleep 100
End If
Loop
On Error GoTo 0

Thanks for your help, Scruby
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top