Archive for the 'VBScript' Category

Run DOS command in VBscript

Keep Reading ...

DOS command can be run in Vb Script using the Shell object
The below script runs a mkdir command through Vb Script
Set objShell = CreateObject(“WScript.Shell”)
objShell.Run “%comspec% /c mkdir dir1″
If your in IT you know coffee is almost as important as the air we breath. Show your support and add to the coffee fund. SHOW YOUR SUPPORT… [...]

VBscript – Create Folders from Excel

Keep Reading ...

1234567891011121314151617181920212223242526272829303132′========================================================

‘ NAME: FolderFromExcel.vbs

‘ COMMENT:  Script will read Excel file.  Column A should contain
‘                  folder names. Folders will then be created.

‘========================================================
Dim objExcel, strPathExcel,strCN
Dim objFile, intRow

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objExcel = CreateObject("Excel.Application")
strPathExcel = "c:\temp\excel.xls"
objExcel.Workbooks.open strPathExcel
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

intRow = 1

Do Until objExcel.Cells(intRow, 1).Value = ""
    strCN = Trim(objSheet.Cells(intRow, [...]

VBScript – Enumerates all SamAccounts in you current Domain

Keep Reading ...

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112′==========================================================================
‘ NAME: List_AD_SamAccounts.vbs

‘ COMMENT: Enumerates all SamAccounts with department and descriptions

‘==========================================================================

Option Explicit

Dim adoCommand, adoConnection, strBase, strFilter, strAttributes

Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strName

Dim strDept, arrDescript, strDescript, strItem

‘ Setup ADO objects.

Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection

‘ Search entire Active [...]

Runs a script against multiple computers

Keep Reading ...

This snippet runs a script against multiple computers taken from a text file. A big time saver.
123456789101112131415161718192021′Create a FileSystemObject
Set oFS = CreateObject("Scripting.FileSystemObject")
‘Open a text file of computer names
‘with one computer name per line
Set oTS = oFS.OpenTextFile("c:computers.txt")

‘go through the text file
Do Until oTS.AtEndOfStream
‘get the next computer name
’store it in variable sComputer
sComputer = oTS.ReadLine

‘———————————–
‘ YOUR CODE HERE [...]

Script to check for new users or computers and email output

Keep Reading ...

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165′==========================================================================


‘ NAME: ADAddedUsersNComputers.vbs

‘ AUTHOR: John Sorensen
‘ DATE  : 2/2/2009

‘ This script Checks AD for any additions made to Users or Computers
‘ in the past 24 hours. The time interval to check can be changed below.

‘*****************************************************************************

‘Please modify these four settings
strSMTPServer = "your_mail_server.domain.com"
strEmailFrom = "Script Output  <script@domain.com>"
strEmailTo = "John Sorensen <you@domain.com>"

strTimeInUTC = CompareDateUTCConvert("h",-24) ‘This is the same [...]

Run a command via vbscript

Keep Reading ...

123456789101112131415161718192021222324252627′==========================================================================

‘ NAME: runcommand.vbs

‘ AUTHOR: John Sorensen

‘ COMMENT:

‘==========================================================================

strCommand = "ipconfig" ‘This is where you place command

WScript.Echo "Running command: " & strCommand
WScript.Echo
set objShell = CreateObject("Wscript.Shell")
set objProc  = objShell.Exec(strCommand)

Do
   WScript.Sleep 100
Loop Until objProc.Status <> 0

if objProc.ExitCode <> 0 Then
   WScript.Echo "EXIT CODE: " & objProc.ExitCode
   WScript.Echo "ERROR: " & objProc.StdErr.ReadAll
end if

WScript.Echo "OUTPUT: " & objProc.StdOut.ReadAll
If your in IT [...]

Folder Report VbScript

Keep Reading ...

1234567891011121314151617181920212223242526272829303132333435363738394041424344′************************************************************
‘ File:  FolderReport.vbs

‘************************************************************

strSource="c:\"
iGrandTotalCount=0
iGrandTotalSum=0

Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFolder=objFSO.GetFolder(strSource)

Call ProcessFiles(objFolder)

WScript.Echo "Total count = " &amp; iGrandTotalCount &amp;_
" files (" &amp; iGrandTotalSum &amp; " bytes)"

Sub ProcessFiles(objFolder)
Set colFiles=objFolder.Files
iSum=0

For Each file In colFiles
iSum=iSum+file.size
Next

‘increment grand total counters
iGrandTotalSum=iGrandTotalSum+iSum
iGrandTotalCount=iGrandTotalCount+colFiles.Count

wscript.Echo objFolder &amp; " = " &amp; colFiles.Count &amp;_
" files (" &amp; iSum &amp; " bytes)"

‘process Subfolders
Call ProcessSubFolders(objFolder)

End Sub

Sub ProcessSubFolders(objFolder)
Set colSubs=objFolder.SubFolders
For Each folder In colSubs
ProcessFiles(folder)
Next

End Sub
If your [...]

Place cmd in context menu via vbscipt

Keep Reading ...

This script place’s a “cmd prompt here” in the explorers context menu. This is a most for any one that uses the command often.
‘**************************************************************************
‘ File: CmdPromptExplorerMenu.vbs
‘**************************************************************************
Dim WSHShell
Set WSHShell = WScript.CreateObject(“WScript.Shell”)
WSHShell.RegWrite “HKCR\Folder\Shell\MenuText\Command\”, “cmd.exe /k cd ” & chr(34) & “%1″ & chr(34)
WSHShell.RegWrite “HKCR\Folder\Shell\MenuText\”, “Cmd Prompt Here”
If your in IT you know coffee is almost as important [...]

Create shortcut VBScript

Keep Reading ...

1234567891011121314151617181920212223′====================================================================
‘ NAME: <createAddRemoveShortCut.vbs>

‘ COMMENT: Key concepts are listed below:
‘1. Uses wscript.shell to create shortcut on the desktop.
‘2. The hard part was passing an argument to the target, which is not allowed
‘3. in the target argument. You need to use the arguments property instead.
‘====================================================================
Option Explicit
Dim objShell ‘instance of the wshSHell object
Dim strDesktop ‘pointer to desktop special [...]

List all computers in Domain

Keep Reading ...

1234567891011121314151617181920212223242526272829303132333435′     Run this script via cscipt other wise edit to direct output to text file
‘     ListComputers.vbs

Dim RootDSE, DomainNC, Connection, Command, RecordSet

‘ CALLOUT A
Set RootDSE = GetObject("LDAP://rootDSE")
DomainNC = RootDSE.Get("defaultNamingContext")
‘ END CALLOUT A

Set Connection = CreateObject("ADODB.Connection")
Connection.Open("Provider=ADsDSOObject;")

Set Command = CreateObject("ADODB.Command")
Command.ActiveConnection = Connection

‘ CALLOUT B
Command.CommandText = "<ldap://" & DomainNC _
  & ">;(objectCategory=Computer);CN;subtree"
‘ END CALLOUT B
Command.Properties("Cache [...]