Kaseya Community

admin vbscripts

  • '''''' BIGFILES to CSV, this will create a list of file sizes over 1 GB, change the number to increase file size requirements, 

    '''' change the drive to search a other then c: or delete 'where drive =' to scan all drives.

    On Error Resume Next

    CONST ForReading = 1, ForWriting = 2, ForAppending = 8

    set oFSO = CreateObject("Scripting.FileSystemObject")

    oFSO.CreateTextFile "c:\test.csv", true

    set sText = oFSO.OpenTextFile("c:\bigfiles.csv", ForAppending, true)

    sText.WriteLine "Folder" & "," &  "Size"

    strComputer = "."

    Set objWMIService = GetObject("winmgmts:" _

       & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colFolders = objWMIService.ExecQuery("Select * from Win32_Directory where Drive = 'c:'")

    For Each objFolder in colFolders

     Set filesys = CreateObject("scripting.FileSystemObject")

     set ofolder = filesys.GetFolder(objFolder.Name)

     IF ofolder.Size > 1073741824 Then

    If ofolder.ParentFolder <> "C:\Windows" Then

    sText.WriteLine objFolder.Name & "," & size(ofolder.Size) & vbTab

    End IF

     End IF

    Next

    sText.Close()

    '''''''''''''''''FUNCTIONS ''''''''''''''''''

    Function size(Bytes)

    If Bytes >= 1073741824 Then

        size = FormatNumber(Bytes / 1024 / 1024 / 1024, 0, -1) & " GB"

    End If

    End Function

  • 'The following writes a Results.log file to c:\ with all file names with the below extentions

    ' I'm not really sure why you'd need this but it was requested by a customer

    On Error Resume Next

    '''''''''''''''''''Declarations ''''''''''''''''''''''

    Dim filetxt, FSO, objDir, ftype

    Const ForReading = 1, ForWriting = 2, ForAppending = 8

    Set FSO = CreateObject("Scripting.FileSystemObject")

    Set objDir = FSO.GetFolder("c:\") ' this sets where to look

    ''''' This is an array with 100 place holders, if you need more add it in the 1st () ''''''''''''

    Dim filetype(100)

    flietype(0) = "txt"

    filetype(1) = "pdf"

    filetype(2) = "doc"

    filetype(3) = "docx"

    filetype(4) = "docm"

    filetype(4) = "dotx"

    filetype(5) = "dotm"

    filetype(6) = "xls"

    filetype(7) = "xlsx"

    filetype(8) = "xlsm"

    filetype(9) = "xltx"

    filetype(10) = "xltm"

    filetype(11) = "xlsb"

    filetype(12) = "xlam"

    filetype(13) = "ppt"

    filetype(14) = "pptx"

    filetype(15) = "pptm"

    filetype(16) = "ppam"

    filetype(17) = "ppsx"

    filetype(18) = "accdb"

    filetype(19) = "accde"

    filetype(20) = "accdt"

    filetype(21) = "accdr"

    filetype(22) = "pst"

    filetype(23) = "ost"

    filetype(24) = "mdb"

    filetypea(25) = "mdbx"

    ''''' this statement loops through each of the above file extensions and calls the sub file below'''''''''''''''

    For Each x In filetype

    ftype = x

    file(objDir)

    Next

    ''''''' Sub statment that actually performs the lookup.

    sub file(ByRef objDir)

    For Each i In objDir.Files

    If LCase(Right(Cstr(i.Name), 3)) = ftype Then

    Set filetxt = FSO.OpenTextFile("c:\Results.log", ForAppending, True)

    path = FSO.GetAbsolutePathName(i)

    filetxt.WriteLine(path)

    filetxt.Close

    End If

    Next

    For Each i In objDir.SubFolders

    file(i)

    Next

    End sub

    Set filetxt = Nothing

    Set FSO = Nothing

    Set objDir = Nothing

    Set ftype = Nothing

  • ' we use a variation built from this to submit tickets to helpdesk on agent install for a list of software needing to be installed

    On Error Resume Next

    const HKEY_LOCAL_MACHINE = &H80000002

    Set WshShell = WScript.CreateObject("WScript.Shell")

    strComputer = "."

    Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ 

    strComputer & "\root\default:StdRegProv")

    strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"

    oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

     

     

    For Each subkey In arrSubKeys

    sDisplay= WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & subkey & "\DisplayName")

    sValue = RegExpTest("Microsoft Office", sDisplay)

    If sValue <> "" Then

    'here you can sub this in instead of Wscript.Echo

    'WshShell.LogEvent 4, "Ticket Triger" & vbCrlf & sDisplay ' this will write to the event log as info wsh source 

    Wscript.Echo sDisplay

    End If

    Next

     

    Function RegExpTest(patrn, strng)

       Dim regEx, Match, Matches   ' Create variable.

       Set regEx = New RegExp   ' Create a regular expression.

       regEx.Pattern = patrn   ' Set pattern.

       regEx.IgnoreCase = True   ' Set case insensitivity.

       regEx.Global = True   ' Set global applicability.

       Set Matches = regEx.Execute(strng)   ' Execute search.

       For Each Match in Matches   ' Iterate Matches collection.

          RetStr = Match.Length

       Next

       RegExpTest = RetStr

    End Function

  • ' I put this one together for someone on the forum here, it will list service properties for any service using Administrator as the login 

     

    Set WshShell = WScript.CreateObject("WScript.Shell")

    Set objSysInfo = CreateObject("WinNTSystemInfo")

    sDomain = objSysInfo.DomainName

    Const ForAppending = 8

    strComputer = "."

    Set objSysInfo = CreateObject ("WinNTSystemInfo")

    computerName = objSysInfo.ComputerName

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    Set objLogFile = objFSO.OpenTextFile("c:\support\maniron\" & computerName & "_Service_List.csv", ForAppending, True)

    objLogFile.Write _

        ("System Name,Service Name,Service Type,Service State, Exit " _ 

            & "Code,Process ID,Can Be Paused,Can Be Stopped,Caption," _ 

            & "Description,Can Interact with Desktop,Display Name,Error " _

            & "Control, Executable Path Name,Service Started," _ 

            & "Start Mode,Account Name ") 

    objLogFile.Writeline

    Set objWMIService = GetObject("winmgmts:" _

        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colListOfServices = objWMIService.ExecQuery _

            ("Select * from Win32_Service")

    sAdmin = ".\Administrator"

    For Each objService in colListOfServices

    IF objService.StartName = sAdmin Then

        objLogFile.Write(objService.SystemName) & "," 

        objLogFile.Write(objService.Name) & "," 

        objLogFile.Write(objService.ServiceType) & "," 

        objLogFile.Write(objService.State) & "," 

        objLogFile.Write(objService.ExitCode) & "," 

        objLogFile.Write(objService.ProcessID) & "," 

        objLogFile.Write(objService.AcceptPause) & "," 

        objLogFile.Write(objService.AcceptStop) & "," 

        objLogFile.Write(objService.Caption) & "," 

        objLogFile.Write(objService.Description) & "," 

        objLogFile.Write(objService.DesktopInteract) & "," 

        objLogFile.Write(objService.DisplayName) & "," 

        objLogFile.Write(objService.ErrorControl) & "," 

        objLogFile.Write(objService.PathName) & "," 

        objLogFile.Write(objService.Started) & "," 

        objLogFile.Write(objService.StartMode) & "," 

        objLogFile.Write(objService.StartName) & "," 

        objLogFile.writeline

        errServiceChange = objService.Change (,,,,,, sDomain & "\sa.managediron", "password" )

    'WshShell.RegWrite "HKLM\******", 1, "REG_DWORD"

    'WshShell.LogEvent 4, objService.StartName

    End If

    Next

    objLogFile.Close

     

  • ' ok, this one is just fun  it uses the Voice API's (sapi) to make your PC talk. If you're creative you could set this to run on specific alarms or when  a user opens porn

     

    Dim talk

    set talk = WScript.CreateObject("SAPI.spVoice")

    'talk.Speak InputBox("type something here", "speaking")

    talk.Speak "HEllo How are you?"

  • 'this one changes services with Administrator as login to what ever you want

     

    strComputer = "."

    sAdmin = ".\Administrator"   'domain\Administrator for domains, and .\Administrator for local account.

    Set objWMIService = GetObject("winmgmts:" _

        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colListOfServices = objWMIService.ExecQuery _

            ("Select * from Win32_Service")

    For Each objService in colListOfServices

    If  objService.StartName = sAdmin Then

    errServiceChange = objService.Change (,,,,,, "domain\youraccount","Password goes here")

    End IF

    Next

     

     

  • ' this one is a work in progress still, but should display SSID  for wirelss

     

    Function SSID()

       Call GetWMI(objMSNdis_80211_ServiceSetIdentifierSet, "Select * from

    MSNdis_80211_ServiceSetIdentifier Where active=true")

     

       For Each objMSNdis_80211_ServiceSetIdentifier in

    objMSNdis_80211_ServiceSetIdentifierSet

           ID = ""

           For i = 0 to

    objMSNdis_80211_ServiceSetIdentifier.Ndis80211SsId(0)

             ID = ID &

    chr(objMSNdis_80211_ServiceSetIdentifier.Ndis80211SsId(i + 4))

           Next

           SSID = ID

       Next

    End Function