tag:blogger.com,1999:blog-34965196669080159662024-03-08T14:35:09.781-08:00Scripting (VB)Scripts mostly in VB for automation.Fuznikhttp://www.blogger.com/profile/01436708169474029207noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-3496519666908015966.post-40723604485093848252012-11-14T19:53:00.001-08:002012-12-02T19:15:39.139-08:00File & registry permissions with subinaclSample 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): <br />
<br />
Sub SetPermissions(strTarget, strUser, strAccess)<br />
'On Error Resume Next<br />
Dim wshShell<br />
Set WshShell = WScript.CreateObject("WScript.Shell")<br />
wshShell.Run "subinacl.exe /subdirectories=directoriesonly " & """" & strTarget & """" & " /grant=" & """" & strUser & """" & "=" & strAccess, 0, True<br />
wshShell.Run "subinacl.exe /subdirectories=directoriesonly " & """" & strTarget & "\*.*" & """" & " /grant=" & """" & strUser & """" & "=" & strAccess, 0, True<br />
wshShell.Run "subinacl.exe /subdirectories=filesonly " & """" & strTarget & "\*.*" & """" & " /grant=" & """" & StrUser & """" & "=" & strAccess, 0, True<br />
End Sub<br />
<br />
'Ignore the following lines more as reference to myself for when I get around to doing it for registry keys<br />
wshShell.Run "subinacl.exe /keyreg " & """" & "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Bloomberg L.P." & """" & " /grant=" & """" & "Authenticated Users" & """" & "=" & "F", 0, True<br />
wshShell.Run "subinacl.exe /keyreg " & """" & "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Bloomberg L.P." & """" & " /grant=" & """" & "Authenticated Users" & """" & "=" & "F", 0, True<br />
<br />Fuznikhttp://www.blogger.com/profile/01436708169474029207noreply@blogger.com0tag:blogger.com,1999:blog-3496519666908015966.post-2033672637907033692012-11-14T14:50:00.002-08:002012-12-02T19:14:50.174-08:00Clear IE Cache FYI<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 14px/17px Verdana; letter-spacing: normal; margin: 20px 0px; orphans: 2; padding: 0px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
Was looking for a way of clearing out IE cache as a prerequisite to the installation to a piece of software, ended up not needing to do this, but I am sure I will need this again at some stage, should be easy enough to just execute this through a script. <br />
<br />
Found here:</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 14px/17px Verdana; letter-spacing: normal; margin: 20px 0px; orphans: 2; padding: 0px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<a href="http://www.howtogeek.com/howto/windows/clear-ie7-browsing-history-from-the-command-line/">http://www.howtogeek.com/howto/windows/clear-ie7-browsing-history-from-the-command-line/</a></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 14px/17px Verdana; letter-spacing: normal; margin: 20px 0px; orphans: 2; padding: 0px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
Appears to work on IE9.</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 14px/17px Verdana; letter-spacing: normal; margin: 20px 0px; orphans: 2; padding: 0px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<b style="font-style: normal; font-weight: bold;">Temporary Internet Files</b></div>
<blockquote style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f9f9f9; border: 1px dashed rgb(47, 111, 171); clear: both; color: black; font-size-adjust: none; font-stretch: normal; font: 15px/1.1em monospace; letter-spacing: normal; margin: 0px; orphans: 2; padding: 4px 4px 4px 6px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<div style="color: #333333; font-family: Verdana; font-size: 14px; line-height: 17px; margin: 0px 0px 10px; padding: 0px;">
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8</div>
</blockquote>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 14px/17px Verdana; letter-spacing: normal; margin: 20px 0px; orphans: 2; padding: 0px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<b style="font-style: normal; font-weight: bold;">Cookies</b></div>
<blockquote style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f9f9f9; border: 1px dashed rgb(47, 111, 171); clear: both; color: black; font-size-adjust: none; font-stretch: normal; font: 15px/1.1em monospace; letter-spacing: normal; margin: 0px; orphans: 2; padding: 4px 4px 4px 6px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<div style="color: #333333; font-family: Verdana; font-size: 14px; line-height: 17px; margin: 0px 0px 10px; padding: 0px;">
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2</div>
</blockquote>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 14px/17px Verdana; letter-spacing: normal; margin: 20px 0px; orphans: 2; padding: 0px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<b style="font-style: normal; font-weight: bold;">History</b></div>
<blockquote style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f9f9f9; border: 1px dashed rgb(47, 111, 171); clear: both; color: black; font-size-adjust: none; font-stretch: normal; font: 15px/1.1em monospace; letter-spacing: normal; margin: 0px; orphans: 2; padding: 4px 4px 4px 6px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<div style="color: #333333; font-family: Verdana; font-size: 14px; line-height: 17px; margin: 0px 0px 10px; padding: 0px;">
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1</div>
</blockquote>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 14px/17px Verdana; letter-spacing: normal; margin: 20px 0px; orphans: 2; padding: 0px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<b style="font-style: normal; font-weight: bold;">Form Data</b></div>
<blockquote style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f9f9f9; border: 1px dashed rgb(47, 111, 171); clear: both; color: black; font-size-adjust: none; font-stretch: normal; font: 15px/1.1em monospace; letter-spacing: normal; margin: 0px; orphans: 2; padding: 4px 4px 4px 6px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<div style="color: #333333; font-family: Verdana; font-size: 14px; line-height: 17px; margin: 0px 0px 10px; padding: 0px;">
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16</div>
</blockquote>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 14px/17px Verdana; letter-spacing: normal; margin: 20px 0px; orphans: 2; padding: 0px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<b style="font-style: normal; font-weight: bold;">Passwords</b></div>
<blockquote style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f9f9f9; border: 1px dashed rgb(47, 111, 171); clear: both; color: black; font-size-adjust: none; font-stretch: normal; font: 15px/1.1em monospace; letter-spacing: normal; margin: 0px; orphans: 2; padding: 4px 4px 4px 6px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<div style="color: #333333; font-family: Verdana; font-size: 14px; line-height: 17px; margin: 0px 0px 10px; padding: 0px;">
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32</div>
</blockquote>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 14px/17px Verdana; letter-spacing: normal; margin: 20px 0px; orphans: 2; padding: 0px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<b style="font-style: normal; font-weight: bold;">Delete All</b></div>
<blockquote style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f9f9f9; border: 1px dashed rgb(47, 111, 171); clear: both; color: black; font-size-adjust: none; font-stretch: normal; font: 15px/1.1em monospace; letter-spacing: normal; margin: 0px; orphans: 2; padding: 4px 4px 4px 6px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<div style="color: #333333; font-family: Verdana; font-size: 14px; line-height: 17px; margin: 0px 0px 10px; padding: 0px;">
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255</div>
</blockquote>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 14px/17px Verdana; letter-spacing: normal; margin: 20px 0px; orphans: 2; padding: 0px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<b style="font-style: normal; font-weight: bold;">Delete All – “Also delete files and settings stored by add-ons”</b></div>
<blockquote style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #f9f9f9; border: 1px dashed rgb(47, 111, 171); clear: both; color: black; font-size-adjust: none; font-stretch: normal; font: 15px/1.1em monospace; letter-spacing: normal; margin: 0px; orphans: 2; padding: 4px 4px 4px 6px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<div style="color: #333333; font-family: Verdana; font-size: 14px; line-height: 17px; margin: 0px 0px 10px; padding: 0px;">
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351</div>
</blockquote>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 14px/17px Verdana; letter-spacing: normal; margin: 20px 0px; orphans: 2; padding: 0px; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
These commands should work in Internet Explorer 7 on XP or on Windows Vista.</div>
Fuznikhttp://www.blogger.com/profile/01436708169474029207noreply@blogger.com0tag:blogger.com,1999:blog-3496519666908015966.post-4794252710939120012012-10-17T16:59:00.001-07:002012-11-11T15:34:40.154-08:00Install MSI, MST & MSP all at onceReason 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.<br />
<br />
On Error Resume Next<br />
Dim wshShell, strMSI, strTransform, strPatch, objFSO, strLogPath<br />
Set wshShell = WScript.CreateObject("WScript.Shell")<br />
Set objFSO = CreateObject("Scripting.FileSystemObject")<br />
strMSI = "YourMSI.msi"<br />
strTransform = "YourMST.mst"<br />
strPatch = objFSO.GetAbsolutePathName("") & "\" & "YourPatch.msp"<br />
strLog = wshShell.ExpandEnvironmentStrings("%windir%") & "\MSILogs\" & Left(strMSI, InStr(strMSI,".msi")) & "log"<br />
wshShell.Run "msiexec /i " & """" & strMSI & """" & " TRANSFORMS=" & """" & strTransform & """" & " PATCH=" & """" & strPatch & """" & " /qb! /norestart /l*v " & strLog, 0, True <br />
Set wshShell = Nothing<br />
Set objFSO = Nothing<br />
If err.Number = 0 Then<br />
wScript.Quit 0<br />
Else<br />
wScript.Quit err.Number<br />
End If<br />
<br />
<br />
Obtained from:<br />
<a href="http://www.visualbasicscript.com/how-to-get-working-drive-and-directory-m1248.aspx">http://www.visualbasicscript.com/how-to-get-working-drive-and-directory-m1248.aspx</a><br />
<br />
<span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #efefef; color: black; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 12px/24px Verdana; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">Set fso = CreateObject("</span><span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #efefef; color: black; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 12px/24px Verdana; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">Scripting</span><span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #efefef; color: black; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 12px/24px Verdana; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">.FileSystemObject")<span class="Apple-converted-space"> </span></span><br />
<span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #efefef; color: black; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 12px/24px Verdana; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">GetAbsolutePath = fso.GetAbsolutePathName("Wscript.ScriptName") 'Returns path and file name of file specified<span class="Apple-converted-space"> </span></span><br />
<span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #efefef; color: black; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 12px/24px Verdana; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">GetTheParent = fso.GetParentFolderName("Wscript.ScriptName")'Returns the parentfolder of the Path/File specified<span class="Apple-converted-space"> </span></span><br />
<span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #efefef; color: black; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 12px/24px Verdana; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">GetTheBase = fso.GetBaseName("Wscript.ScriptName")'Returns<span class="Apple-converted-space"> </span></span><span class="IL_AD" id="IL_AD3" style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-attachment: scroll !important; background-color: #efefef; background-image: none !important; background-position: 0% 50%; background-repeat: repeat repeat !important; border-bottom-color: rgb(0, 153, 0) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; color: #b00000; cursor: pointer !important; display: inline !important; float: none !important; font-size-adjust: none; font-stretch: normal; font: 12px/24px Verdana; letter-spacing: normal; orphans: 2; padding: 0px 0px 1px !important; position: static; text-decoration: underline !important; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">the file</span><span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #efefef; color: black; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 12px/24px Verdana; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"><span class="Apple-converted-space"> </span>name minus file extension<span class="Apple-converted-space"> </span></span><br />
<span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #efefef; color: black; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 12px/24px Verdana; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">GetTheScriptFullName = WScript.ScriptFullName'Returns path of<span class="Apple-converted-space"> </span></span><span class="IL_AD" id="IL_AD2" style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-attachment: scroll !important; background-color: #efefef; background-image: none !important; background-position: 0% 50%; background-repeat: repeat repeat !important; border-bottom-color: rgb(0, 153, 0) !important; border-bottom-style: solid !important; border-bottom-width: 1px !important; color: #b00000; cursor: pointer !important; display: inline !important; float: none !important; font-size-adjust: none; font-stretch: normal; font: 12px/24px Verdana; letter-spacing: normal; orphans: 2; padding: 0px 0px 1px !important; position: static; text-decoration: underline !important; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">the script</span><span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #efefef; color: black; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 12px/24px Verdana; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"><span class="Apple-converted-space"> </span>being called.<span class="Apple-converted-space"> </span></span><br />
<span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #efefef; color: black; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 12px/24px Verdana; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">GetTheScriptName = Wscript.ScriptName'Returns the name of<span class="Apple-converted-space"> </span></span><span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #efefef; color: black; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 12px/24px Verdana; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">the script</span><span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #efefef; color: black; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 12px/24px Verdana; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"><span class="Apple-converted-space"> </span></span><br />
<br />
<span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #efefef; color: black; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 12px/24px Verdana; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">msgbox "Using AbsolutePath: " & GetAbsolutePath & vbcr _<span class="Apple-converted-space"> </span></span><br />
<span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #efefef; color: black; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 12px/24px Verdana; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">& "Using GetParentFolderName: " & GetTheParent & vbcr _<span class="Apple-converted-space"> </span></span><br />
<span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #efefef; color: black; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 12px/24px Verdana; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">& "Using GetBaseName: " & GetTheBase & vbcr _<span class="Apple-converted-space"> </span></span><br />
<span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #efefef; color: black; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 12px/24px Verdana; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">& "Using ScriptFullName: " & GetTheScriptFullName & vbcr _<span class="Apple-converted-space"> </span></span><br />
<span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #efefef; color: black; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 12px/24px Verdana; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">& "Using ScriptName: " & GetTheScriptName</span><br />
<span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #efefef; color: black; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 12px/24px Verdana; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"></span><br />
<span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #efefef; color: black; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 12px/24px Verdana; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">Or if you use batch files:</span><br />
<span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #efefef; color: black; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 12px/24px Verdana; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"><span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: black; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 14px/18px Arial, "Liberation Sans", "DejaVu Sans", sans-serif; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">Echo %~f0</span></span><br />
<span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #efefef; color: black; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 12px/24px Verdana; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"><a href="http://stackoverflow.com/questions/1421286/getting-a-batch-files-full-path"><span style="font-family: Times New Roman; font-size: small;">http://stackoverflow.com/questions/1421286/getting-a-batch-files-full-path</span></a></span><br />
<span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #efefef; color: black; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 12px/24px Verdana; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"></span><br />
<span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #efefef; color: black; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 12px/24px Verdana; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"></span><br />
<span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #efefef; color: black; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 12px/24px Verdana; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"></span><br />
<span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #efefef; color: black; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 12px/24px Verdana; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"></span><br />Fuznikhttp://www.blogger.com/profile/01436708169474029207noreply@blogger.com0tag:blogger.com,1999:blog-3496519666908015966.post-49572000855094945012012-10-15T18:09:00.002-07:002012-10-15T20:08:27.163-07:00Microsoft Hotfix/KB CheckCreated the below for a requirement installed check in CM 2012, based on the script here:<br />
<a href="http://desktopdeploy.wordpress.com/2010/04/26/vbscript-list-ms-hotfixes-installed/">http://desktopdeploy.wordpress.com/2010/04/26/vbscript-list-ms-hotfixes-installed/</a><br />
<br />
Option Explicit<br />
On Error Resume Next<br />
Dim strComputer, objWMIService, colQuickFixes, objQuickFix, HFInstalled, HFID<br />
strComputer = "."<br />
HFID = "KB958830"<br />
HFInstalled = False<br />
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")<br />
Set colQuickFixes = objWMIService.ExecQuery ("Select * from Win32_QuickFixEngineering")<br />
For Each objQuickFix in colQuickFixes<br />
If objQuickFix.HotFixID = HFID Then<br />
HFInstalled = True<br />
Exit For<br />
End If<br />
Next<br />
If HFInstalled = True Then<br />
wScript.Quit 0<br />
Else<br />
wScript.Quit 1<br />
End IfFuznikhttp://www.blogger.com/profile/01436708169474029207noreply@blogger.com0tag:blogger.com,1999:blog-3496519666908015966.post-36550777139378631302012-09-16T22:30:00.001-07:002012-09-16T22:31:48.983-07:00Scripts and exit codesColleague of mine asked me to write a small blurb on using exit codes when using scripts to wrap packages for deployment. This is a very simplistic overview. This is from an SMS/SCCM perspective, though this probably applies to other deployment tools (maybe).<br />
<br />
Typically if you are just using some sort of script execute say an msi it might be in the following format:<br />
<br />
On Error Resume Next<br />
objFSO.dosomestuff<br />
wshShell.Run "SomeApplication.msi" /qb /norestart<br />
wScript.quit<br />
<br />
This for the most part is fine, as long as you do not run into any problems with the deployment. The above will effectively always exit with a success code, so when you are looking through the deployment reports from SCCM even if the application failed to install on all of the machines you are going to get 100% success rate as the script it self completed successfully.<br />
<br />
A very basic way around this would be to have something like this:<br />
<br />
If err.number <> 0 Then<br />
wScript.quit 1<br />
Else<br />
wScript.quit 0<br />
End If<br />
<br />
Where 1 is a generic error code and 0 is a generic success code. So if there is an issue with the execution of that msi then you will at least get an idea that there is a problem.<br />
<br />
SCCM has a few exit codes that you could use in order to manipulate the advertisement behaviour:<br />
<br />
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: black; font-size-adjust: none; font-stretch: normal; font: 13px/normal Tahoma, Arial, Helvetica; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
Success:<br />
0 </div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: black; font-size-adjust: none; font-stretch: normal; font: 13px/normal Tahoma, Arial, Helvetica; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
Reboot:<br />
1604<br />
1641<br />
3010<br />
3011 </div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: black; font-size-adjust: none; font-stretch: normal; font: 13px/normal Tahoma, Arial, Helvetica; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
Retry*:<br />
4<br />
5<br />
8<br />
13<br />
14<br />
39<br />
51<br />
53<br />
54<br />
55<br />
59<br />
64<br />
65<br />
67<br />
70<br />
71<br />
85<br />
86<br />
87<br />
112<br />
128<br />
170<br />
267<br />
999<br />
1003<br />
1203<br />
1219<br />
1220<br />
1222<br />
1231<br />
1232<br />
1238<br />
1265<br />
1311<br />
1323<br />
1326<br />
1330<br />
1618<br />
1622<br />
2250</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: black; font-size-adjust: none; font-stretch: normal; font: 13px/normal Tahoma, Arial, Helvetica; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
*) A retry exit code will force SMS/SCCM to rerun the advertisement after a timeout of 10 minutes.</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: black; font-size-adjust: none; font-stretch: normal; font: 13px/normal Tahoma, Arial, Helvetica; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: black; font-size-adjust: none; font-stretch: normal; font: 13px/normal Tahoma, Arial, Helvetica; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
The above exit codes are from here:</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: black; font-size-adjust: none; font-stretch: normal; font: 13px/normal Tahoma, Arial, Helvetica; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<a href="http://myitforum.com/cs2/blogs/rzander/archive/2009/02/25/program-exit-codes.aspx">http://myitforum.com/cs2/blogs/rzander/archive/2009/02/25/program-exit-codes.aspx</a></div>
Fuznikhttp://www.blogger.com/profile/01436708169474029207noreply@blogger.com0tag:blogger.com,1999:blog-3496519666908015966.post-47584265743091794372012-09-13T19:43:00.000-07:002013-02-11T21:09:07.223-08:00Ping script (VBS)<br />
<span style="background-color: white; color: #373737; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; line-height: 24px;">Will ping list of machines and write results to log file, will also attempt to move old log files to an archive folder.</span>
You need to create a text file called "hosts.txt" and paste in the machine names that you wish to ping.<br />
<br />
Option Explicit<br />
'On Error Resume Next<br />
<br />
Dim objFSO, objFile, Hostname, varHostsFileName, varLogFileName, varArchFld<br />
Const ForReading = 1, ForWriting = 2, ForAppending = 8<br />
Set objFSO = CreateObject("Scripting.FileSystemObject")<br />
<br />
varHostsFileName = "Hosts.txt"<br />
varLogFileName = "Ping" & Hour(Time) & Minute(Time) & Second(Time)<br />
varArchFld = "Archive\" & Year(Date) & Month(Date) & Day(Date)<br />
<br />
Archive<br />
<br />
Set objFile = objFSO.OpenTextFile(varHostsFileName, ForReading)<br />
Do Until objFile.AtEndOfStream<br />
HostName = objFile.ReadLine()<br />
If Ping(HostName) = "Online" Then<br />
LogFile Hostname & vbTab & "Online", varLogFileName<br />
Else<br />
LogFile Hostname & vbTab & "Offline", varLogFileName<br />
End If<br />
Loop<br />
<br />
objFile.Close<br />
<br />
wScript.Quit<br />
<br />
'Subs & Functions<br />
Function Ping(HostName)<br />
'On Error Resume Next<br />
Dim colPingResults, objPingResult, strQuery<br />
strQuery = "SELECT * FROM Win32_PingStatus WHERE Address = '" & HostName & "'"<br />
Set colPingResults = GetObject("winmgmts://./root/cimv2").ExecQuery(strQuery)<br />
For Each objPingResult In colPingResults<br />
If Not IsObject(objPingResult) Then<br />
Ping = "Offline"<br />
ElseIf objPingResult.StatusCode = 0 Then<br />
Ping = "Online"<br />
Else<br />
Ping = "Offline"<br />
End If<br />
Next<br />
Set colPingResults = Nothing<br />
End Function<br />
<br />
Sub LogFile(strInput, varLogFileName)<br />
'On Error Resume Next<br />
Dim objFSO, LogFile<br />
Const ForReading = 1, ForWriting = 2, ForAppending = 8<br />
Set objFSO = CreateObject("Scripting.FileSystemObject")<br />
Set LogFile = objFSO.OpenTextFile(varLogFileName & ".log", ForAppending, True)<br />
LogFile.WriteLine(FormatDateTime(Date, 2) & vbTab & FormatDateTime(Time, 4) & ":" & Second(Time) & vbTab & strInput)<br />
LogFile.Close<br />
End Sub<br />
<br />
<br />
Sub CreateFld(Fld)<br />
'On Error Resume Next<br />
Dim objFSO<br />
Set objFSO = CreateObject("Scripting.FileSystemObject")<br />
If Fld <> "" Then<br />
If Not objFSO.FolderExists(objFSO.GetParentFolderName(Fld)) Then<br />
Call CreateFld(objFSO.GetParentFolderName(Fld))<br />
End If<br />
objFSO.CreateFolder(Fld) & "\"<br />
End If<br />
End Sub<br />
<br />
<br />
Sub Archive<br />
On Error Resume Next<br />
Dim objFSO<br />
Set objFSO = CreateObject("Scripting.FileSystemObject")<br />
CreateFld(varArchFld)<br />
objFSO.MoveFile "*.log", varArchFld & "\"<br />
End SubFuznikhttp://www.blogger.com/profile/01436708169474029207noreply@blogger.com0tag:blogger.com,1999:blog-3496519666908015966.post-81349564492902818942012-09-13T19:42:00.000-07:002013-12-09T14:21:23.610-08:00Functions & Sub Routines'Create target folder and all subfolders if they do not exist.<br />
Sub CreateFld(Fld)<br />
'On Error Resume Next<br />
Dim objFSO<br />
Set objFSO = CreateObject("Scripting.FileSystemObject")<br />
If Fld <> "" Then<br />
If Not objFSO.FolderExists(objFSO.GetParentFolderName(Fld)) Then<br />
Call CreateFld(objFSO.GetParentFolderName(Fld))<br />
End If<br />
If Not objFSO.FolderExists(Fld) Then<br /> objFSO.CreateFolder(Fld) & "\"<br /> End If<br />
End If<br />
End Sub<br />
<br />
'Ping machine returns value of "Offline" or "Online"<br />
Function Ping(HostName)<br />
'On Error Resume Next<br />
Dim colPingResults, objPingResult, strQuery<br />
strQuery = "SELECT * FROM Win32_PingStatus WHERE Address = '" & HostName & "'"<br />
Set colPingResults = GetObject("winmgmts://./root/cimv2").ExecQuery(strQuery)<br />
For Each objPingResult In colPingResults<br />
If Not IsObject(objPingResult) Then<br />
Ping = "Offline"<br />
ElseIf objPingResult.StatusCode = 0 Then<br />
Ping = "Online"<br />
Else<br />
Ping = "Offline"<br />
End If<br />
Next<br />
Set colPingResults = Nothing<br />
End Function<br />
<br />
'Creates log and writes to log given input and log name<br />
Sub LogFile(strInput, varLogFileName)<br />
'On Error Resume Next<br />
Dim objFSO, LogFile<br />
Const ForReading = 1, ForWriting = 2, ForAppending = 8<br />
Set objFSO = CreateObject("Scripting.FileSystemObject")<br />
Set LogFile = objFSO.OpenTextFile(varLogFileName & ".log", ForAppending, True)<br />
LogFile.WriteLine(FormatDateTime(Date, 2) & vbTab & FormatDateTime(Time, 4) & ":" & Second(Time) & vbTab & strInput)<br />
LogFile.Close<br />
End Sub<br />
<br />
'Captures the output of a dos command and returns it in a string found here:<br />
<a href="http://www.visualbasicscript.com/tm.aspx?high=&m=42892&mpage=1#42892">http://www.visualbasicscript.com/tm.aspx?high=&m=42892&mpage=1#42892</a><br />
wscript.echo fShellRun("%comspec% /c dir c:\")<br />
<br />
Function fShellRun(sCommandStringToExecute)<br />
' This function will accept a string as a DOS command to execute.<br />
' It will then execute the command in a shell, and capture the output into a file.<br />
' That file is then read in and its contents are returned as the value the function returns.<br />
Dim oShellObject, oFileSystemObject, sShellRndTmpFile<br />
Dim oShellOutputFileToRead, iErr<br />
Set oShellObject = CreateObject("Wscript.Shell")<br />
Set oFileSystemObject = CreateObject("Scripting.FileSystemObject")<br />
sShellRndTmpFile = oShellObject.ExpandEnvironmentStrings("%temp%") & oFileSystemObject.GetTempName<br />
On Error Resume Next <br />
oShellObject.Run sCommandStringToExecute & " > " & sShellRndTmpFile, 0, True<br />
iErr = Err.Number<br />
On Error GoTo 0<br />
If iErr <> 0 Then <br />
fShellRun = ""<br />
Exit Function <br />
End If <br />
fShellRun = oFileSystemObject.OpenTextFile(sShellRndTmpFile,1).ReadAll<br />
oFileSystemObject.DeleteFile sShellRndTmpFile, True <br />
End Function<br />
<br />
'Returns chassis type, useful for identifying notebooks and workstations slightly tweaked from here:<br />
<a href="http://blogs.technet.com/b/heyscriptingguy/archive/2004/09/21/how-can-i-determine-if-a-computer-is-a-laptop-or-a-desktop-machine.aspx">http://blogs.technet.com/b/heyscriptingguy/archive/2004/09/21/how-can-i-determine-if-a-computer-is-a-laptop-or-a-desktop-machine.aspx</a><br />
<br />
Function Chassis<br />
'On Error Resume Next<br />
Dim strComputer, objWMIService, colChassis, objChassis<br />
strComputer = "."<br />
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")<br />
Set colChassis = objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")<br />
For Each objChassis in colChassis<br />
For Each strChassisType in objChassis.ChassisTypes<br />
Select Case strChassisType<br />
Case 1<br />
Chassis = "Other"<br />
Case 2<br />
Chassis = "Unknown"<br />
Case 3<br />
Chassis = "Desktop"<br />
Case 4<br />
Chassis = "Low Profile Desktop"<br />
Case 5<br />
Chassis = "Pizza Box"<br />
Case 6<br />
Chassis = "Mini Tower"<br />
Case 7<br />
Chassis = "Tower"<br />
Case 8<br />
Chassis = "Portable"<br />
Case 9<br />
Chassis = "Laptop"<br />
Case 10<br />
Chassis = "Notebook"<br />
Case 11<br />
Chassis = "Handheld"<br />
Case 12<br />
Chassis = "Docking Station"<br />
Case 13<br />
Chassis = "All-in-One"<br />
Case 14<br />
Chassis = "Sub-Notebook"<br />
Case 15<br />
Chassis = "Space Saving"<br />
Case 16<br />
Chassis = "Lunch Box"<br />
Case 17<br />
Chassis = "Main System Chassis"<br />
Case 18<br />
Chassis = "Expansion Chassis"<br />
Case 19<br />
Chassis = "Sub-Chassis"<br />
Case 20<br />
Chassis = "Bus Expansion Chassis"<br />
Case 21<br />
Chassis = "Peripheral Chassis"<br />
Case 22<br />
Chassis = "Storage Chassis"<br />
Case 23<br />
Chassis = "Rack Mount Chassis"<br />
Case 24<br />
Chassis = "Sealed-Case PC"<br />
Case Else<br />
Chassis = "Unknown"<br />
End Select<br />
Next<br />
Next<br />
End Function<br />
<br />
'Check for existence of reg value and returns value of true or false<br />
<br />
Function RegValueExist(strRegHive, strKeyPath, strValueName)<br />
On Error Resume Next<br />
Dim strComputer, objRegistry, strValue<br />
Const HKEY_CLASSES_ROOT = &H80000000<br />
Const HKEY_CURRENT_USER = &H80000001<br />
Const HKEY_LOCAL_MACHINE = &H80000002<br />
Const HKEY_USERS = &H80000003<br />
Const HKEY_CURRENT_CONFIG = &H80000005<br />
strComputer = "."<br />
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")<br />
Select Case strRegHive<br />
Case "HKCR"<br />
objRegistry.GetStringValue HKEY_CLASSES_ROOT, strKeyPath,strValueName,strValue<br />
Case "HKCU"<br />
objRegistry.GetStringValue HKEY_CURRENT_USER, strKeyPath,strValueName,strValue<br />
Case "HKLM"<br />
objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath,strValueName,strValue<br />
Case "HKU"<br />
objRegistry.GetStringValue HKEY_USERS, strKeyPath,strValueName,strValue<br />
Case "HKCC"<br />
objRegistry.GetStringValue HKEY_CURRENT_CONFIG, strKeyPath,strValueName,strValue<br />
End Select<br />
If IsNull(strValue) Then<br />
RegValueExist = False<br />
Else<br />
RegValueExist = True<br />
End If<br />
End Function<br />
<br />
Usage:<br />
RegValueExist ("RegHive", "Software\Test", "RegValueName")<br />
<br />
'Check for existence of reg key and returns value of true or false<br />
<br />
Function RegKeyExists(strHive, strKeyPath)<br />
On Error Resume Next<br />
Dim strComputer, objRegistry, arrSubKeys<br />
Const HKCR = &H80000000 'HKEY_CLASSES_ROOT<br />
Const HKCU = &H80000001 'HKEY_CURRENT_USER<br />
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE<br />
Const HKUS = &H80000003 'HKEY_USERS<br />
Const HKCC = &H80000005 'HKEY_CURRENT_CONFIG<br />
strComputer = "."<br />
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")<br />
RegKeyExists = False<br />
Select Case strHive<br />
Case "HKCR"<br />
If objRegistry.EnumKey (HKCR, strKeyPath) = 0 Then<br />
RegKeyExists = True<br />
End If<br />
Case "HKCU"<br />
If objRegistry.EnumKey (HKCU, strKeyPath) = 0 Then<br />
RegKeyExists = True<br />
End If<br />
Case "HKLM"<br />
If objRegistry.EnumKey (HKLM, strKeyPath) = 0 Then<br />
RegKeyExists = True<br />
End If<br />
Case "HKU"<br />
If objRegistry.EnumKey (HKU, strKeyPath) = 0 Then<br />
RegKeyExists = True<br />
End If<br />
Case "HKCC"<br />
If objRegistry.EnumKey (HKCC, strKeyPath) = 0 Then<br />
RegKeyExists = True<br />
End If<br />
End Select<br />
End Function<br />
<br />
Usage:<br />
RegKeyExists("RegHive","RegKeyPath")<br />
<br />
'Created this for a package that included a licence key that I was unable to create a response file for. Sometimes you have windows that only appear if certain conditions are met, so to account for this i have included a case statement to allow for this<br />
<br />
Function ActiveWindow(strWindow, intWaitTime)<br />
On Error Resume Next<br />
Dim wshShell, intFailSafe<br />
intFailSafe = 0<br />
Set wshShell = WScript.CreateObject("WScript.Shell")<br />
Select Case strWindow<br />
Case "Your application window name"<br />
Do Until wshShell.AppActivate(strWindow) = True Or intFailSafe > intWaitTime<br />
wScript.Sleep 5000<br />
intFailSafe = intFailSafe + 1<br />
Loop<br />
If wshShell.AppActivate(strWindow) = True Then<br />
wshShell.SendKeys "%(y)"<br />
Exit Function<br />
End If<br />
Exit Function<br />
Case Else<br />
Do Until wshShell.AppActivate(strWindow) = True Or intFailSafe > intWaitTime<br />
wScript.Sleep 5000<br />
intFailSafe = intFailSafe + 1<br />
Loop<br />
If intFailSafe > intWaitTime Then<br />
wscript.quit 1<br />
End If<br />
End Select<br />
End Function<br />
<br />
Usage:<br />
strWindow = "Your application window name"<br />
inWaitTime = "Total time you want it to wait for this window before moving on, it is currently in increments of 5 seconds so if you set 12 it will wait for 1 minute"<br />
<br />
ActiveWindow(strWindow, intWaitTime)Fuznikhttp://www.blogger.com/profile/01436708169474029207noreply@blogger.com0