Showing posts with label Vb Scripts. Show all posts
Showing posts with label Vb Scripts. Show all posts

Wednesday, September 3, 2014

Deleting entries in ora file using VBscript

Create one temp.ora file in the location of Vbscript and add the entries manually in temp.ora file.

When executing vb script it will compare the temp.ora file with test.ora in this  location(\oracle\product\11.0.0.0.0\network\admin\) and it will delete accordingly.


On Error Resume Next
Const ForReading = 1
Const ForWriting = 2

Set Wshshell = CreateObject("Wscript.Shell")
Set objFSO   = CreateObject("Scripting.FileSystemObject")

StrCurrPath = Replace(Wscript.ScriptFullName,Wscript.ScriptName,"")
ORAFilePath   = Wshshell.ExpandEnvironmentStrings("%systemdrive%") & "\oracle\product\11.2.0.2.0\network\admin\"
ORAFilePath     = ORAFilePath & "test.ora"
TmpORAFilePath = StrCurrPath & "temp.ora"


Set objORAfile = objFSO.OpenTextFile(ORAFilePath, ForReading)
 StrReadORAFile= objORAfile.ReadAll
objORAFile.Close

Set objTmpORAfile = objFSO.OpenTextFile(TmpORAFilePath, ForReading)
 StrReadTmpORAFile= objTmpORAfile.ReadAll
objTmpORAfile.Close


If Instr(StrReadORAFile,StrReadTmpORAFile) <> 0 then
StrData = Replace(StrReadORAFile,StrReadTmpORAFile,"")
Set objORAfile = objFSO.OpenTextFile(ORAFilePath, ForWriting)
objORAfile.Write StrData
objORAfile.close

End If

Appending entries in ora file using VBscript

Create one temp.ora file in the location of Vbscript and add the entries manually in temp.ora file.

When executing vb script it will compare the temp.ora file with test.ora in this  location(\oracle\product\11.0.0.0.0\network\admin\) and it will append accordingly.

On Error Resume Next
Const ForReading = 1
Const ForWriting = 2
const ForAppending = 8

Set Wshshell = CreateObject("Wscript.Shell")
Set objFSO   = CreateObject("Scripting.FileSystemObject")

StrCurrPath = Replace(Wscript.ScriptFullName,Wscript.ScriptName,"")
ORAFilePath   = Wshshell.ExpandEnvironmentStrings("%systemdrive%") & "\oracle\product\11.0.0.0.0\network\admin\"
ORAFilePath     = ORAFilePath & "Test.ora"
TmpORAFilePath = StrCurrPath & "Temp.ora"

Set objORAfile = objFSO.OpenTextFile(ORAFilePath, ForReading)
 StrReadORAFile= objORAfile.ReadAll
objORAFile.Close


Set objTmpORAfile = objFSO.OpenTextFile(TmpORAFilePath, ForReading)
 StrReadTmpORAFile= objTmpORAfile.ReadAll
objTmpORAfile.Close

If Instr(StrReadORAFile,StrReadTmpORAFile) = 0 then
Set objORAfile = objFSO.OpenTextFile(ORAFilePath, ForAppending)
 objORAfile.Writeline StrReadTmpORAFile
objORAFile.Close

End if

Monday, August 11, 2014

Deleting Folders & Subfolders using VBscript


Set folder = fso.GetFolder("C:\Program Files\Test")
' delete all files in root folder
for each f in folder.Files
   On Error Resume Next
   name = f.name
   f.Delete True
   
   On Error GoTo 0
Next

' delete all subfolders and files
For Each f In folder.SubFolders
   On Error Resume Next
   name = f.name
   f.Delete True
   
   On Error GoTo 0
Next

Deleting Appdata file for all the users

Dim FSfolder 
Dim subfolder 
Dim i 


set objshell = CreateObject("Wscript.shell") 
Set FSO = CreateObject("Scripting.FileSystemObject")
Profile = strSysDrive & "C:\Users"
Set FSfolder = FSO.GetFolder(Profile) 'getting the user profile folders





'starting of the loop to delete the HKCUs


For Each subfolder In FSfolder.SubFolders


   If (subfolder.Name <> "All Users" And  subfolder.Name <> "Default User"_
   and subfolder.Name <> "Public" and subfolder.Name <> "Default") Then


 folder1=Profile & "\" & subfolder.Name & "\AppData\Roaming\Quest Software\Test"

DeleteThisFolder(folder1)

  end if


Next 


Function DeleteThisFolder(FolderName)


    If FSO.FolderExists(FolderName) Then
       On Error Resume Next
       fso.DeleteFile(Profile & "\" & subfolder.Name & "\AppData\Roaming\Quest Software\Test\sample.lnk")
    End If

End Function

Wednesday, July 16, 2014

Removing Registry-BinaryValue using VB Scripts

Const HKEY_CLASSES_ROOT  = &H80000000
Const HKEY_CURRENT_USER  = &H80000001
Const HKEY_LOCAL_MACHINE  = &H80000002
Const HKEY_USERS   = &H80000003
Const HKEY_CURRENT_CONFIG  = &H80000005


strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
    strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\V6R2012x"

strBinaryValueName = "AUTOCAD"


oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strBinaryValueName

Removing Registry-MultiStringValue using VB Scripts

Const HKEY_CLASSES_ROOT  = &H80000000
Const HKEY_CURRENT_USER  = &H80000001
Const HKEY_LOCAL_MACHINE  = &H80000002
Const HKEY_USERS   = &H80000003
Const HKEY_CURRENT_CONFIG  = &H80000005

strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\V6R2012x"

strMultiStringValueName = "AUTOCAD"


oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strMultiStringValueName

Removing Registry-ExpandedStringValue using VB Scripts

Const HKEY_CLASSES_ROOT  = &H80000000
Const HKEY_CURRENT_USER  = &H80000001
Const HKEY_LOCAL_MACHINE  = &H80000002
Const HKEY_USERS   = &H80000003
Const HKEY_CURRENT_CONFIG  = &H80000005

strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
    strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\V6R2012x"

strExpandedStringValueName = "AUTOCAD"

oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strExpandedStringValueName

Removing Registry-String Value using VB Scripts

Const HKEY_CLASSES_ROOT  = &H80000000
Const HKEY_CURRENT_USER  = &H80000001
Const HKEY_LOCAL_MACHINE  = &H80000002
Const HKEY_USERS   = &H80000003
Const HKEY_CURRENT_CONFIG  = &H80000005

strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
    strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\V6R2012x"

strStringValueName = "AUTOCAD"

oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strStringValueName

Removing Registry key Using VB Scripts

Const HKEY_CLASSES_ROOT  = &H80000000
Const HKEY_CURRENT_USER  = &H80000001
Const HKEY_LOCAL_MACHINE  = &H80000002
Const HKEY_USERS   = &H80000003
Const HKEY_CURRENT_CONFIG  = &H80000005

strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\V6R2012x"
strKeyPath1="SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\EE9929DE5563356CDE4A7CA7331EF14A"


oReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath
oReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath1

Tuesday, June 24, 2014

Checking System date(Range) and executing EXE using Vbscripts

strComputer = "."
strDateFrom = "4/28/2013"
strEndDate   = "5/21/2013"
Set objFSO   = CreateObject("Scripting.FileSystemObject")
Set Wshshell = CreateObject("Wscript.Shell")
DateInfo = DateInfo & Date & VbCrLf
If DateInfo >StrDateFrom And DateInfo <StrEndDate Then
wshshell.run "C:\test.exe"
End IF

Thursday, June 19, 2014

How to disable Local area connection -power management options Using Vb scripts 2

Below Script will check for PnPCapabilities and replace the value and it will also check for IPV4 network connection and add PnPCapabilities Value.

Option Explicit

Const HKEY_LOCAL_MACHINE = &H80000002

Dim objReg
Dim strComputer, strKeyPath, arrSubKeys, arrValueTypes, arrValueNames,arrValueNames1,arrValueTypes1
Dim subkey, i

on error resume next

strComputer = "."

Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")


strKeyPath = "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}"


objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys


     
        objReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath & "\" & subkey, arrValueNames, arrValueTypes
     
        for i=0 to ubound(arrValuenames)
                'wscript.echo "Value Name: " & arrValueNames(i)
                if arrValueNames(i) = "PnPCapabilities" then
                        objReg.SetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath & "\" & subkey, "PnPCapabilities", 56
                End If
        next

       objReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath & "\" & subkey, arrValueNames1, arrValueTypes1
        for i=0 to ubound(arrValuenames1)
                if arrValueNames1(i) = "*LsoV1IPv4" then
                        objReg.SetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath & "\" & subkey, "PnPCapabilities", 56
                End If
        next

Next

Set objReg = nothing

How to disable Local area connection -power management options Using Vb scripts

Below Script will check for PnPCapabilities and replace the value

Option Explicit

Const HKEY_LOCAL_MACHINE = &H80000002

Dim objReg
Dim strComputer, strKeyPath, arrSubKeys, arrValueTypes, arrValueNames
Dim subkey, i

on error resume next
 strComputer = "."

Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

 strKeyPath = "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}"

objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

For Each subkey In arrSubKeys
      objReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath & "\" & subkey, arrValueNames, arrValueTypes
        for i=0 to ubound(arrValuenames)
                if arrValueNames(i) = "PnPCapabilities" then
                        objReg.SetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath & "\" & subkey, "PnPCapabilities", 56
                End If
        next
     
Next

Set objReg = nothing

Renaming Local area connection using Vb Scripts

On Error Resume Next
Const NETWORK_CONNECTIONS = &H31&
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter")

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(NETWORK_CONNECTIONS)

Set colItems = objFolder.Items
For Each objItem in colItems
    If objItem.Name = "Local Area Connection" Then
       objItem.Name = "Local Area Connection 2"
    End If
Next

Friday, May 23, 2014

User Profile Folder and URL rename Using VB scripts

On Error Resume Next  

Dim FSO
Dim FSOFol
Set oShell = CreateObject( "WScript.Shell" )
USERPROFILE=oShell.ExpandEnvironmentStrings("%USERPROFILE%")


Set FSOFol = CreateObject("Scripting.FileSystemObject")
strFolder = USERPROFILE & "\Favorites\Microsoft Websites"

  strFolderRename = USERPROFILE & "\Favorites\Websites"
   If FSOFol.FolderExists(strFolder) Then
        FSOFol.MoveFolder strFolder, strFolderRename
   End If

  Set FSO = CreateObject("Scripting.FileSystemObject")
  strFile = USERPROFILE & "\Favorites\Websites\Microsoft Store.url"
  strRename = USERPROFILE & "\Favorites\Websites\test.url"
   If FSO.FileExists(strFile) Then
        FSO.MoveFile strFile, strRename
   End If




VB Script to delete User profile favorites folder and desktop shortcut

On Error Resume Next

Set oFso = CreateObject("Scripting.FileSystemObject")
set objShell=CreateObject("wscript.shell")
strTemp=objShell.ExpandEnvironmentStrings("%USERPROFILE%")
strFolder = strTemp & "\Favorites\MSN Websites"
strFolder1 = strTemp & "\Favorites\Windows Live"

set filesys=CreateObject("Scripting.FileSystemObject")

If filesys.FolderExists (strFolder) Then
filesys.DeleteFolder strFolder
End if

If filesys.FolderExists (strFolder1) Then
filesys.DeleteFolder strFolder1
End if

If oFso.FileExists("C:\Users\Public\Desktop\Skypetest.lnk") then
oFso.DeleteFile("C:\Users\Public\Desktop\Skypetest.lnk"), force
End If

Renaming Desktop Shortcut Using VB Scripts

On Error Resume Next  
Dim FSO
Dim FSOFol
  Set FSO = CreateObject("Scripting.FileSystemObject")
  strFile = "C:\Users\Public\Desktop\Skype.lnk"
  strRename = "C:\Users\public\Desktop\Skypetest.lnk"
   If FSO.FileExists(strFile) Then
        FSO.MoveFile strFile, strRename
   End If


Checking 64bit Registry-Display Version value and storing in varialbe to use in WiseScripts

On error Resume Next
Value = "3.0.85.0"
strComputer = "."
Const HKLM = &h80000002
Set objCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
objCtx.Add "__ProviderArchitecture", 64
objCtx.Add "__RequiredArchitecture", TRUE
Set objLocator = CreateObject("Wbemscripting.SWbemLocator")
Set objServices = objLocator.ConnectServer("","root\default","","",,,,objCtx)
Set objStdRegProv = objServices.Get("StdRegProv")

Set Inparams = objStdRegProv.Methods_("GetStringValue").InParameters
'Inparams.Hdefkey = HKLM
Inparams.Ssubkeyname = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{100E94A6-F85A-E828-9EE3-C1DD14706B6A}"
Inparams.SValueName = "DisplayVersion"
Set Outparams = objStdRegProv.ExecMethod_("GetStringValue", Inparams,,objCtx)

strValue = Outparams.sValue

If strvalue=value then

SetVariable "CONDITION",success

Else

SetVariable "CONDITION",Failed
 
End If


Checking 64bit Registry-Display Version value using VB Scripts

On error Resume Next
Value = "3.0.85.0"
strComputer = "."
Const HKLM = &h80000002
Set objCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
objCtx.Add "__ProviderArchitecture", 64
objCtx.Add "__RequiredArchitecture", TRUE
Set objLocator = CreateObject("Wbemscripting.SWbemLocator")
Set objServices = objLocator.ConnectServer("","root\default","","",,,,objCtx)
Set objStdRegProv = objServices.Get("StdRegProv")

Set Inparams = objStdRegProv.Methods_("GetStringValue").InParameters
'Inparams.Hdefkey = HKLM
Inparams.Ssubkeyname = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{100E94A6-F85A-E828-9EE3-C1DD14706B6A}"
Inparams.SValueName = "DisplayVersion"
Set Outparams = objStdRegProv.ExecMethod_("GetStringValue", Inparams,,objCtx)

strValue = Outparams.sValue

If strvalue=value then
MSGBOX "success"

Else
MSGBOX "NOT success"  
End If


Tuesday, May 20, 2014

VBScript To delete desktop shortcut and Start Menu Shortcut

On Error Resume Next
strComputer = "."
set fso =createobject("scripting.filesystemobject")
set wshshell = createobject("wscript.shell")
Desktop = wshshell.expandenvironmentstrings("%PUBLIC%")
StartMenu = wshshell.expandenvironmentstrings("%ProgramData%")
If fso.FolderExists(StartMenu   & "\Microsoft\Windows\Start Menu\Programs\Beyond Compare 2") Then
   fso.DeleteFile(StartMenu & "\Microsoft\Windows\Start Menu\Programs\Beyond Compare 2\Uninstall Beyond Compare 2.lnk")
   fso.DeleteFile(Desktop & "\Desktop\Beyond Compare 2.lnk")
End if

VB Script to Stop a service

strComputer = "."
strServiceName = "msiserver"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery("Select * from Win32_Service Where Name ='" & strServiceName & "'")
For Each objService in colListOfServices
    objService.StopService()
Next