Pages

Wednesday, 28 January 2009

Search for Script Path and copy files to Destination - VBScript

The below script will search for the directory in which the script file is placed and will copy the files from the path in script to the destination path in script




Dim fso,l_path,oWsh,l_prgfiles
Set fso = CreateObject("Scripting.FileSystemObject")
Set oWsh = CreateObject("Wscript.Shell")
l_prgfiles = oWsh.ExpandEnvironmentStrings("%programfiles%") & "\"
l_source = fso.GetParentFolderName(wscript.ScriptFullName) & "\bo6data"
fso.CopyFolder l_source,l_prgfiles,true

Adding Registries using VBScript

Option Explicit
const HKEY_LOCAL_MACHINE = &H80000002
const HKEY_CLASSES_ROOT = &H80000000


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


Return = objReg.CreateKey(HKEY_CLASSES_ROOT,"Interface\{000C0300-0000-0000-C000-000000000046}")
Return = objReg.SetStringValue(HKEY_CLASSES_ROOT,"Interface\{000C0300-0000-0000-C000-000000000046}","","_IMsoDispObj")
Return = objReg.CreateKey(HKEY_CLASSES_ROOT,"Interface\{000C0300-0000-0000-C000-000000000046}\ProxyStubClsid")
Return = objReg.SetStringValue(HKEY_CLASSES_ROOT,"Interface\{000C0300-0000-0000-C000-000000000046}\ProxyStubClsid","","{00020424-0000-0000-C000-000000000046}")
Return = objReg.CreateKey(HKEY_CLASSES_ROOT,"Interface\{4EF6100A-AF88-11D0-9846-00C04FC29993}\ProxyStubClsid32")
Return = objReg.SetStringValue(HKEY_CLASSES_ROOT,"Interface\{000C0300-0000-0000-C000-000000000046}\ProxyStubClsid32","","{00020424-0000-0000-C000-000000000046}")
Return = objReg.CreateKey(HKEY_CLASSES_ROOT,"Interface\{4EF6100A-AF88-11D0-9846-00C04FC29993}\TypeLib")
Return = objReg.SetStringValue(HKEY_CLASSES_ROOT,"Interface\{000C0300-0000-0000-C000-000000000046}\TypeLib","","{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}")
Return = objReg.SetStringValue(HKEY_CLASSES_ROOT,"Interface\{000C0300-0000-0000-C000-000000000046}\TypeLib","Version","2.3")




Return = objReg.CreateKey(HKEY_CLASSES_ROOT,"Interface\{618736E0-3C3D-11CF-810C-00AA00389B71}")
Return = objReg.SetStringValue(HKEY_CLASSES_ROOT,"Interface\{618736E0-3C3D-11CF-810C-00AA00389B71}","","IAccessible")
Return = objReg.CreateKey(HKEY_CLASSES_ROOT,"Interface\{618736E0-3C3D-11CF-810C-00AA00389B71}\NumMethods")
Return = objReg.SetStringValue(HKEY_CLASSES_ROOT,"Interface\{618736E0-3C3D-11CF-810C-00AA00389B71}\NumMethods","","28")
Return = objReg.CreateKey(HKEY_CLASSES_ROOT,"Interface\{618736E0-3C3D-11CF-810C-00AA00389B71}\ProxyStubClsid")
Return = objReg.SetStringValue(HKEY_CLASSES_ROOT,"Interface\{618736E0-3C3D-11CF-810C-00AA00389B71}\ProxyStubClsid","","{00020424-0000-0000-C000-000000000046}")
Return = objReg.CreateKey(HKEY_CLASSES_ROOT,"Interface\{618736E0-3C3D-11CF-810C-00AA00389B71}\ProxyStubClsid32")
Return = objReg.SetStringValue(HKEY_CLASSES_ROOT,"Interface\{618736E0-3C3D-11CF-810C-00AA00389B71}\ProxyStubClsid32","","{00020424-0000-0000-C000-000000000046}")
Return = objReg.CreateKey(HKEY_CLASSES_ROOT,"Interface\{618736E0-3C3D-11CF-810C-00AA00389B71}\TypeLib")
Return = objReg.SetStringValue(HKEY_CLASSES_ROOT,"Interface\{618736E0-3C3D-11CF-810C-00AA00389B71}\TypeLib","","{1EA4DBF0-3C3B-11CF-810C-00AA00389B71}")
Return = objReg.SetStringValue(HKEY_CLASSES_ROOT,"Interface\{618736E0-3C3D-11CF-810C-00AA00389B71}\TypeLib","Version","1.1")




Set objReg = Nothing

Tuesday, 20 January 2009

Restoring Registry - Value of Default - VBScript

The following script will restore a registry with value under Default


Dim objWshShell


Set objWshShell=CreateObject("WScript.Shell")


WINDIR =objWshShell.ExpandEnvironmentStrings("%windir%")
objWshShell.RegWrite "HKCR\CLSID\{0BE35200-8F91-11CE-9DE3-00AA004BB851}\","Font Property Page","REG_SZ"
objWshShell.RegWrite "HKCR\CLSID\{0BE35200-8F91-11CE-9DE3-00AA004BB851}\InprocServer32\", WINDIR & "\System32\MFC42u.DLL","REG_SZ"


Set objWshShell=Nothing

Friday, 16 January 2009

Delete files of common naming using VBScript

Suppose cr123.tmp, crequ.tmp, crkkin.tmp...........etc files are present under C:\Windows folder.


The following script can be used to delete cr*.tmp files from C:\Windows folder


strDir = "C:\WINDOWS"
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(Left(Cstr(aItem.Name), 2)) = "cr") AND fso.GetExtensionName(LCase(aItem.Name)) = "tmp" Then
aItem.delete(True)
End If
Next
For Each aItem In pCurrentDir.SubFolders
'wscript.Echo aItem.Name & " passing recursively"
getInfo(aItem)
Next
End Sub

Sunday, 11 January 2009

MSI Errors List

  • 1620: This installation package could not be opened. Contact the application vendor to verify that this is a valid Windows Installer package.
  • 1911: Could not register type library for file [2]. Contact your support personnel.
  • 1601: The Windows Installer service could not be accessed. Contact your support personnel to verify that the Windows Installer service is properly registered.
  • 1605: This action is only valid for products that are currently installed.
  • 1601: The Windows Installer Service Could Not Be Accessed
  • 1155: File [1] not found
  • 1325: ''[2]'' is not a valid short file name.
  • 2303: Error getting volume info. GetLastError: [2].
  • 2717: Bad action condition or error calling custom action ''[2]''.
  • 1613: This installation package cannot be installed by the Windows Installer service. You must install a Windows service pack that contains a newer version of the Windows Installer service.
  • 1603: A fatal error occurred during installation.
  • 1706: No valid source could be found for product [2].
  • 1316: A network error occurred while attempting to read from the file: [2]
  • 1723: There is a problem with this Windows Installer package. A DLL required for this install to complete could not be run. Contact your support personnel or package vendor. Action [2], entry: [3], library: [4]
  • 2755: Server returned unexpected error [2] attempting to install package [3].
  • 1719: Windows Installer service could not be accessed. Contact your support personnel to verify that it is properly registered and enabled.
  • 1635: This patch package could not be opened. Verify that the patch package exists and is accessible, or contact the application vendor to verify that this is a valid Windows Installer patch package.
  • 1612: The installation source for this product is not available. Verify that the source exists and that you can access it.
  • 1601: The Windows Installer service could not be accessed. Contact your support personnel to verify that the Windows Installer service is properly registered.
  • 1713: [2] cannot install one of its required products. Contact your technical support group. System Error: [3].
  • 1321: The Installer has insufficient privileges to modify this file: [2].

Install MSI from Remote Machine

The following is from Microsoft's "System Administration Scripting Guide". Note that Active Directory is needed for this VB script to work.

Description:

Installs a hypothetical software program (using a Windows Installer package) on a remote computer. Requires delegation for the computer and user accounts involved in the procedure.

Script Code

====================

Const wbemImpersonationLevelDelegate = 4
Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objConnection = objwbemLocator.ConnectServer _
("WebServer", "root\cimv2", "fabrikam\administrator", _
"password", , "kerberos:WebServer")
objConnection.Security_.ImpersonationLevel = wbemImpersonationLevelDelegate
Set objSoftware = objConnection.Get("Win32_Product")
errReturn = objSoftware.Install("\\atl-dc-02\scripts\1561_lab.msi",,True)
Wscript.Echo errReturn

===========================


MSI Log Files

MSI log files can be incredibly useful for creating silent installations of vendor provided MSI's - for example, an application that has a serial number, or asks various questions, if you do a manual install fully logged (msiexec.exe /i /L*v c:\temp\funkylog.log) and then look in the log for the command line - it will change as the installation progresses but often things that the installation asks the user for are uses as properties, which can be entered in the command line, or in an MST and aid a silent installation.