Posts

VBScript to Determine 32-bit or 64-bit machine

Often we come across a situation where we need to see the Operating system bit information and then install application or do any customization. Here is a script which I use for this purpose: '=============================================================== Const HKEY_LOCAL_MACHINE = &H80000002 'Lines to get the computer Name Set wshShell = WScript.CreateObject( "WScript.Shell" ) strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )   '=============================================================== 'To check whether the OS is 32 bit or 64 bit of Windows 7 '=============================================================== 'Lines to detect whether the OS is 32 bit or 64 bit of Windows 7 Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputerName & "\root\default:StdRegProv")   strKeyPath = "HARDWARE\DESCRIPTION\System\CentralProcessor\0"   strValueName = ...

VBScript to determine Root Drive

As per best practices we should not hard code the Root Drive in our package. If your package goes to multiple machines having different Root Drives, then you can use this simple VBScript in your package as Custom Action and it will set the Root Drive automatically for that machine. This script picks up the Root Drive from where Program Files folder is installed. Set oshell=CreateObject("Wscript.shell") prog=oshell.ExpandEnvironmentStrings("%ProgramFiles%") vletter=Split(prog,":") dletter=vletter(0) & ":\" session.property("ROOTDRIVE")=dletter

Installation and Uninstallation of MSU in silent mode

MSU are the Microsoft Update files. You can easily install the MSU file silently without reboot with the following command line: wusa.exe Windows6.1-KB123456-x86.msu /quiet /norestart To Uninstall it Silently you need to follow this simple procedure: 1) Run this command: expand c:\temp\Windows6.0-KB123456-x86.msu –F:Windows6.0-KB123456-x86.xml c:\temp 2) This will create an XML file in temp folder as per the name above. Edit this xml in notepad. 3)Find the assemblyidentity tag. Then, note the values of the following attributes: The name attribute The publickeytoken attribute The processArchitecture attribute The version attribute 4) Use the below command to uninstall the MSU from your machine. start /w pkgmgr /up: name ~ publickeytoken ~ processArchitecture ~~ version Note: The variables above need to be replaced by the vaules you have copied in step 3.

VBScript to copy file and Powershell Script to copy file

VBScript to copy file: dim filesys, oShell Set filesys = CreateObject("Scripting.FileSystemObject") Set oShell = CreateObject("WScript.Shell") sup = oShell.ExpandEnvironmentStrings ("%APPDATA%") des = oShell.ExpandEnvironmentStrings ("%ProgramFiles(x86)%") destfile= sup & "\AR System\HOME\AR" sourcefile= des & "\AR System\User\AR" If filesys.FileExists(sourcefile) Then    filesys.CopyFile sourcefile, destfile End If Powershell Script to copy file: $SourceFile = "c:\foo\Test.txt";  $NewFile    = "c:\foo\Test2.txt";    # Now - check to see if $Sourcefile exists, and if so,  # copy it to $newfile   if ([System.IO.File]::Exists($SourceFile))  {     [System.IO.File]::Copy($SourceFile, $NewFile)     "Source File ($SourceFile) copied to ($newFile)"  }  else {  "Source file ($Sourcefile) does not exist."  }

Creating a SendTo Shortcut through MSI

If you want to create a SendTo shortcut through MSI, then if you just add the shortcut in MSI in SendTo folder, it will not work. Even if you get the shortcut there in every user profile, still it will not work. To make a SendTo shortcut, you need to create it on the fly, which means that shortcut should be created from original exe. To solve this issue for one of my application, WinSCP, I wrote the below VBScript and placed it in %ALLUSERPROFILE%\WinSCP folder. Then I created an Active setup to call this VBScript. Set Shell = CreateObject("WScript.Shell") ShortcutPath = Shell.SpecialFolders("SendTo") Set link = Shell.CreateShortcut(ShortcutPath & "\WinSCP (for upload).lnk") link.Arguments = "/upload" link.Description = "WinScp" link.HotKey = "" link.IconLocation = "C:\Program Files (x86)\WinSCP\WinSCP.exe,0" link.TargetPath = "C:\Program Files (x86)\WinSCP\WinSCP.exe" link.WindowStyle = 3 link.WorkingD...

VBScript to Kill a Process

This worked great for me. Just use as function and kill as many processes as you like. KillProc "abc.exe" Sub KillProc( myProcess )     Dim blnRunning, colProcesses, objProcess     blnRunning = False     Set colProcesses = GetObject( _                        "winmgmts:{impersonationLevel=impersonate}" _                        ).ExecQuery( "Select * From Win32_Process", , 48 )     For Each objProcess in colProcesses         If LCase( myProcess ) = LCase( objProcess.Name ) Then             ' Confirm that the process was actually running             blnRunning = True ...

VBScript to enable "Use this connection's DNS Suffix in DNS registration" in IPV4

I have written this below VBScript to enable "Use this connection's DNS Suffix in DNS registration" in IPV4 Advanced Settings. For Desktop adaptor, this (to enable "Use this connection's DNS Suffix in DNS registration" in IPV4) can be fixed by changing the registry value of HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces\ NetworkInterfaceID \RegisterAdapterName to 1 Here NetowrkInterfaceID is a unique ID for every user and this can be obtained from "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\8\ServiceName" key. The issue is there can be multiple Network adaptors connected to the machine like Network adaptor for Desktop, Wireless Adaptor, VMware adaptor etc and they all are stored under different hive, like 8, 12, 14 etc. Hence I have written a script which will check for all this and will change the value for all adaptors. If you want for only one particular adaptor, you can modify...