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
Wednesday, 28 January 2009
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
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
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
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
===========================
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.
Local Admin Check - VBScript
Check if the current user is a local administrator using the Windows Installer service.
Dim oInst, oSess, iAdmin, oProducts
Const msiUILEVELNONE = 2
Set oInst = CreateObject("WindowsInstaller.Installer")
oInst.UILevel = msiUILEVELNONE
Set oProducts = oInst.Products
Set oSess = oInst.OpenProduct(oProducts(0))
iAdmin = oSess.Property("AdminUser")
If iAdmin = 1 Then
Msgbox "You are a local administrator!", vbInformation, "ADMINISTRATOR"
Else
Msgbox "You are not a local administrator!", vbCritical, "NON-ADMIN"
End If
Dim oInst, oSess, iAdmin, oProducts
Const msiUILEVELNONE = 2
Set oInst = CreateObject("WindowsInstaller.Installer")
oInst.UILevel = msiUILEVELNONE
Set oProducts = oInst.Products
Set oSess = oInst.OpenProduct(oProducts(0))
iAdmin = oSess.Property("AdminUser")
If iAdmin = 1 Then
Msgbox "You are a local administrator!", vbInformation, "ADMINISTRATOR"
Else
Msgbox "You are not a local administrator!", vbCritical, "NON-ADMIN"
End If
Restart for the Setup Capture Process
Many applications come up with a message after installation stating you must now restart the Computer.
Some packagers and Instructors are taught that during the setup capture of an application you MUST restart the Computer to capture any file updates and or registry changes that take place.
This is not always true.
Many times after the installation of an application simply running any and or all shortcuts that are created before doing the End Capture will update or create the Registry keys and files needed for the application package to work properly. Being able to bypass the restart during the setup capture does save time and depending what kind of environment you are packaging in (hopefully a VMware OS only environment) you will not capture any Registry keys or files that are not needed for the application package to function properly.
I have found that doing the steps above works atleast 80% of the time.
Some packagers and Instructors are taught that during the setup capture of an application you MUST restart the Computer to capture any file updates and or registry changes that take place.
This is not always true.
Many times after the installation of an application simply running any and or all shortcuts that are created before doing the End Capture will update or create the Registry keys and files needed for the application package to work properly. Being able to bypass the restart during the setup capture does save time and depending what kind of environment you are packaging in (hopefully a VMware OS only environment) you will not capture any Registry keys or files that are not needed for the application package to function properly.
I have found that doing the steps above works atleast 80% of the time.
All about MSI Re-Packaging
First of all MSI installations are already in a in a distributable format, so there is no benefit to recreating the setup. MSI packages are full of internal references, which cannot be captured and recreated. These internal references are critical to the self-healing functionality of MSI packages and are fundamental to their operation.
Repackaging an MSI may result in uninstall problems and other Windows Installer related problems. Finally, and perhaps most important, when the vendor releases and update or patch (MSP) for the product, it will be designed to update their MSI and not yours. When repackaging, all of the globally unique identifiers (GUIDs) used to identify items in the package are regenerated and will not match up to the updates provided by the software vendor package.
There are no changes that cannot be implemented at install-time using an MST (transform) file. Aside from dictating installation preferences, you can add, delete or change any items you wish. I have had some people challenge the fact that the capabilities of MST negate the need to repackage an MSI. While the statement is certianly a fact- it can admittedly be a very difficult task to carry out when dealing with certian packages. Have you given up on MST and repackaged an MSI? Please rate the applications difficulty and provide comments in the software's Package Knowledge base entry. Fighting with a package right now? The Package Knowledge base may hold some answers for you. Also visit our package development message board.
Repackaging an MSI may result in uninstall problems and other Windows Installer related problems. Finally, and perhaps most important, when the vendor releases and update or patch (MSP) for the product, it will be designed to update their MSI and not yours. When repackaging, all of the globally unique identifiers (GUIDs) used to identify items in the package are regenerated and will not match up to the updates provided by the software vendor package.
There are no changes that cannot be implemented at install-time using an MST (transform) file. Aside from dictating installation preferences, you can add, delete or change any items you wish. I have had some people challenge the fact that the capabilities of MST negate the need to repackage an MSI. While the statement is certianly a fact- it can admittedly be a very difficult task to carry out when dealing with certian packages. Have you given up on MST and repackaged an MSI? Please rate the applications difficulty and provide comments in the software's Package Knowledge base entry. Fighting with a package right now? The Package Knowledge base may hold some answers for you. Also visit our package development message board.
Subscribe to:
Posts (Atom)