Tuesday, October 30, 2007

VBscript - User Cannot Change Password Option

Disabling the User Cannot Change Password Option

Const ADS_ACETYPE_ACCESS_DENIED_OBJECT = &H6
Const CHANGE_PASSWORD_GUID = _
"{ab721a53-1e2f-11d0-9819-00aa0040529b}"

Set objUser = GetObject _
("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")
Set objSD = objUser.Get("nTSecurityDescriptor")
Set objDACL = objSD.DiscretionaryAcl
arrTrustees = Array("nt authority\self", "everyone")

For Each strTrustee In arrTrustees
For Each ace In objDACL
If(LCase(ace.Trustee) = strTrustee) Then
If((ace.AceType = ADS_ACETYPE_ACCESS_DENIED_OBJECT) And _
(LCase(ace.ObjectType) = CHANGE_PASSWORD_GUID)) Then
objDACL.RemoveAce ace
End If
End If
Next
Next

objUser.Put "nTSecurityDescriptor", objSD
objUser.SetInfo

Wednesday, October 17, 2007

VBScript - List network adapters including wireless adapters

This script will display all the network adapters including wireless adapters in your workstation.

'Script Start

'Call WMI service win32_networkadapter
strComputer = "."Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")Set colItems = objWMIService.ExecQuery ("Select * from in32_NetworkAdapter",,48)

'Display all objects.
For Each objItem in colItems

WScript.Echo "Name: " & objItem.Name
WScript.Echo "Availability: " & objItem.Availability

Next
WScript.Quit
'Script End

Friday, October 12, 2007

VBScript - String Arrays

A small script to explain arrays. While using string array don't forget double quotes.

'Script start

Strservers = array("EX1","EX2","EX3")
For each str in strservers 'To get each object in an array
wscript.echo str
Next

'Script end

Wednesday, October 10, 2007

Update E-Mail Addresses Based on Recipient Policy - msexchpoliciesexcluded checkbox

The Recipient Update Service does not update e-mail addresses automatically when the Automatically update e-mail addresses based on recipient policy check box is not selected. That attribute stops the Recipient Update Service from running against the object when this check box is not selected.
The Automatically update e-mail addresses based on recipient policy check box refers to the value of the attribute msExchPoliciesExcluded on the object. If this attribute is not set, it indicates that this check box is selected.
If this value is set to {26491CFC-9E50-4857-861B-0CB8DF22B5D7}, it indicates that the checkbox is not selected.

The Script finds whether the AD object has "The Automatically update e-mail addresses based on recipient policy" checkbox enabled.

'Script Start

Set oConfig = GetObject("LDAP://You LDAP DOMAIN")
Set oConn = CreateObject("ADODB.Connection")
oConn.Provider = "ADSDSOObject"
oConn.Open ""
strQuery = "<" & oConfig.adspath & ">;(&(objectCategory=person)(objectClass=User)(homemdb=*)(!(msExchPoliciesExcluded={26491CFC-9E50-4857-861B-0CB8DF22B5D7})));name,adspath;subtree"
Set oRS = oConn.Execute(strQuery)
While Not oRS.EOF
user = oRS.Fields("name")
'user = User & " " & oRS.Fields("adspath")
wscript.echo User
User = " "
oRS.MoveNext
Wend

'Script end

Thursday, October 4, 2007

Vbscript to create Mail enabled Universal groups or distribution lists

This script creates Mail enabled Universal groups or distribution lists by reading input from a CSV file.
This script is also written to update group owners name and also enables the checkbox "Manager can update member list"


Sample INPUT
universal,Grpname,This is a test grp,Ownername,OU1,OU2,OU3
'Script Start
Const ADS_GROUP_TYPE_GLOBAL = &H2
Const ADS_GROUP_TYPE_LOCAL = &H4
Const ADS_GROUP_TYPE_UNIVERSAL = &H8
Const ADS_ACETYPE_ACCESS_ALLOWED_OBJECT = &h5
Const ADS_FLAG_OBJECT_TYPE_PRESENT = &h1
Const ADS_RIGHT_DS_WRITE_PROP = &h20
Const MEMBER_ATTRIBUTE = "{bf9679c0-0de6-11d0-a285-00aa003049e2}"



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

Set ObjFSO = createobject("Scripting.FilesystemObject")
Set ObjTextfile = ObjFSO.Opentextfile("C:\dlinput.csv")




Do Until ObjTextfile.AtEndofStream
StrGet = ObjTextfile.ReadLine
StrInput = split(strGet,",")
StrLdappath = "LDAP:// YOUR LDAP PATH "
'wscript.echo strLdappath & " " & strInput(1)
Set objOU = GetObject(strLdappath)


Select Case StrInput(0)
Case "universal"
StrGrpName = strInput(1)
Set objGroup = objOU.Create("Group", "cn=" & strGrpName )
objGroup.groupType = ADS_GROUP_TYPE_UNIVERSAL
objGroup.SetInfo
case Else
StrGrpName = strInput(1)
Set objGroup = objOU.Create("Group", "cn=" & strGrpName )
objGroup.groupType = ADS_GROUP_TYPE_UNIVERSAL
objGroup.SetInfo

End Select

objGroup.sAMAccountName = Right (strInput(1),Len(StrInput(1))-1)
objGroup.SetInfo
objGroup.description = strInput(2)
objGroup.SetInfo
'wscript.echo strGrpName & "@" & strInput(6) & ".yourdomain.com"
objGroup.mail = strGrpName & "@" & strInput(6) & ".yourdomain.com"
objGroup.MailEnable
objGroup.Put "ProxyAddresses", "SMTP:" + "##-" + strInput(1) + "@" + strInput(6) + ".yourdomain.com"
objGroup.SetInfo

'wscript.echo strInput(3)
objCommand2.CommandText ="SELECT Userprincipalname,adspath,distinguishedName FROM 'LDAP:\\Your LDAP PATH' WHERE objectCategory='User' " & "AND CN='" & strInput(3) & "'"
Set objRecordSet2 = objCommand2.Execute
objRecordSet2.MoveFirst
'wscript.echo objRecordSet2.Fields("Adspath").Value
If Not objRecordSet2.EOF then
objGroup.Put "managedby" , Trim(Replace(objRecordSet2.Fields("adspath").Value,"LDAP://"," "))
objGroup.SetInfo
set objSD = objGroup.Get("ntSecurityDescriptor")
set objDACL = objSD.DiscretionaryAcl
set objACE = CreateObject("AccessControlEntry")
objACE.Trustee = objRecordSet2.Fields("UserprincipalName").Value
objACE.AccessMask = ADS_RIGHT_DS_WRITE_PROP
objACE.AceFlags = 0
objACE.Flags = ADS_FLAG_OBJECT_TYPE_PRESENT
objACE.AceType = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
objACE.ObjectType = MEMBER_ATTRIBUTE
objDACL.AddAce objACE
objSD.DiscretionaryAcl = objDACL
objGroup.Put "ntSecurityDescriptor", objSD
objGroup.SetInfo
End If






wscript.echo "Group named " & strinput(1) & " is created"
Loop

Wscript.echo "***** Script End *****"
'Script end

Queries on scripts. Open http://orangescripts.blogspot.com and post it

Wednesday, October 3, 2007

VBScript - Search and delete MP3 files inside ZIP

'Script start

strDir = "D:\cvc4sp4"
Set fso = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")

Set objDir = FSO.GetFolder(strDir)
getInfo(objDir)
Sub getInfo(pCurrentDir)
For Each aItem In pCurrentDir.Files
If LCase(Right(Cstr(aItem.Name), 3)) = "zip" Then
wscript.echo aItem.path
objshell.run "c:\7za d " & aItem.path & " *.mp3" 'Download 7za.exe from internet and place the exe in the specified path. Its free download
End If
If LCase(Right(Cstr(aItem.Name), 3)) = "mp3" Then
wscript.echo aItem.path
aItem.delete(True)
End If
Next
For Each aItem In pCurrentDir.SubFolders
'wscript.Echo aItem.Name & " passing recursively"
getInfo(aItem)
Next
End Sub

'Script End

Queries on customization. Open http://Orangescripts.blogspot.com and post it.

Tuesday, October 2, 2007

VBScript - Printer - Logging when printer is used

'Script start

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colEvents = objWMIService.ExecQuery _
("Select * from Win32_NTLogEvent Where LogFile='System' and eventcode=10")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\Events.CSV")
For Each objEvent in colEvents
strTimeWritten = objEvent.TimeWritten
dtmTimeWritten = CDate(Mid(strTimeWritten, 5, 2) & "/" & _
Mid(strTimeWritten, 7, 2) & "/" & Left(strTimeWritten, 4) _
& " " & Mid (strTimeWritten, 9, 2) & ":" & _
Mid(strTimeWritten, 11, 2) & ":" & Mid(strTimeWritten, 13, 2))
dtmDate = FormatDateTime(dtmTimeWritten, vbShortDate)
dtmTime = FormatDateTime(dtmTimeWritten, vbLongTime)
strDescription = objEvent.Message
strEvent = dtmTime & "," & trim(strDescription)
objFile.WriteLine strEvent
Next
objFile.Close


'Script End

Queries on scripts ? . Open http://orangescripts.blogspot.com and post it.

Monday, October 1, 2007

VBScript - Outlook - Send message from text file

'Script start


Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(0)
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("C:\Documents and Settings\murugan1\Desktop\mailsg.txt", ForReading)
strNextLine = objTextFile.Readall
wscript.echo StrNextLine
With objOutlookMsg
.To = InputBox("Enter To field")
.Subject = InputBox("Enter Subject")
.Body = strNextLine
.Send
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing



'Script End


Queries on customization. Open Orangescripts.blogspot.com and post it .

VBScript - Internet Explorer - Proxy settings

'Script Start

On Error Resume Next
strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Proxy")


Const HKEY_CURRENT_USER = &H80000001
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings"
strValueName = "ProxyEnable"
dim dWord
objRegistry.GetDWORDValue HKEY_CURRENT_USER , strKeyPath , strValueName ,dWord
if dWord = 1 then
dwValue = 0
objRegistry.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, dwValue
else
For Each objItem in colItems
dwValue = 1
objRegistry.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, dwValue
objItem.SetProxySetting "HOME","8080" 'Change parameters here
Next
end if





'Script End
Got from website dev.thatsit.net.au
How to execute a VBScript
Please post suggestions to improve this blog.
You can reach me at itmurugappan@hotmail.com

Saturday, September 29, 2007

VBScript to read MYSQL database

' Script start

Const adClipString = 2 ' 00000002
Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
Dim sFSpec : sFSpec = ".\imexportmysql.txt"
sFSpec = oFS.GetAbsolutePathName( sFSpec )
sFSpec = Replace( sFSpec, "\", "/" )
Dim oCNCT : Set oCNCT = CreateObject( "ADODB.Connection" )
Dim sCS : sCS = "DRIVER={MySQL ODBC 3.51 Driver};" _
+ "Server=localhost;" _
+ "Port=3306;" _
+ "Option=16384;" _
+ "Stmt=;" _
+ "Database=test;" _
+ "Uid=;" _
+ "Pwd=;"
Dim sSQL
oCNCT.Open sCS
If oFS.FileExists( sFSpec ) Then oFS.DeleteFile sFSpec
sSQL = "SELECT * FROM tblPerson INTO OUTFILE '" + sFSpec + "'"
oCNCT.Execute sSQL
WScript.Echo sSQL
sSQL = "DELETE FROM tblPerson"
oCNCT.Execute sSQL
WScript.Echo sSQL
sSQL = "SELECT COUNT(iId) FROM tblPerson"
WScript.Echo sSQL, "=>", oCNCT.Execute( sSQL ).Fields( 0 ).Value
sSQL = "LOAD DATA LOCAL INFILE '" + sFSpec + "' INTO TABLE tblPerson"
oCNCT.Execute sSQL
WScript.Echo sSQL
sSQL = "SELECT * FROM tblPerson"
WScript.Echo sSQL
WScript.Echo oCNCT.Execute( sSQL ).GetString( adClipString, , vbTab, vbCrLf, "NULL" )
End if
oCNCT.Close

output

dbcnt::doImExportMySQL()
SELECT * FROM tblPerson INTO OUTFILE 'M:/trials/02dbcnct/imexportmysql.txt'
DELETE FROM tblPerson
SELECT COUNT(iId) FROM tblPerson => 0
LOAD DATA LOCAL INFILE 'M:/trials/02dbcnct/imexportmysql.txt' INTO TABLE tblPerson
SELECT * FROM tblPerson
1 A
2 B
3 m
4 e
5 K

Script from : http://www.visualbasicscript.com/fb.aspx?m=50814

Queries on customization. Open http://Orangescripts.blogspot.com and post it

VBScript - To get service tag of your desktop

Usage: Script.vbs computer1 computer2 computer3

'Script start

For i = 0 to wscript.arguments.count-1
sComputer = wscript.arguments(i)
Set oWMI = GetObject("winmgmts:\\" & sComputer & "\root\cimv2")
Set oCol = oWMI.ExecQuery("Select * from Win32_ComputerSystemProduct")
For Each x in oCol
wscript.echo sComputer & vbtab & x.IdentifyingNumber
Next
Next

'Script End

content from pooradmin.com

Queries on customization. Open http://Orangescripts.blogspot.com and post it .

VBScript to add entry in a Registry path

'Script start

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "MyNetworkComputername"Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")strKeyPath = "Softwares\Microsoft\Windows\Currentversion\Run"
strValueName = "StartMyProgram"
strVal="myprogram.exe"
oReg.SetstringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strVal

'Script End

Queries on customization. Open http://orangescripts.blogspot.com/ and post it .

Friday, September 28, 2007

WScript.exe and CScript.exe Options

For the most part, options listed in the following table are applicable to both WScript.exe and CScript.exe. Exceptions are noted.

/B Batch mode; suppresses command-line display of user prompts and script errors. Default is Interactive mode.
/D Turns on the debugger.
/E:engine Executes the script with the specified script engine.
/H:CScript or /H:WScript Registers CScript.exe or WScript.exe as the default application for running scripts. If neither is specified, WScript.exe is assumed as the default.
/I Default. Interactive mode; allows display of user prompts and script errors Opposite of Batch mode.
/Job: Runs the specified JobID from the .wsf file.
/logo Default. Displays a banner. Opposite of nologo.
/nologo Prevents display of an execution banner at run time. Default is logo.
/S Saves the current command-line options for this user.
/T:nn Enables time-out: the maximum number of seconds the script can run. The default is no limit. The /T parameter prevents excessive execution of scripts by setting a timer. When execution time exceeds the specified value, CScript interrupts the script engine using the IActiveScript::InterruptThread method and terminates the process.
/U Used with Windows NT and Windows 2000 to force the command line output to be in Unicode. There is no way for CScript to determine whether to output in Unicode or ANSI; it defaults to ANSI.
/X Launches the program in the debugger.
/? Displays a brief description of and usage information for command parameters (the usage information).

Running Scripts from the Command Prompt

Content from Microsoft site.

Windows Script Host enables you to run scripts from the command prompt. CScript.exe provides command-line switches for setting script properties.

Procedures

To run scripts using CScript.exe
Type a command at the command prompt using the following syntax:

Copy Code

cscript [host options...] [script name] [script options and parameters]

Host Options enable or disable various Windows Script Host features. Host options are preceded by two slashes (//).Script name is the name of the script file with extension and necessary path information, for example, d:\admin\vbscripts\chart.vbs. Script options and parameters are passed to the script. Script parameters are preceded by a single slash (/).

Each parameter is optional; however, you cannot specify script options without specifying a script name. If you do not specify parameters, CScript displays the CScript syntax and the valid host parameters.

CScript Example

Suppose, for the purposes of this example, that you have copied the Chart.vbs sample script to the following folder on your computer:

Copy Code

c:\sample scripts\chart.vbs
You can run the script with and without a logo as follows.

To run a script with or without a logo
Start the MS-DOS command prompt.

Enter the following commands at the command prompt (modify accordingly if your sample scripts are located in a different folder):

Copy Code

cscript //logo c:\"sample scripts"\chart.vbs

cscript //nologo c:\"sample scripts"\chart.VBScript

Thursday, September 27, 2007

VBScript for Remote Shutdown

'Script Start


Set OpSysSet = GetObject("winmgmts:{impersonationLevel=impersonate,(RemoteShutdown)}//Your ip address").ExecQuery("select * from Win32_OperatingSystem where Primary=true")
for each OpSys in OpSysSet
OpSys.Reboot()
Next



'Script End

Got from website www.vittorio.tk

How to execute a VBScript

VBScript to move files according to date

'Script Start

' Covet - Use this script carefully.


Const OverwriteExisting = True

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(" Your source folder - HERE - full path ")



For Each file In f.Files

if DateDiff("m",file.DateCreated, "09/01/2007") = 0 then 'change date accordingly

FSO.CopyFile file.path , " Destination folder with full path and \ at end - HERE " , OverwriteExisting
file.delete

End if


Next



For Each subf In f.subfolders

For Each file In subf.Files

if DateDiff("m",file.DateCreated, "09/01/2007") = 0 then 'change date accordingly

FSO.CopyFile file.path , " Destination folder with full path and \ at end - HERE " , OverwriteExisting
file.delete
End if


Next

Next

wscript.echo "End"





'Script End



How to execute a VBScript

VBScript to find file information

'Script Start


Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("C:\")
For Each file In f.Files
MsgBox file.Name
MsgBox file.DateCreated
MsgBox file.DateLastAccessed
MsgBox file.DateLastModified
MsgBox file.Path
MsgBox file.ShortName
MsgBox file.ShortPath
MsgBox file.Size
Next





'Script End



How to execute a VBScript

VBScript to assign DHCP ip address

'Script Start


strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled = true")

goDHCP()


Sub goDHCP()
For Each objItem In colItems

errEnable = objItem.EnableDHCP()
If errEnable = 0 Then
Wscript.Echo "DHCP has been enabled."
Else
Wscript.Echo "DHCP could not be enabled."
End If
Msgbox "setting DNS"
errDNS = objitem.SetDNSServerSearchOrder()
errDDNS = objItem.SetDynamicDNSRegistration
msgbox "DNS Set"
errRenew = objItem.RenewDHCPLease
msgbox "renew called"
If errRenew = 0 Then
Wscript.Echo "DHCP lease renewed."
Else
Wscript.Echo "DHCP lease could not be renewed." & err.number & err.description
End If
Next
End Sub





'Script End

Got from website www.vittorio.tk

How to execute a VBScript

VBScript to assign static IP address

'Script Start


strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled = true")

'// Static Ip addrerss settings
strIPAddress = Array("192.168.36.36")
strSubnetMask = Array("255.255.252.0")
strGateway = Array("192.168.36.1")
strGatewayMetric = Array(1)
strDNSservers = Array ("192.168.76.33","192.168.76.34")


goStatic


Sub goStatic()
For Each objItem In colItems
errEnable = objItem.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objItem.SetGateways(strGateway, strGatewaymetric)
'// This line removes all DNS servers
errDNS = objitem.SetDNSServerSearchOrder()
errDNS = objitem.SetDNSServerSearchOrder(strDNSServers)
If errEnable = 0 Then
WScript.Echo "The IP address has been changed."
Else
WScript.Echo "The IP address could not be changed."
End If
Next
'// ReQuery to see changes
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled = true")
For Each objItem In colItems
If Not IsNull(objitem.ipaddress) Then
For i = LBound(objitem.IPAddress) To UBound(objitem.IPAddress)
WScript.Echo "New IP is " & objitem.IPAddress(i)
Next
End If
If Not IsNull(objitem.ipSubnet) Then
For i = LBound(objitem.IPSubnet) To UBound(objitem.IPSubnet)
WScript.Echo "New subnet is " & objitem.IPSubnet(i)
Next
End If
If Not IsNull(objitem.DefaultIPGateway) Then
For i = LBound(objitem.DefaultIPGateway) To UBound(objitem.DefaultIPGateway)
WScript.Echo "Gateway is " & objitem.DefaultIPGateway(i)
Next
End If
Next
End Sub





'Script End

Got from website www.vittorio.tk

How to execute a VBScript

VBScript to get size of all subfolders in a directory

'Script Start


BaseDirectory = "D:\"

CheckFolder(BaseDirectory)

Function CheckFolder(Directory)
Set sss = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(Directory)
For each sf In f.subfolders
value = round(sf.Size/1048576,2)

wscript.echo sf.name & " " & Value & " Mb"

Next
End Function




'Script End



How to execute a VBScript

VBScript to Retrieve a file from an URL and save it to the Hard Disk

'Script Start


URL = "http://sitename/filename.txt"
saveTo = "C:\filename.txt"

Set Obj1 = CreateObject("MSXML2.ServerObj1")
Obj1.open "GET", URL, false
Obj1.send()
Set Obj2 = CreateObject("ADODB.Stream")
Obj2.Open
Obj2.Type = 1 'adTypeBinary
Obj2.Write Obj1.ResponseBody 'Give the XML string to the ADO Stream
Obj2.Position = 0 'Set the stream position to the start
Set FSO = Createobject("Scripting.FileSystemObject")
if fso.Fileexists(saveTo) then Fso.DeleteFile hdLocation
set FSO = Nothing
Obj2.SaveToFile saveTo
Obj2.Close
Set Obj2 = Nothing
Set Obj1 = Nothing




'Script End

Got from the site www.vittorio.tk

How to execute a VBScript

VBScript to get total physical memory of your desktop

'Script Start


Set obj = GetObject("winmgmts:").InstancesOf("Win32_PhysicalMemory")
i = 1
For Each obj2 In obj
memTmp1 = obj2.capacity / 1024 / 1024
wscript.echo "Module" & i & ": " & memTmp1 & " MB"
TotalRam = TotalRam + memTmp1
i = i +1
Next
wscript.echo "Total RAM: " & TotalRam & " MB"



'Script End



How to execute a VBScript

VBScript to send Email

'Script Start


Set objEmail = CreateObject("CDO.Message")

'Change from field
objEmail.From = "admin1@fabrikam.com"

'change to field
objEmail.To = "admin2@fabrikam.com"

'change subject
objEmail.Subject = "Server down"

'change textbody
objEmail.Textbody = "Server1 is no longer accessible over the network."


objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "Your mail server IP - HERE"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send



'Script End



How to execute a VBScript

VBScript Running Scripts on Remote Computers

'Script Start


'Substitute server

strRemoteComputer = "servername"

'Substitute script name

strWorkerScript = "scripttorunonremote.vbs"
Set objWshController = WScript.CreateObject("WshController")
Set objRemoteScript = objWshController.CreateScript(strWorkerScript, strRemoteComputer)
objRemoteScript.Execute

Do While Not objRemoteScript.Status = 2
Wscript.Sleep(100)
Wscript.Echo "Remote script not yet complete."
Loop




'Script End



How to execute a VBScript

VBScript to set default printer in your desktop

'Script Start


Set objNetwork = WScript.CreateObject("WScript.Network")
objNetwork.SetDefaultPrinter("\\servername\printername")





'Script End



How to execute a VBScript

VBScript to enumerate available printers on your desktop

'Script Start


Set objNetwork = WScript.CreateObject("WScript.Network")
Set colPrinters = objNetwork.EnumPrinterConnections
For i = 0 to colPrinters.Count -1 Step 2
Wscript.Echo colPrinters.Item(i) & vbTab & colPrinters.Item (i + 1)
Next





'Script End



How to execute a VBScript

VBscript Remove a Windows based printer

'Script Start


Set objNetwork = WScript.CreateObject("WScript.Network")
objNetwork.RemovePrinterConnection "\\servername\printername"



'Script End



How to execute a VBScript

VBScript add a windows based printer

'Script Start


Set objNetwork = Wscript.CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\HRServer01\Printer1"


'Script End



How to execute a VBScript

VBScript to display all shared drives

'Script start

Set objNetwork = WScript.CreateObject("WScript.Network")
Set colDrives = objNetwork.EnumNetworkDrives
For i = 0 to colDrives.Count-1 Step 2
Wscript.Echo colDrives.Item(i) & vbTab & colDrives.Item (i + 1)
Next

'Script end

How to execute a VBScript

VBScript to Unmap a Network Drive

'Script start

Set objNetwork = WScript.CreateObject("Wscript.Network")
objNetwork.RemoveNetworkDrive "G:"

'Script end



How to execute a VBScript

VBScript to Map a network drive

'Script start

Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive "S:", file://server/share

'Script end

Edit //server/share according to you needs. Current user should have permission to the mentioned folder

How to execute a VBScript

VBScript to find Current username

'Script Start

Set WshNetwork = WScript.CreateObject("WScript.Network")
WScript.Echo "Current User Name: " & WshNetwork.UserName

'Script End

How to execute a VBScript

How to Execute a VBScript

STEP 1 Copy the script into a notepad
STEP 2 Click save target as - In the file name type "name.vbs" [along with double quotes]
STEP 3 Choose drive
STEP 4 Goto the place where u saved and just double click name.vbs

Wednesday, September 26, 2007

VB Script to get computer name from your workstation


Set WshNetwork = WScript.CreateObject("WScript.Network")
WScript.Echo "You Computer Name = " & WshNetwork.ComputerName


How to execute a VBScript