[dba-Tech] Windows Update

Gustav Brock gustav at cactus.dk
Sat Oct 18 03:34:18 CDT 2014


Hi Jim

Sure. Nothing fancy:

<vbscript>
Option Explicit

' Main script

  Dim strNetBIOSDomain
  Dim strNTName
  Dim strNTPath
  Dim strNTProvider
  Dim varNull
  Dim IsMemberOfCactusData
  Dim IsMemberOfTeamCactus

  Dim objShell
  Dim objNetwork
  Dim objGroupNames

  Set objShell = CreateObject("WScript.Shell")
  Set objNetwork = CreateObject("Wscript.Network")

  strNetBIOSDomain = EnvString("userdomain")
  strNTName = EnvString("username")
  strNTPath = strNetBIOSDomain & "/" & strNTName
  strNTProvider = "WinNT://" & strNTPath

  IsMemberOfCactusData = IsMemberOfGroup("CactusData")
  IsMemberOfTeamCactus = IsMemberOfGroup("TeamCactus")

  If IsMemberOfTeamCactus Then
    Call MapDrive("i", "\\cactus.dom\cactus data\inst")
    Call MapDrive("s", "\\cactus.dom\cactus data\data\database")
    Call MapDrive("t", "\\cactus.dom\cactus data\data\document")
    Call MapDrive("u", "\\cactus.dom\cactus data\data\internal\privat")
  ElseIf IsMemberOfCactusData Then
    Call MapDrive("i", "\\cactus.dom\cactus data\inst")
    'Call MapDrive("n", "\\cactus.dom\cactus data\data")
    Call MapDrive("p", "\\cactus.dom\cactus data\data\internal")
    Call MapDrive("r", "\\cactus.dom\cactus data\data\codebase")
    Call MapDrive("s", "\\cactus.dom\cactus data\data\database")
    Call MapDrive("t", "\\cactus.dom\cactus data\data\document")
    Call MapDrive("u", "\\cactus.dom\cactus data\data\internal\privat")
  ElseIf LCase(strNTName) = "skan" Then
    Call MapDrive("i", "\\cactus.dom\cactus data\inst")
    Call MapDrive("t", "\\cactus.dom\cactus data\data\document")
  ElseIf LCase(strNTName) = "backuser" Then
    Call MapDrive("i", "\\sanzibar\inst")
    Call MapDrive("m", "\\sanzibar\data")
  Else
    Call MapDrive("i", "\\cactus.dom\cactus data\inst")
    Call MapDrive("s", "\\cactus.dom\cactus data\data\database")
    Call MapDrive("t", "\\cactus.dom\cactus data\data\document")
    Call MapDrive("u", "\\cactus.dom\cactus data\data\internal\privat")
  End If
  If LCase(strNTName) = "gustav" Or LCase(strNTName) = "cactus" Then
    Call MapDrive("q", "\\cactus.dom\cactus data\data\external")
  End If

  varNull = objGroupNames.RemoveAll()
  Set objGroupNames = Nothing
  Set objNetwork = Nothing
  Set objShell = Nothing

' End script
' -----------------------------------------------------

Private Sub MapDrive(strDriveLetter, strUNC)
' Map a drive to strUNC.
'''    On Error Resume Next
    strDriveLetter = Chr(Asc(strDriveLetter)) & ":"
    objNetwork.MapNetworkDrive strDriveLetter, strUNC
    If (Err.Number <> 0) Then
        On Error GoTo 0
        objNetwork.RemoveNetworkDrive strDriveLetter, True, True
        objNetwork.MapNetworkDrive strDriveLetter, strUNC
    End If
    On Error GoTo 0

End Sub
 

Private Function IsMemberOfGroup(strGroupName)
' Checks if the current user is a group member of groupName.

    Dim objUser
    Dim objGroup

    If IsEmpty(objGroupNames) Then
        Set objGroupNames = CreateObject("Scripting.Dictionary")
        objGroupNames.CompareMode = vbTextCompare
        Set objUser = GetObject(strNTProvider & ",user")
        For Each objGroup in objUser.Groups
            objGroupNames.Add objGroup.Name, True
        Next
        Set objGroup = Nothing
        Set objUser = Nothing
    End if

    IsMemberOfGroup = CBool(objGroupNames.Exists(strGroupName))

End Function


Private Function EnvString(strEnvironmentVariable)
' Returns the value from Environment of the environment variable strEnvironmentVariable.

    strEnvironmentVariable = "%" & strEnvironmentVariable & "%"
    EnvString = objShell.ExpandEnvironmentStrings(strEnvironmentVariable)

End Function
</vbscript>

/gustav
________________________________________
Fra: dba-tech-bounces at databaseadvisors.com <dba-tech-bounces at databaseadvisors.com> på vegne af Jim Lawrence <accessd at shaw.ca>
Sendt: 18. oktober 2014 04:21
Til: Discussion of Hardware and Software issues
Emne: Re: [dba-Tech] Windows Update

Hi Gustav:

Would you have a script that I could take a look at? If you don't think that is a good idea, fine but if its OK, sent it either online or offline. :-)

Jim

----- Original Message -----
From: "Gustav Brock" <gustav at cactus.dk>
To: "Discussion of Hardware and Software issues" <dba-tech at databaseadvisors.com>
Sent: Friday, October 17, 2014 3:01:02 PM
Subject: Re: [dba-Tech] Windows Update

Hi Jim

I've never heard of such issues. On the other hand, I do all testing connecting to our AD; then DNS etc. are assigned by the login script, so it always works. I never touch the hostfile.

/gustav


More information about the dba-Tech mailing list