Sample script that makes use of subinacl to modfiy permissions for files and/or registry, in this case I have done a function for alter file permissions, when I have to do somehthing for the registry I will add a new function or modify this one (you will need to obtain a copy of subinacl.exe from Microsoft which I believe is free):
Sub SetPermissions(strTarget, strUser, strAccess)
'On Error Resume Next
Dim wshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
wshShell.Run "subinacl.exe /subdirectories=directoriesonly " & """" & strTarget & """" & " /grant=" & """" & strUser & """" & "=" & strAccess, 0, True
wshShell.Run "subinacl.exe /subdirectories=directoriesonly " & """" & strTarget & "\*.*" & """" & " /grant=" & """" & strUser & """" & "=" & strAccess, 0, True
wshShell.Run "subinacl.exe /subdirectories=filesonly " & """" & strTarget & "\*.*" & """" & " /grant=" & """" & StrUser & """" & "=" & strAccess, 0, True
End Sub
'Ignore the following lines more as reference to myself for when I get around to doing it for registry keys
wshShell.Run "subinacl.exe /keyreg " & """" & "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Bloomberg L.P." & """" & " /grant=" & """" & "Authenticated Users" & """" & "=" & "F", 0, True
wshShell.Run "subinacl.exe /keyreg " & """" & "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Bloomberg L.P." & """" & " /grant=" & """" & "Authenticated Users" & """" & "=" & "F", 0, True
Showing posts with label vbs. Show all posts
Showing posts with label vbs. Show all posts
Wednesday, 14 November 2012
Wednesday, 17 October 2012
Install MSI, MST & MSP all at once
Reason for this post is that if you attempt to use the PATCH property it requires that you provide the full path to the patch, there are other methods for obtaining this which is at the bottom of this post. If you are wondering about the strLog I got a little bored, I am sure there is a more efficient way of creating the log file name.
On Error Resume Next
Dim wshShell, strMSI, strTransform, strPatch, objFSO, strLogPath
Set wshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strMSI = "YourMSI.msi"
strTransform = "YourMST.mst"
strPatch = objFSO.GetAbsolutePathName("") & "\" & "YourPatch.msp"
strLog = wshShell.ExpandEnvironmentStrings("%windir%") & "\MSILogs\" & Left(strMSI, InStr(strMSI,".msi")) & "log"
wshShell.Run "msiexec /i " & """" & strMSI & """" & " TRANSFORMS=" & """" & strTransform & """" & " PATCH=" & """" & strPatch & """" & " /qb! /norestart /l*v " & strLog, 0, True
Set wshShell = Nothing
Set objFSO = Nothing
If err.Number = 0 Then
wScript.Quit 0
Else
wScript.Quit err.Number
End If
Obtained from:
http://www.visualbasicscript.com/how-to-get-working-drive-and-directory-m1248.aspx
Set fso = CreateObject("Scripting.FileSystemObject")
GetAbsolutePath = fso.GetAbsolutePathName("Wscript.ScriptName") 'Returns path and file name of file specified
GetTheParent = fso.GetParentFolderName("Wscript.ScriptName")'Returns the parentfolder of the Path/File specified
GetTheBase = fso.GetBaseName("Wscript.ScriptName")'Returns the file name minus file extension
GetTheScriptFullName = WScript.ScriptFullName'Returns path of the script being called.
GetTheScriptName = Wscript.ScriptName'Returns the name of the script
msgbox "Using AbsolutePath: " & GetAbsolutePath & vbcr _
& "Using GetParentFolderName: " & GetTheParent & vbcr _
& "Using GetBaseName: " & GetTheBase & vbcr _
& "Using ScriptFullName: " & GetTheScriptFullName & vbcr _
& "Using ScriptName: " & GetTheScriptName
Or if you use batch files:
Echo %~f0
http://stackoverflow.com/questions/1421286/getting-a-batch-files-full-path
On Error Resume Next
Dim wshShell, strMSI, strTransform, strPatch, objFSO, strLogPath
Set wshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strMSI = "YourMSI.msi"
strTransform = "YourMST.mst"
strPatch = objFSO.GetAbsolutePathName("") & "\" & "YourPatch.msp"
strLog = wshShell.ExpandEnvironmentStrings("%windir%") & "\MSILogs\" & Left(strMSI, InStr(strMSI,".msi")) & "log"
wshShell.Run "msiexec /i " & """" & strMSI & """" & " TRANSFORMS=" & """" & strTransform & """" & " PATCH=" & """" & strPatch & """" & " /qb! /norestart /l*v " & strLog, 0, True
Set wshShell = Nothing
Set objFSO = Nothing
If err.Number = 0 Then
wScript.Quit 0
Else
wScript.Quit err.Number
End If
Obtained from:
http://www.visualbasicscript.com/how-to-get-working-drive-and-directory-m1248.aspx
Set fso = CreateObject("Scripting.FileSystemObject")
GetAbsolutePath = fso.GetAbsolutePathName("Wscript.ScriptName") 'Returns path and file name of file specified
GetTheParent = fso.GetParentFolderName("Wscript.ScriptName")'Returns the parentfolder of the Path/File specified
GetTheBase = fso.GetBaseName("Wscript.ScriptName")'Returns the file name minus file extension
GetTheScriptFullName = WScript.ScriptFullName'Returns path of the script being called.
GetTheScriptName = Wscript.ScriptName'Returns the name of the script
msgbox "Using AbsolutePath: " & GetAbsolutePath & vbcr _
& "Using GetParentFolderName: " & GetTheParent & vbcr _
& "Using GetBaseName: " & GetTheBase & vbcr _
& "Using ScriptFullName: " & GetTheScriptFullName & vbcr _
& "Using ScriptName: " & GetTheScriptName
Or if you use batch files:
Echo %~f0
http://stackoverflow.com/questions/1421286/getting-a-batch-files-full-path
Monday, 15 October 2012
Microsoft Hotfix/KB Check
Created the below for a requirement installed check in CM 2012, based on the script here:
http://desktopdeploy.wordpress.com/2010/04/26/vbscript-list-ms-hotfixes-installed/
Option Explicit
On Error Resume Next
Dim strComputer, objWMIService, colQuickFixes, objQuickFix, HFInstalled, HFID
strComputer = "."
HFID = "KB958830"
HFInstalled = False
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colQuickFixes = objWMIService.ExecQuery ("Select * from Win32_QuickFixEngineering")
For Each objQuickFix in colQuickFixes
If objQuickFix.HotFixID = HFID Then
HFInstalled = True
Exit For
End If
Next
If HFInstalled = True Then
wScript.Quit 0
Else
wScript.Quit 1
End If
http://desktopdeploy.wordpress.com/2010/04/26/vbscript-list-ms-hotfixes-installed/
Option Explicit
On Error Resume Next
Dim strComputer, objWMIService, colQuickFixes, objQuickFix, HFInstalled, HFID
strComputer = "."
HFID = "KB958830"
HFInstalled = False
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colQuickFixes = objWMIService.ExecQuery ("Select * from Win32_QuickFixEngineering")
For Each objQuickFix in colQuickFixes
If objQuickFix.HotFixID = HFID Then
HFInstalled = True
Exit For
End If
Next
If HFInstalled = True Then
wScript.Quit 0
Else
wScript.Quit 1
End If
Thursday, 13 September 2012
Ping script (VBS)
Will ping list of machines and write results to log file, will also attempt to move old log files to an archive folder. You need to create a text file called "hosts.txt" and paste in the machine names that you wish to ping.
Option Explicit
'On Error Resume Next
Dim objFSO, objFile, Hostname, varHostsFileName, varLogFileName, varArchFld
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
varHostsFileName = "Hosts.txt"
varLogFileName = "Ping" & Hour(Time) & Minute(Time) & Second(Time)
varArchFld = "Archive\" & Year(Date) & Month(Date) & Day(Date)
Archive
Set objFile = objFSO.OpenTextFile(varHostsFileName, ForReading)
Do Until objFile.AtEndOfStream
HostName = objFile.ReadLine()
If Ping(HostName) = "Online" Then
LogFile Hostname & vbTab & "Online", varLogFileName
Else
LogFile Hostname & vbTab & "Offline", varLogFileName
End If
Loop
objFile.Close
wScript.Quit
'Subs & Functions
Function Ping(HostName)
'On Error Resume Next
Dim colPingResults, objPingResult, strQuery
strQuery = "SELECT * FROM Win32_PingStatus WHERE Address = '" & HostName & "'"
Set colPingResults = GetObject("winmgmts://./root/cimv2").ExecQuery(strQuery)
For Each objPingResult In colPingResults
If Not IsObject(objPingResult) Then
Ping = "Offline"
ElseIf objPingResult.StatusCode = 0 Then
Ping = "Online"
Else
Ping = "Offline"
End If
Next
Set colPingResults = Nothing
End Function
Sub LogFile(strInput, varLogFileName)
'On Error Resume Next
Dim objFSO, LogFile
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set LogFile = objFSO.OpenTextFile(varLogFileName & ".log", ForAppending, True)
LogFile.WriteLine(FormatDateTime(Date, 2) & vbTab & FormatDateTime(Time, 4) & ":" & Second(Time) & vbTab & strInput)
LogFile.Close
End Sub
Sub CreateFld(Fld)
'On Error Resume Next
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Fld <> "" Then
If Not objFSO.FolderExists(objFSO.GetParentFolderName(Fld)) Then
Call CreateFld(objFSO.GetParentFolderName(Fld))
End If
objFSO.CreateFolder(Fld) & "\"
End If
End Sub
Sub Archive
On Error Resume Next
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
CreateFld(varArchFld)
objFSO.MoveFile "*.log", varArchFld & "\"
End Sub
Subscribe to:
Posts (Atom)