Friday, 15 June 2012
Change File Attributes - VBScript
use following script to change attributes of any file or folder.
options are normal, read-only, hidden and system.
any combination of attributes may be set.
Dim FSO, fil, f, attr, i, Arg
Set FSO = CreateObject("Scripting.FileSystemObject")
'--check for drag-and-drop:
If WScript.arguments.count = 0 Then
Arg = InputBox("Enter the path of the file or folder you want to change the attributes of.", "Change File Attributes")
Else
Arg = WScript.arguments.item(0)
End If
If Arg = "" Then WScript.quit
'--check for existence of either file or folder and keep track of which with i :
If FSO.FileExists(Arg) = True Then
f = "File"
i = 1
ElseIf FSO.FolderExists(Arg) = True Then
f = "Folder"
i = 2
Else
MsgBox "Path is wrong. No such file or folder.", 16, "Wrong Path"
WScript.quit
End If
attr = InputBox("Enter the attributes number. Add numbers to get the desired combination of attributes." & VBCrLf & "Normal is 0" & VBCrLf & "ReadOnly is 1" & VBCrLf & "Hidden is 2" & VBCrLf & "System is 4", "Choose Attributes Setting", "0")
'--make sure that input is a number from 0 to 7:
If isNumeric(attr) = False Then
MsgBox "Wrong entry. Must be a number from 0 to 7.", 16, "Wrong Number"
WScript.quit
End If
If cInt(attr) > 7 or cInt(attr) < 0 Then
MsgBox "Wrong entry. Only 0 to 7 are possible.", 16, "Wrong Number"
WScript.quit
End If
If i = 1 Then
Set fil = FSO.GetFile(Arg)
fil.attributes = attr
Set fil = Nothing
MsgBox f & " attributes changed.", 0, "All Done"
End If
If i = 2 Then
Set fil = FSO.GetFolder(Arg)
fil.attributes = attr
Set fil = Nothing
MsgBox f & " attributes changed.", 0, "All Done"
End If
Increment ActiveSetup Version - VBScript
'This script will create the Active setup if not present on the system, otherwise it will increment the version of the active setup
' Need to replace the "Any that you want to run" with the exact path of the EXE/MSI/Script which has to run
' Replace the "<NameOfActiveSetup>" with the related unique application name
Option Explicit
On Error Resume Next
Dim WshShell ,PrgFiles,KeyValue
Set WshShell=CreateObject("WScript.Shell")
KeyValue=WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components\<NameOfActiveSetup>\Version")
WshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components\<NameOfActiveSetup>\StubPath", "Any that you want to run"
'Err.Clear
If Err.Number=0 Then
WshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components\<NameOfActiveSetup>\Version",KeyValue+1,"REG_SZ"
Else
WshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components\<NameOfActiveSetup>\Version","1","REG_SZ"
End If
Set WshShell = Nothing
Set PrgFiles = Nothing
WScript.Quit
Get current directory - VBScript
on Error Resume Next
Set objWshShell = CreateObject("WScript.Shell")
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
sScriptDir=objFileSystem.GetParentFolderName(WScript.ScriptFullName)
msgbox sscriptdir
Hide ARP Entry of MSI
use following script to Hide ARP entry of an MSI
Dim WSHShell,strRegKey
Set WSHShell = WScript.CreateObject("WScript.Shell")
WSHShell.Regwrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\<ProductCode>\SystemComponent","1","REG_DWORD"
Dim WSHShell,strRegKey
Set WSHShell = WScript.CreateObject("WScript.Shell")
WSHShell.Regwrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\<ProductCode>\SystemComponent","1","REG_DWORD"
Check Free Disk Space - VBScript
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_LogicalDisk WHERE DeviceID = 'C:'",,48)
For Each objItem in colItems
Bytes = objItem.FreeSpace
If Bytes >= 1073741824 Then
SetBytes = Round(FormatNumber(Bytes / 1024 / 1024 / 1024, 2), 0) & " GB"
ElseIf Bytes >= 1048576 Then
SetBytes = Round(FormatNumber(Bytes / 1024 / 1024, 2), 0) & " MB"
ElseIf Bytes >= 1024 Then
SetBytes = Round(FormatNumber(Bytes / 1024, 2), 0) & " KB"
ElseIf Bytes < 1024 Then
SetBytes = Bytes & " Bytes"
Else
SetBytes = "0 Bytes"
End If
Wscript.Echo "OUTPUT = " & SetBytes
Next
SendKeys VBscript Example
On Error Resume Next
Set WshShell = CreateObject("WScript.Shell")
strWindowNameEN = "PictureTaker Personal Edition"
successEN = False
Do
successEN = WshShell.AppActivate(strWindowNameEN)
Loop Until (successEN = True)
If (successEN) Then
WshShell.AppActivate strWindowNameEN
End IF
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{ENTER}"
Thursday, 14 June 2012
Install MSI using WiseScript
Following script installs sample.msi located in the location where wisescript EXE is located.
Declaration of Variables
-> Set Variable MSI to "Path of MSI"
-> Set Variable MSIEXEC to "path of msiexec.exe file present in system32 folder"
then execute MSI installation command
-> Execute Program, provide the executable to run along with command line arguments
-> Ouput WiseScriptEXE needs Sample.msi to be present beside to perform MSI installation
Declaration of Variables
-> Set Variable MSI to "Path of MSI"
-> Set Variable MSIEXEC to "path of msiexec.exe file present in system32 folder"
then execute MSI installation command
-> Execute Program, provide the executable to run along with command line arguments
-> Ouput WiseScriptEXE needs Sample.msi to be present beside to perform MSI installation
Subscribe to:
Posts (Atom)