Showing posts with label VBScript. Show all posts
Showing posts with label VBScript. Show all posts

Friday, 21 October 2011

A VBScript Example to Copy Files to User Temp Folder

Below is an example of VBScript codes to copy files from current folder to '[User Profile]\Local Settings\Temp' folder then execute an executable file under the folder:
Set objShell = WScript.CreateObject("WScript.Shell")
currentFolder = objShell.CurrentDirectory

Dim filesys
Set filesys = CreateObject("Scripting.FileSystemObject")

Set appShell = CreateObject("Shell.Application")


'Set the destination folder to be checked/created

'these commented codes would use a folder under 'Program Files'
'Const PROGRAM_FILES = &H26&
'Set objFolder = appShell.Namespace(PROGRAM_FILES)
'Set objFolderItem = objFolder.Self
'Wscript.Echo objFolderItem.Path    'testing
'destinationFolderPath = objFolderItem.Path & "\MyApp\Install" 

'using '[User Profile]\Local Settings\Temp' folder, this value can be retrieved by using
'   filesys.GetSpecialFolder(2)     or      objShell.ExpandEnvironmentStrings("%temp%")
'testing - Wscript.Echo filesys.GetSpecialFolder(2)   ' or objShell.ExpandEnvironmentStrings("%temp%")
destinationFolderPath = objShell.ExpandEnvironmentStrings("%temp%") & "\MyApp.TMP"


'Check if folder exists
Dim newfolder
If Not filesys.FolderExists(destinationFolderPath) Then
    'if not then create one
    Set newfolder = filesys.CreateFolder(destinationFolderPath)
Else
    'clear all existing files under the destination folder
    filesys.DeleteFile(destinationFolderPath & "\*"), true  ' true - delete read only files
End If


'Copy all files under current folder to the destination folder
filesys.CopyFile currentFolder & "\*.*", destinationFolderPath & "\", true  ' true - overwrite existing


'Run installer
objShell.Run ("""" & destinationFolderPath & "\setup.exe" & """")
'objShell.Run ("""" & destinationFolderPath & "\setup.exe" & """"), 0, true     ' 0 - Hides the window and activates another window.
                                                                                ' true - the script should wait for the program to finish executing before continuing to the next statement


'Finalise
set appShell = Nothing
set filesys = Nothing
set objShell = Nothing
Wscript.Quit

Some Notes about Windows Installer, IExpress and VBScript


Choosing a deployment strategy for Visual Studio 2010
http://msdn.microsoft.com/en-us/library/e2444w33%28VS.100%29.aspx


ClickOnce
ClickOnce is a deployment technology that enables you to create self-updating Windows-based applications that can be installed and run with minimal user interaction. ClickOnce deployment overcomes three major issues in deployment:

- Difficulties in updating applications. With Microsoft Windows Installer deployment, whenever an application is updated, the user must reinstall the whole application; with ClickOnce deployment, you can provide updates automatically. Only those parts of the application that have changed are downloaded, and then the full, updated application is reinstalled from a new side-by-side folder.

- Impact to the user's computer. With Windows Installer deployment, applications often rely on shared components, with the potential for versioning conflicts; with ClickOnce deployment, each application is self-contained and cannot interfere with other applications.

- Security permissions. Windows Installer deployment requires administrative permissions and allows only limited user installation; ClickOnce deployment enables non-administrative users to install and grants only those Code Access Security permissions necessary for the application.
[http://msdn.microsoft.com/en-us/library/142dbbz4.aspx]


Walkthrough of creating an installer using Windows Setup Project
http://www.codeproject.com/KB/dotnet/Win_App_Setup_Project.aspx


Product Code and Package Code
If the new MSI file has the same ProductCode and PackageCode as a product that’s already installed, Windows indicates that you must repair or remove the product.

If the new MSI file has the same ProductCode as an installed product but a different PackageCode, you’ll receive a message indicating that another version of the product is already installed.

Repair does not use your new MSI file to repair the product, nor does it update what you previously installed. Instead, it repairs the existing installed product. That is, it behaves as if you went to the original MSI file used to install the existing product, selected the context menu, and chose repair. (Note: Repair can also be initiated from Add/Remove programs.)
[http://www.simple-talk.com/dotnet/visual-studio/updates-to-setup-projects/]


Creating bootstrapper packages
http://msdn.microsoft.com/en-us/library/ms165429.aspx


The difference between MSI and EXE file
http://www.symantec.com/connect/articles/understanding-difference-between-exe-and-msi


DISABLEADVTSHORTCUTS property of Setup.EXE
Setting the DISABLEADVTSHORTCUTS property disables the generation of shortcuts supporting installation-on-demand and advertisement. Setting this property specifies that these shortcuts should instead be replaced by regular shortcuts.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa368297%28v=vs.85%29.aspx


Installation-on-demand and advertisement
With traditional installation technology, it is necessary to exit an application and rerun setup to perform an installation task. This commonly occurred when a user wanted a feature or product not chosen during the first run of setup. This often made the process of product configuration inefficient because it required the user to anticipate the functionality required before they ever used the product.

Installation-on-demand makes it possible to offer functionality to users and applications in the absence of the files themselves. This notion is known as advertisement. The Windows Installer has the capability of advertising functionality and to make installation-on-demand of application features or entire products possible. When a user or application activates an advertised feature or product, the installer proceeds with installation of the needed components. This shortens the configuration process because additional functionality can be accessed without having to exit and rerun another setup procedure.
[http://msdn.microsoft.com/en-us/library/windows/desktop/aa369293%28v=vs.85%29.aspx]


IExpress – How to use
http://home.wanadoo.nl/kixtart/download/IExpress.pdf

When IExpress extracts the files to a temporary directory and runs an installation command it watches the command it ran. When this process is finished, IExpress removes its temporary files from the drive.
[http://www.picturestoexe.com/forums/index.php?/topic/1983-maybe-you-didnt-know/]
http://www.mdgx.com/INF_web/iexpress.htm


SED file for IExpress - Overview
http://www.mdgx.com/INF_web/cdfinfo.htm


Running VBScript file from IExpress
http://markalexanderbain.suite101.com/distributing-a-vbscript-application-a90365


How to install shortcuts using VBScript:
http://ss64.com/nt/shortcut.html
http://www.vbforums.com/showthread.php?t=234891
http://www.appdeploy.com/messageboards/tm.asp?m=26758&mpage=1&key=梆

How to install application using VBScript:
http://www.symantec.com/connect/blogs/installing-application-using-vbscript
http://www.symantec.com/connect/downloads/vbscript-install-application-exit-code
http://msdn.microsoft.com/en-us/library/d5fk67ky%28v=vs.85%29.aspx
http://technet.microsoft.com/en-us/library/ee692649.aspx

VBScript examples for file management:
http://activexperts.com/activmonitor/windowsmanagement/adminscripts/filesfolders/files/
http://technet.microsoft.com/en-us/library/ee176983.aspx
http://www.computerperformance.co.uk/ezine/ezine139.htm

VBScript examples for special folders
http://www.activexperts.com/activmonitor/windowsmanagement/scripts/desktop/specialfolders/