Share your logon scripts??? - SMB

This is a discussion on Share your logon scripts??? - SMB ; Hi, I've been using a .bat file for the past several years, but lately when I see folks sample smb.conf(s) they're using a .vbs instead Anyone able to post their .vbs file for a looksee? TIA Steve...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Share your logon scripts???

  1. Share your logon scripts???

    Hi,

    I've been using a .bat file for the past several years, but lately when I
    see folks sample smb.conf(s) they're using a .vbs instead

    Anyone able to post their .vbs file for a looksee?

    TIA
    Steve



  2. Re: Share your logon scripts???

    Here is one that is probably more complicated than you want, but it shows
    the possibilities.
    I actually use a bat file as the logon script since Win9x clients can't use
    a vbs logon script directly. The bat file calls this script. Note that vbs
    isn't very good at some things, (like setting environment variables or
    running system commands) so I handle those in another bat script that is
    created by this vbs script and run from the logon bat script that called
    this vbs script. Got that?
    Mark


    ' --- This "startup.vbs" connection file is called from
    ' --- a common logon batch file. Mark 8-14-2003

    Option Explicit
    Dim oNet, oWsh, oEnv, oFS, oBatFile, oLogFile
    Dim sUserName, sGroup, sOpSys, sMailUser, sMyPath, sPrn, sRes
    Dim sCompName
    Set oNet = CreateObject("WScript.Network")
    Set oWsh = CreateObject("WScript.Shell")
    Set oEnv = oWsh.Environment
    Set oFS = CreateObject("Scripting.FileSystemObject")

    ' --- Make a log file in which to write our results
    Set oLogFile = oFS.CreateTextFile("c:\TMaLog.txt", True)
    oLogFile.WriteLine("Start time " & Now)

    sOpSys = oEnv("OS") ' is Windows_NT for Win2k

    ' Get the user name. On Windows 9x, the user will not be logged
    ' on when the script starts running; keep checking every
    ' second until he or she is logged on.

    If sOpSys <> "Windows_NT" then
    sOpSys = "Win9x"
    on error resume next
    sUserName = oNet.UserName

    Do While sUserName = ""
    Wscript.Sleep 1000
    sUserName = oNet.UserName
    Loop
    Else
    sUserName = oNet.UserName
    End If

    sCompName = oNet.ComputerName
    oLogFile.WriteLine("User=" & sUserName & " OS=" & sOpSys & " Machine=" &
    sCompName)

    ' Most users are in the engin group, make an entry here for the others.
    Select Case sUserName
    Case "pam"
    sGroup = "admin"
    Case "danny"
    sGroup = "draft"
    Case "barry"
    sGroup = "draft"
    Case ELSE
    sGroup = "engin"
    End Select

    oLogFile.WriteLine("PmailUser=" & sMailUser & " Group=" & sGroup)

    ' --- Everyone needs the following two connections.
    Call MapDrive("O","\\gecko\office","Office resource.")
    Call MapDrive("P","\\gecko\p-mail","P-mail resource.")

    ' --- Additional connections for some groups.
    Select Case sGroup
    Case "draft"
    Call MapDrive("X","\\gecko\drawings","Drawings resource.")
    Case "engin"
    Call MapDrive("X","\\gecko\drawings","Drawings resource.")
    Call MapDrive("F","\\gecko\engineer","Engineering programs.")
    Call MapDrive("G","\\gecko\engndata","Engineering data.")
    End Select

    ' ---Some Win2k machines need LPT mapping so engineering DOS programs can
    print.
    If (sOpSys = "Windows_NT") AND (sGroup = "engin") then
    sPrn = "LPT1"
    Select Case sCompName
    Case "ATH2100-3"
    sRes = "\\gecko\hp4600dn"
    Case "ATH2100-2"
    sRes = "\\gecko\hp4600dn"
    Case "P3550-3"
    sRes = "\\P2450-2\laser5"
    Case ELSE
    sPrn = "none"
    End Select

    If not (sPrn = "none") then
    Call MapPrinter(sPrn,sRes)
    End If
    End If

    ' ---Sychronize the local Word macros with the copy on the server---
    If sOpSys = "Windows_NT" then
    sMyPath = oWsh.ExpandEnvironmentStrings("%APPDATA%") & _
    "\Microsoft\Word\Startup\"
    Else
    sMyPath = "C:\Windows\Application Data\Microsoft\Word\Startup\"
    End If
    If oFS.FolderExists(sMyPath) then
    Call SyncFile("TMaGlobal.dot", sMyPath, "O:\Forms\TMaWordGlobal\")
    End If


    ' --- Make a regular dos batch file to handle environment variables and
    ' --- other tasks that VBscript can't do very well.
    ' --- The batch file will be called from the batch file that called this vbs
    file.
    Set oBatFile = oFS.CreateTextFile("c:\setEnv.bat", True)
    oBatFile.WriteLine("@echo off")
    If (sOpSys = "Windows_NT") then
    oBatFile.WriteLine("\\gecko\netlogon\setx PMuser " & sMailUser)
    Else
    oBatFile.WriteLine("\\gecko\netlogon\winset PMuser=" & sMailUser)
    End If
    oBatFile.Close
    Set oBatFile = Nothing

    oLogFile.WriteLine (vbCrLf & "Successful Completion.")
    oLogFile.Close
    Set oLogFile = Nothing


    ' +++++Subroutine to map network drives and log results+++++
    Sub MapDrive(sLetter,sShare,sMsg)
    Dim colNetDrives, i
    oLogFile.WriteLine (vbCrLf & "Connecting drive " & sLetter & " to " & sMsg)
    If oFS.DriveExists(sLetter) then
    Set colNetDrives = oNet.EnumNetworkDrives
    For i = 0 to colNetDrives.Count -1 Step 2
    If colNetDrives(i) = sLetter & ":" then
    oLogFile.WriteLine ("Drive " & sLetter & " already mapped. Deleting it
    first.")
    oNet.RemoveNetworkDrive sLetter & ":"
    End If
    Next
    ' see if that fixed it
    If oFS.DriveExists(sLetter) then
    oLogFile.WriteLine ("Drive " & sLetter & " is a real drive. Skipping
    map.")
    Exit Sub
    End If
    End If
    oNet.MapNetworkDrive sLetter & ":", sShare
    End Sub


    ' +++++Subroutine to map network printer and log results+++++
    Sub MapPrinter(sLetter,sShare)
    Dim colNetPrinters, i
    oLogFile.WriteLine (vbCrLf & "Connecting " & sLetter & " to " & sShare)
    Set colNetPrinters = oNet.EnumPrinterConnections
    For i = 0 to colNetPrinters.Count -1 Step 2
    If colNetPrinters(i) = sLetter then
    oLogFile.WriteLine ("Port " & sLetter & " already mapped. Deleting it
    first.")
    oNet.RemovePrinterConnection sLetter
    End If
    Next

    on error resume next
    Err.Number = 0
    oNet.AddPrinterConnection sLetter, sShare, FALSE
    If Err.Number <> 0 then
    MsgBox "Couldn't connect " & sLetter & " to " & sShare & " --skipping
    it."
    End If
    End Sub


    ' +++++Subroutine to synchronize a file+++++
    Sub SyncFile(sFilename, sLocalPath, SsourcePath)
    dim oFile1, oFile2
    ' Can't sync if the Source file doesn't exist.
    If not oFS.FileExists(sSourcePath & sFilename) then
    oLogFile.WriteLine (vbCrLf & "The source file" & sSourcePath & sFilename &
    " does not exist!")
    Exit sub
    End If

    ' ---Is there already a local file?, then sync----
    If oFS.FileExists(sLocalPath & sFilename) then
    Set oFile1 = oFS.GetFile(sLocalPath & sFilename)
    Set oFile2 = oFS.GetFile(sSourcePath & sFilename)
    If oFile1.DateLastModified < oFile2.DateLastModified then
    'the copy will fail if the local file is read-only
    oFile1.attributes = 0
    oFile2.Copy sLocalPath & sFilename, True
    oLogFile.WriteLine (vbcrLf & "Updated file " & sLocalPath & sFilename)
    Else
    oLogFile.WriteLine (vbCrLf & "File " & sLocalPath & sFilename & " is up to
    date.")
    End If
    Exit sub
    End If

    ' ---No local file, just copy the source---
    Set oFile2 = oFS.GetFile(sSourcePath & sFilename)
    oFile2.Copy sLocalPath & sFilename
    oLogFile.WriteLine (vbCrLf & "File " & sLocalPath & sFilename & "
    created.")
    End Sub



    "Steve Morley" wrote in message
    news:c292514416eead6fd13f14a2615cae30@grapevine.is landnet.com...
    > Hi,
    >
    > I've been using a .bat file for the past several years, but lately when I
    > see folks sample smb.conf(s) they're using a .vbs instead
    >
    > Anyone able to post their .vbs file for a looksee?
    >
    > TIA
    > Steve
    >
    >




  3. Re: Share your logon scripts???

    Hi Mark,

    > I actually use a bat file as the logon script since Win9x clients can't

    use
    > a vbs logon script directly.


    Thanks for the posting, I'll go through your script, but the above tells me
    that I should probably stick with my .bat for now, as all the machines
    are currently 98.

    Steve



+ Reply to Thread