Thursday 12 March 2015

Installing INF/Driver - DPInst through VBScript - Advance Application Packaging


Driver Package Installer (DPInst) version 2.1 is a component of Driver Install Frameworks (DIFx) version 2.1.
DIFx simplifies and customizes the installation of driver packages for devices that have not yet been installed in a computer.
This type of installation is commonly known as a software-first installation.

DPInst searches for INF files for driver packages in the DPInst working directory.
By default, the DPInst working directory is the DPInst root directory, which is the directory that contains the DPInst executable (DPInst.exe).
You can use the /path DPInst command-line switch to specify a custom DPInst working directory.

For each driver package that is installed by DPInst,DPInst adds an entry to Programs and Features in Control Panel.
Users can select this entry within Programs and Features to remove the driver package from their computers.
If a user removes a driver package, the package is removed from the DIFx driver store, the corresponding INF file is removed from the system INF file directory, and all the devices that were previously supported by the package are updated with the next best available driver.

DPInst records high-level messages in the DPInst log file (%SystemRoot%\DPINST.LOG).
The log file is a plain-text file that contains information and error messages and identifies the driver package that was being installed when an error occurred.

DPInst Command-Line Switches - Click Here


Installation :-

Option Explicit
On Error Resume Next

Dim strCmd,WshShell,strInstalldir


Set WshShell = CreateObject("WScript.Shell")

strInstalldir = WshShell.ExpandEnvironmentStrings( "%SYSTEMDRIVE%" )

strCmd = chr(34) & strInstalldir & "\snb\apps\blp\DriverFiles\DPInst_x64.exe" & chr(34) & " /F /LM /S" 


WshShell.Run strCmd


Set WshShell = Nothing



Uninstallation :-

Option Explicit
On Error Resume Next

Dim strCmd,WshShell,strInstalldir,strcmd1, strcmd2

Set WshShell = CreateObject("WScript.Shell")
strInstalldir = WshShell.ExpandEnvironmentStrings( "%SYSTEMDRIVE%" )

strcmd= chr(34) & strInstalldir & "\snb\apps\blp\DriverFiles\DPInst_x64.exe" & chr(34) & " /S /U " & chr(34) & strInstalldir & "\snb\apps\blp\DriverFiles\ATTchWDF.inf" & chr(34) &" /D"

    
WshShell.Run strCmd

Set WshShell = Nothing


Download the DPInst.exe file according to your OS Architecture requirnment and update in VBScript too.

DPInst_x64.exe

DPInst_x86.exe


More detailed Arical on Symentec website - Click Here
Thank you for reading.






Wednesday 11 March 2015

Service Start/Stop through VBScript - Advance Application Packaging


Hereby writting a simple VBScript to start and stop any service :


Option Explicit
On Error Resume Next

Dim strCmd

Dim WshShell
                                                                    
strCmd = "cmd.exe /c net stop Spooler"                  
Set WshShell = CreateObject("WScript.Shell")                                                    
WshShell.Run strCmd , 0, True                                                                                   
Set WshShell = Nothing


In above Example Spooler is service name.

To Start
strCmd = "cmd.exe /c net start Spooler" 

To Stop
strCmd = "cmd.exe /c net stop Spooler" 

some more parameter can be used with NET command are as below,

[ ACCOUNTS | COMPUTER | CONFIG | CONTINUE | FILE | GROUP | HELP | HELPMSG | LOCALGROUP | PAUSE | SESSION | SHARE | START | STATISTICS | STOP | TIME | USE | USER | VIEW ]

Thank you for reading.

Register a DLL through VBScript - Advance Application Packaging


Below piece of code can be used to register a DLL.
EAL.dll  & erxml.dll are two DLL are registered from ProgramFiles(x86) location

Option Explicit
On Error Resume Next

Dim oShell

Dim StrOSType,strPath

set oShell = CreateObject("Wscript.Shell")

strPath=oShell.ExpandEnvironmentStrings("%ProgramFiles(x86)%")

objshell.run "regsvr32.exe /s %programfiles(x86)%\CA\AllFusion ERwin Data Modeler r7\EAL.dll"

objshell.run "regsvr32.exe /s %programfiles(x86)%\CA\AllFusion ERwin Data Modeler r7\erxml.dll"

Set oShell = nothing



Below piece of code can be used to unregister a DLL
EAL.dll  & erxml.dll are two DLL are unregistered from ProgramFiles(x86) location

Option Explicit
On Error Resume Next

Dim oShell

Dim StrOSType,strPath

set oShell = CreateObject("Wscript.Shell")

strPath=oShell.ExpandEnvironmentStrings("%ProgramFiles(x86)%")

oShell.Run "cmd /C regsvr32 /u /s "& chr(34) & strPath &"\CA\AllFusion ERwin Data Modeler r7\EAL.dll"& chr(34),0,True

oShell.Run "cmd /C regsvr32 /u /s "& chr(34) & strPath &"\CA\AllFusion ERwin Data Modeler r7\erxml.dll"& ch(34),0,True


Set oShell = nothing


Thank you for reading.

Taskkill through VBScript - Advance Application Packaging


During uninstallation of some application some background task must be killed before proceeding to uninstall.

In such scenaros following code can be embeded in CustomAction,


Option Explicit
On Error Resume Next

Dim strProcessName, strCmd

Dim WshShell

strProcessName = "RemoteVault.exe"

strCmd = "CMd /C TASKKILL /IM " & strProcessName & " /F /T"                  
Set WshShell = CreateObject("WScript.Shell")                                                    
WshShell.Run strCmd , 0, True                                                                                   
Set WshShell = Nothing


In above line of code RemoteVault.exe is the background running process/task.

Thank you for reading.

CREATE/COPY/DELETE the FILE/FOLDER through VBScript - Advance Application Packaging

Hi all,

Here is small piecs of code which will be very usefule in doing file & folder operations during writting any VBScript.


Option Explicit
on error resume next
Dim objShell,objFSO,strPath
Dim CreateFolder1,Copyfile1,DelFolder1
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strPath = objShell.ExpandEnvironmentStrings("%ProgramData%")

*************** CREATE FOLDER ***************

CreateFolder1=strPath & "\Microsoft\Windows\Start Menu\Programs\MyApps"
CreateFolder2=strPath & "\Microsoft\Windows\Start Menu\Programs\MyApps\Vinayak"

If NOT objFSO.FolderExists(CreateFolder1) Then

objFSO.CreateFolder(CreateFolder1)
objFSO.CreateFolder(CreateFolder2)
End If

OR 

objShell.Run "CMD.exe /C md "& chr(34) & strPath & "\MyApps\Vinayak"& chr(34),0,True

objShell.Run "cmd.exe /c " & chr(34) & "md " & chr(34) & CreateFolder2 & chr(34),0,True



*************** COPY FILE ***************

Copyfile1=strPath & "\Microsoft\Windows\Start Menu\Programs\MyApps\Vinayak\MyShortcut.lnk"

If objFSO.FileExists(Copyfile1) Then

objFSO.copyFile Copyfile1,CreateFolder2
End If

objShell.Run "cmd.exe /c " & chr(34) & "copy /Y " & chr(34) & Copyfile1 & chr(34) & " " & chr(34) & CreateFolder2 & chr(34) & chr(34),0,True


*************** COPY FOLDER ***************


If objFSO.FolderExists(CreateFolder1) Then
objFSO.CopyFolder CreateFolder2,CreateFolder1
objFSO.CopyFolder "C:\MyApps\Vinayak", "C:\Vinayak\" 
objFSO.CopyFolder strPath & "\MyApps\Vinayak",strPath & "\Vinayak\",True
End If

*************** DELETE FILE ***************

Delfile1=strPath & "\Microsoft\Windows\Start Menu\Programs\MyApps\Vinayak\MyShortcut.lnk"

If objFSO.FileExists(Delfile1) Then

objFSO.DeleteFile Delfile1,TRUE
End If

*************** DELETE FOLDER ***************


DelFolder1=strPath & "\Microsoft\Windows\Start Menu\Programs\MyApps\Vinayak\"

If objFSO.FolderExists(DelFolder1) Then

objFSO.DeleteFolder DelFolder1,TRUE
objFSO.DeleteFolder StrPath & "\MyApps\Vinayak",True
End If

objShell.Run "cmd.exe /c " & chr(34) & "RD /S /Q " & chr(34) & DelFolder1 & chr(34) & chr(34),0,True

  
Set objFSO = Nothing
Set objShell = Nothing


Thank you for reading.

Replace text in .txt file through VBScript - Advance Application Packaging


Replacing some text in .txt file or any file through VBScript,


Function ReplacePrgPath(sFilePath,FND,REPL)
  Dim goFso
  Dim oGFile,oFile,sFileContent
  Set goFso = CreateObject("Scripting.FileSystemObject")
  Set oGFile = goFso.GetFile(sFilePath)
  Set oFile = oGFile.OpenAsTextStream(1, -2)
  sFileContent = oFile.ReadAll
  oFile.Close
  Set oFile = Nothing

  sFileContent = Replace(sFileContent, FND, REPL)


  Set oFile = oGFile.OpenAsTextStream(2, 0)

  Err.Clear
  oFile.Write sFileContent
  oFile.Close
  Set oFile = Nothing
  Set oGFile = Nothing
End Function

ReplacePrgPath sActionItem, "C:\",RDRIVE & "\"




sActionItem          IS FILE NAME with PATH
"C:\"                     IS TEXT TO BE REPLACE
RDRIVE & "\"    IS TEXT TO BE REPLACE WITH


Thank you for reading.

Preventing "Open File - Security Warning" through VBScript - Advance Application Packaging


When we run any VBScript from network location Security Warning popup comes up to go further,




 To prevents "Open File - Security Warning" dialog box use below code :



'Declare this variable
Dim oEnv

'Put this piece of code after obj shell declaration
set oEnv = objShell.Environment("PROCESS")
oEnv("SEE_MASK_NOZONECHECKS") = 1

'Put this code at the last section of script
objEnv.Remove("SEE_MASK_NOZONECHECKS")

Thank you for reading.

Wait for some process in VBScript - Advance Application Packaging


Sometime it is required to wait for some process exeution to go for next execution step in VBScript, In such scenario following piece of code can be useful.

Dim colProcesses, objWmi
   
Set objWmi=GetObject ("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set objShell = CreateObject("WScript.Shell")
objShell.Run "ping 1.1.1.1 -n 1 -w 30000",0,True 

Set colProcesses=objWmi.ExecQuery ("Select * From Win32_Process Where Name='Setup.exe'")

Do While colProcesses.Count<>0
Set colProcesses=objWmi.ExecQuery ("Select * From Win32_Process Where Name='Setup.exe'")
objShell.Run "ping 1.1.1.1 -n 1 -w 30000",0,True 
Loop


Ping can be replace with Wait also
Ex : objShell.Run "ping 1.1.1.1 -n 1 -w 30000",0,True OR wscript.sleep(30000)

Setup.exe is the name of process for which installer/script will wait/loop for specified time interval

Thank you for reading.

Tuesday 10 March 2015

Detecting Processors Architecture/OS Version through VBScript - Advance Application Packaging


If you want to find the architecture of the machine, you can grab it from the following registry entry:

"HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE"

If your application is a 32-bit application running on a 64-bit OS the process version of this environment variable will return x86.


Option Explicit
On Error Resume Next

dim filesys,objShell,strProgData, StrOSType

Set filesys = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
StrOSType = objShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE")

If (StrOSType = "x86") Then

strProgData=objShell.ExpandEnvironmentStrings("%programfiles%")
'To Set variable value to 32 bit

else

strProgData=objShell.ExpandEnvironmentStrings("%programfiles(x86)%")
'To Set variable value to 64 bit

End if



Same way we can check the Operating System version

Option Explicit
On Error Resume Next
Dim intOSVersion,OSVersion
intOSVersion = objShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion")

If intOSVersion = 6.1 Then


OSVersion = "Windows7"


ElseIf intOSVersion <= 5.2 Then


OSVersion = "WindowsXP"


End If



Thank you for reading.