Thursday, 21 July 2011

VBScript to Install a batch file to remote computers by reading their computer names from a text file

This script will install a batch file to the computers listed in the text file.
For executing this, you need to create a text file (Servers.txt) listing computer names (one name per line).
This will check if the application is already present in the machine and if present it will reinstall the application and if not it will install to that machine.
----------------------------------------------------------------------------------------------------------------------
Dim strComputer
Dim objWMIService
Dim propValue
Dim objItem
Dim SWBemlocator
Dim UserName
Dim Password
Dim colItems
Dim objFSO

Const INPUT_FILE_NAME = "C:\Servers.txt"
Const FOR_READING = 1
Const ForAppending = 8

Set objFSO = CreateObject("Scripting.FileSystemObject")
dim shell
dim objTextFile
set shell=createobject("wscript.shell")
Set objTextFile = objFSO.CreateTextFile("C:\SMSClient.txt", True)
objTextFile.WriteLine("Remote installation of SMS Client:")
objTextFile.WriteLine("----------------------------------")
objTextFile.WriteBlankLines(1)
rem Next

Set objFile = objFSO.OpenTextFile(INPUT_FILE_NAME, FOR_READING)
strComputers = objFile.ReadAll
objFile.Close
arrComputers = Split(strComputers, vbCrLf)
On Error Resume Next
 For Each strComputer In arrComputers

 If Trim(strComputer) <> "" Then
      Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
      Set objWMIService = SWBemlocator.ConnectServer(strComputer,"\root\CIMV2",UserName,Password)
  If (Err.Number <> 0) Then
         objTextFile.WriteLine "" & Date & " " & Time & ":" & " Error encountered connecting to '" & strComputer & "': " & Err.Number & ", " & Err.Description
         objTextFile.WriteBlankLines(1)
         rem Next
         Err.Clear
      Else
         Set colItems = objWMIService.ExecQuery("Select * from Win32_WMISetting",,48)
   If (Err.Number <> 0) Then
           objTextFile.WriteLine "" & Date & " " & Time & ":" & " Error querying Win32_WMISetting on '" & strComputer & "': " & Err.Number & Err.Description
    objTextFile.WriteBlankLines(1)
           rem Next
           Err.Clear
         Else
    For Each objItem in colItems
         
     Const HKEY_LOCAL_MACHINE = &H80000002
     Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
     strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{4A39A27F-005B-407E-8CF5-F4D8065658E4}"
     strValueName = "DisplayName"
     objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
     If IsNull(strValue) Then

      objFSO.CopyFile "Install.bat" , "\\" & strComputer & "\C$\", True
      strCommand = "\\" & strComputer & "\C$\Install.bat"
      Const INTERVAL = "n"
      Const MINUTES = 1
      Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
      Set objScheduledJob = objWMIService.Get("Win32_ScheduledJob")
      Set objSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")

      objSWbemDateTime.SetVarDate(DateAdd(INTERVAL, MINUTES, Now()))
      errReturn = objScheduledJob.Create(strCommand, objSWbemDateTime.Value, False, 0, 0, True, intJobID)
    
      Wscript.Sleep 150000
      objFSO.DeleteFile("\\" & strComputer & "\C$\Install.bat")
    
      objTextFile.WriteLine "" & Date & " " & Time & ":" & " SMS Client is not found in " & strComputer
      objTextFile.WriteBlankLines(1)
      rem Next      
      If errReturn <> 0 then
       objTextFile.WriteLine "" & Date & " " & Time & ":" & " Failed to Install SMS Client to " & strComputer
       objTextFile.WriteBlankLines(1)
       rem Next
      Else
       WScript.Sleep 20000
       objTextFile.WriteLine "" & Date & " " & Time & ":" & " Successfully installed SMS Client to " & strComputer
       objTextFile.WriteBlankLines(1)
       rem Next
      End if
     Else
    
     
      strValue= "Processing on "
      objTextFile.WriteLine(Date & " " & Time & ":" & " " & strValue & strComputer)
      objTextFile.WriteBlankLines(1)
      objTextFile.WriteLine "" & Date & " " & Time & ":" & " Reinstalling SMS Client in " & strComputer
      objTextFile.WriteBlankLines(1)
      rem Next
      intCacheSize = 2048
      Set objWMIService = GetObject("winmgmts://" & strComputer & "/root/ccm/SoftMgmtAgent")
      Set colItems = objWMIService.ExecQuery("Select * from CacheConfig")
      For Each objItem_1 in colItems
       objItem_1.Size = intCacheSize
       objItem_1.Put_ 0
                   
      Next
      Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
      Set colItems = objWMIService.ExecQuery("Select * from Win32_Service Where Name = 'CCMExec'")
      For Each objItem_1 in colItems
       objItem_1.StopService(strServiceName)
       Wscript.Sleep 10000
       objItem_1.StartService(strServiceName)
       objTextFile.WriteLine "" & Date & " " & Time & ":" & " The Cache On " & UCase(strComputer) & " is changed"
       objTextFile.WriteBlankLines(1)
       rem Next
      Next

      objFSO.CopyFile "Reinstall.bat" , "\\" & strComputer & "\C$\", True
      strCommand = "\\" & strComputer & "\C$\Reinstall.bat"
      Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
      Set objScheduledJob = objWMIService.Get("Win32_ScheduledJob")
      Set objSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")

      objSWbemDateTime.SetVarDate(DateAdd(INTERVAL, MINUTES, Now()))
      errReturn = objScheduledJob.Create(strCommand, objSWbemDateTime.Value, False, 0, 0, True, intJobID)
      Wscript.Sleep 150000
      objFSO.DeleteFile("\\" & strComputer & "\C$\Reinstall.bat")

          
      If errReturn <> 0 then
       objTextFile.WriteLine "" & Date & " " & Time & ":" & " Failed to Install SMS Client to " & strComputer
       objTextFile.WriteBlankLines(1)
       rem Next
      Else
       WScript.Sleep 20000
       objTextFile.WriteLine "" & Date & " " & Time & ":" & " Successfully installed SMS Client to " & strComputer
       objTextFile.WriteBlankLines(1)
       rem Next
      End if
     End If

    Next
   End If
  End If
 End If
 Next

Packaging .Net Framework 3.5 SP1

For the .Net Framework 3.5 SP1 application, the files get extracted to "C:\Windows\Microsoft.NET\Framework\v3.5", after installing the downloaded executable file. Out of those extracted files, we need to copy "vs_setup.msi" file and "vs_setup.cab" file which is the source for creating the package.
 
Create the application transform using this MSI file and add a property "ADDEPLOY" with value "1" and run it.

VB Script to kill the process using Wait Method and Do While Loop

Option Explicit
Dim objWMIService,objProcess, objProcess1, colProcess, strProcess,strProcess1
Dim xComputer,Flag
strProcess = "'notepad.exe'"
strProcess1 = "'cmd.exe'"
xComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& xComputer & "\root\cimv2")
 
Do
   Flag = 0
   WScript.Sleep 60000
   Set colProcess = objWMIService.ExecQuery _
   ("Select * from Win32_Process Where Name = " & strProcess)
   For Each objProcess in colProcess
   If objProcess.Name = strProcess then   
   objProcess.Terminate()
   Flag=1
   End If
   Next 
 
Loop Until Flag = 1

Easy way of Copying Condition in Custom Action

Suppose you are making a CustomAction2 and have added it in the sequence as shown :
 
And now you have to mention the condition same as that of CustomAction1, which in this case is "NOT Installed AND NOT PATCH", you have to click on CustomAction1 in the sequence and it will be like this:












 
 
 
You can see the Condition in the greyed area. You cannot copy it directly, but what you have to do is: go to any of the other tab from this situation, be it Properties or Details tab.
 
 
 
 
 



















 
 
 
All you have to do next is to come back to your Location tab. And here you see the result.The Condition is automatically copied to the CustomAction2.
 
 
 
 


















 
 
 

Adobe CS5 - disabling various auto updates

The solutions for disabling the various auto updates in the Adobe CS5 suite is as follows:
(The disabling of the application update itself isn't covered and is done by using the Adobe Application Manager Enterprise Edition utility.)
Adobe Help.exeThe solution to the Adobe Help application is to set the read-only attribute (using attrib.exe or similiar utility) of an xml file.
%APPDATA%\chc.4875E02D9FB21EE389F73B8D1702B320485DF8CE.1\Local Store\#ApplicationUpdater\state.xml
Adobe AirThe solution to disabling the Adobe Air auto updater is to create an empty file named updateDisabled and to put it in the following directory %APPDATA%\Adobe\AIR
Adobe Media PlayerThe solution is to add the following values to the file prefs.xml located in %APPDATA%\Adobe\Adobe Media Player\Local Store\settings

Packaging Adobe CS5

The Adobe Creative Suite 5 application has below file and folders:
-Deploy
-packages
-payloads
-resources
-Set-up.exe
The Adobe CS5 can be customized in 2 ways:
1. Using application.xml.override file 
Create "application.xml.override" file and place it in "Deploy" folder.
Below are the contents of "application.xml.override":
-------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Payload>
<Data key="EULA">Suppress</Data>
<Data key="Serial" protected="0">XXXXXXSERIALKEYXXXXXX</Data>
<Data key="Registration">Suppress</Data>
<Data key="Updates">Suppress</Data>
</Payload>
</Configuration>
--------------------------------------------------------------------------
Command lines
To install: Set-up.exe --mode=silent --deploymentFile=".\Deploy\en_US_Deployment.xml" overrideFile=".\Deploy\application.xml.override"
To uninstall:Set-up.exe --mode=silent --deploymentFile=".\Deploy\Uninstall.xml"
 
2.Using ApplicationManagerEnterprise  tool                                          
Double click on "ApplicationManagerEnterprise_2_all.exe",
Click on "Accept", below screen will appear.
Click on "INSTALLATION PACKAGE", below screen will appear:
Fill in the information:
Package Name: Name of the customized package to be created(An msi will be created with this name itself)
Save to : Browse for the location to save the customized package
Locate the Product Install folder: Browse for the folder in which the setup.exe and other folders present.
Find the below screenshot with filled data:
Click on "Next" the below screen will appear:
Enter the "SERIAL KEY" and click Next, the below screen will appear:
Click on Next, the below screen will apear:
Check or Uncheck the options depending on your requirement and click "Next", the below screen will appear
This checks for the updates and below screen appears
If you do not want to include the Updatesin the package uncheck "All Updates" and then Click On "Build".
If you want the updates to be installed, you click on to select the Updates according to your requirement.
ding
Upon Selection Click On "Build",
It creates a package which contains an msi with suport folders for installation.
The custom package contains the folders "Build" and "Exceptions". Use the Build folder for installation of Adobe CS5 application.
Tips:
-The msi created cannot be installed in UI mode and with switch /qb!.
-Use the below command to install in silent mode
Command Line: Msiexec.exe /i "<Path to CustomAdobe CS5.msi>" /qn
-Adobe design premium CS5 will install several applications.(Adobe Bridge, Device central, Adobe Air and many more)
-Adobe Air 1.0 is a part of Adobe CS5 intallation. So it is recommendable to install higher version of Adobe Air(Ex: Adobe Air 4.5) as a pre-requisite for Design premium CS5 application.
-Though the application is customized to suppress the
automatic update option, it will not be set in all applications which CS5 installs. This needs to handled by creating other msi.
-Refer the post from here to support suppressing the automatic update in all applications.
-Command line for uninstallation of the application:
msiexec /x <product code of AdobeCustom CS5> /qn

Using MSI Launch Conditions to Prevent Installation on Unsupported Windows Platforms

Before Windows 7, support for 64-bit Windows was not really a concern for most applications because they were aimed squarely at the 32-bit Windows market.  With Windows 7, a large percentage of Windows users will be using the 64-bit version, which means that your setup program has to know what to do when it encounters 64-bit Windows.  If your software only works on certain versions of Windows, you should be using launch conditions to prevent users from installing it on unsupported platforms.
I’ve created several launch conditions that you might want to use in your setups.  To keep things easy, I have organized the launch conditions using the table format of the LaunchCondition table in the InstallShield Direct Editor.
Example 1: Preventing Installation on 64-Bit Windows
In this example, the application will only work on 32-bit versions of Windows.  Therefore, the launch condition could be something like this:
Condition
Description
Not VersionNT64
[ProductName] will only work on 32-bit versions of Windows.  Please run the setup on 32-bit Windows.  Setup will now exit.

Example 2: Preventing Installation on 32-Bit Windows
This is the converse of Example 1. That is, the application requires 64-bit Windows and it will not run on 32-bit Windows.
Condition
Description
VersionNT64
[ProductName] will only work on 64-bit versions of Windows.  Please run the setup on 64-bit Windows.  Setup will now exit.

Example 3: Handling Multiple Versions of Windows with Different Service Packs
In this example, the application will run on three versions of Windows and each should have certain service packs.  The first condition (VersionNT >= “501”) prevents the end user from running the setup on Windows 2000 or Windows NT.  The last three conditions apply to only specific versions of Windows.  So if the setup runs on Windows Vista (VersionNT = “600), for example, the first, second, and fourth conditions will always return true, and the third condition will only return true if Service Pack 2 or later is installed.
Condition
Description
VersionNT >= “501”
[ProductName] requires Windows XP, Windows Vista, Windows 7, or a later version of Windows.  Setup will now exit.
(VersionNT = "501" And ServicePackLevel >= "3") Or VersionNT <> "501"
[ProductName] requires Windows XP Service Pack 3 or later.  Setup will now exit.
(VersionNT = "600" And ServicePackLevel >= "2") Or VersionNT <> "600"
[ProductName] requires Windows Vista Service Pack 2 or later.  Setup will now exit.
(VersionNT = “601” And ServicePackLevel >= “1”) Or VersionNT <> “601”
[ProductName] requires Windows 7 Service Pack 1 or later.  Setup will now exit.

Example 4: Ensuring the Setup Has Sufficient Privileges
Most setups install files to privileged locations such as the Program Files folder or the System folder.  And most setups also write to HKEY_LOCAL_MACHINE or HKEY_CLASSES_ROOT in the registry.  These locations require administrative privileges.  The best way to check for these privileges is to use the Privileged condition:
Condition
Description
Privileged
[ProductName] requires administrative privileges or elevated privileges.  Setup will now exit.


Launch Conditions in Windows Installer (MSI) are a great way to make sure that end users run the setup only on supported platforms. To take this idea further, you can also combine a System Search with a launch condition to check for required software or registry entries. The possibilities are numerous and correct use of launch conditions can really improve a setup.