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
*************.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