<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bahramov's Personal Blog &#187; Scripting</title>
	<atom:link href="http://www.bahramov.com/category/windows/scripting-windows/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bahramov.com</link>
	<description>Computers, databases, networks and virtualization</description>
	<lastBuildDate>Fri, 24 Jun 2011 12:05:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Script to fix error with start up of AU and BITS (EventID 7023 and 7024)</title>
		<link>http://www.bahramov.com/2009/06/30/script-to-fix-the-error-with-start-up-of-automatic-updates-and-bits-services-eventid-7023-and-eventid-7024/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.bahramov.com/2009/06/30/script-to-fix-the-error-with-start-up-of-automatic-updates-and-bits-services-eventid-7023-and-eventid-7024/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 11:39:13 +0000</pubDate>
		<dc:creator>Zaur Bahramov</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[VB]]></category>
		<category><![CDATA[VBScript]]></category>

		<guid isPermaLink="false">http://www.bahramov.com/?p=330</guid>
		<description><![CDATA[This script detects and tries to fix the error related to start up of Automatic Updates and BITS services on network computers. Such error is related to security identifier (EventID 7023 and EventID 7024). Â This problem is usually observed on network computers after applying changes to group policies. In such cases the script will reset [...]]]></description>
			<content:encoded><![CDATA[<p>This script detects and tries to fix the error related to start up of Automatic Updates and BITS services on network computers. Such error is related to security identifier (EventID 7023 and EventID 7024). Â This problem is usually observed on network computers after applying changes to group policies. In such cases the script will reset a security identifier as per Microsoft KB 555336Â (<a href="http://support.microsoft.com/kb/555336">http://support.microsoft.com/kb/555336</a>) and start Automatic Updates and BITS.Â Can be usefull for networks where Windows Server Update Services 3.0 (WSUS) is used.</p>
<p>Script is taken from: <a href="http://forum.vingrad.ru/forum/topic-154708/view-all.html">http://forum.vingrad.ru/forum/topic-154708/view-all.html</a></p>
<p><span id="more-330"></span>
<pre class="brush: vb.net">&#039; This script detects and tries to fix the error related to start up of Automatic Updates and BITS services
&#039; on network computers. Such error is related to security identifier (EventID 7023 and EventID 7024).
&#039; This problem is usually observed on network computers after applying changes to group policies.
&#039; In such cases the script will reset a security identifier as per Microsoft KB 555336
&#039; http://support.microsoft.com/kb/555336 and start Automatic Updates and BITS.
&#039; Can be usefull for networks where Windows Server Update Services 3.0 (WSUS) is used.
&#039; Script source: http://forum.vingrad.ru/forum/topic-154708/view-all.html

&#039; Initialize variables and WMI-moniker
strComputer = &quot;.&quot;
Set objWMIService = GetObject(&quot;winmgmts:&quot; _
Â Â Â  &amp;amp; &quot;{impersonationLevel=impersonate}!\\&quot; &amp;amp; strComputer &amp;amp; &quot;\root\cimv2&quot;)
Â Â Â 
&#039; Select Automatic Updates and BITS services from the list of services
Set colListOfServices = objWMIService.ExecQuery _
Â Â Â  (&quot;Select * from Win32_Service Where Name = &#039;BITS&#039; or Name = &#039;wuauserv&#039;&quot;)
Â Â Â 
&#039; For each of selected services:
For Each objService in colListOfServices
Â Â Â  isStarted = 0
Â Â Â  &#039; Check its status. If stopped then
Â Â Â  IfÂ  objService.State = &quot;Stopped&quot; Then
Â Â Â Â  &#039; Try to start it.
Â Â Â Â  WScript.Echo (&quot;Service &quot; &amp;amp; objService.Name &amp;amp; &quot; Stopped&quot;)
Â Â Â Â  isStarted = objService.StartService()
Â 
Â Â Â Â  &#039; If when starting we get the same problem try to fix it
Â Â Â Â  &#039; (fix is provided by the Repair function)
Â Â Â Â  If objService.ExitCode &lt;&gt; 0 Then
Â Â Â Â Â Â Â Â  WScript.Echo(&quot;WARNING!!! Error occured, when try to started...&quot;)
Â Â Â Â Â Â Â Â  WScript.Echo (&quot;Try to repair...&quot; &amp;amp; objService.Name)
Â Â Â Â Â Â Â Â Â Â Â  intCode = Repair(strComputer)
Â Â Â Â Â Â Â Â Â Â Â  If intCode = 0 Then
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  WScript.Echo(&quot;Done...&quot;)
Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  objService.StartService
Â Â Â Â Â Â Â Â Â Â Â  Else WScript.Echo(&quot;Failed To Repair&quot;)
Â Â Â Â Â Â Â Â Â Â Â  End If
Â Â Â Â  Else If objService.ExitCode = 0 Then WScript.Echo (&quot;Successfully stated...&quot;)
Â Â Â Â  End If
Â Â Â  End If
Next
Function Repair(strComputer)
Â Â Â  strCommandLine = &quot;sc sdset &quot; &amp;amp; objService.Name &amp;amp; &quot; &quot; &amp;amp; Chr(34) &amp;amp; &quot;D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;AU)(A;;CCLCSWRPWPDTLOCRRC;;;PU)&quot; &amp;amp; Chr(34)
Â Â Â  Set objWMIService = GetObject(&quot;winmgmts:\\&quot; &amp;amp; strComputer &amp;amp; &quot;\root\CIMV2&quot;)
Â Â Â  &#039; Obtain the definition of the class.
Â Â Â  Set objShare = objWMIService.Get(&quot;Win32_Process&quot;)
Â Â Â  &#039; Obtain an InParameters object specific
Â Â Â  &#039; to the method.
Â Â Â  Set objInParam = objShare.Methods_(&quot;Create&quot;). _
Â Â Â Â  inParameters.SpawnInstance_()
Â Â Â  &#039; Add the input parameters.
Â Â Â  objInParam.Properties_.Item(&quot;CommandLine&quot;) = strCommandLine
Â Â Â  &#039; Execute the method and obtain the return status.
Â Â Â  &#039; The OutParameters object in objOutParams
Â Â Â  &#039; is created by the provider.
Â Â Â  Set objOutParams = objWMIService.ExecMethod(&quot;Win32_Process&quot;, &quot;Create&quot;, objInParam)
Â Â Â  &#039; List OutParams
Â Â Â  WScript.Echo &quot;Out Parameters: &quot;
Â Â Â  WScript.echo &quot;ProcessId: &quot; &amp;amp; objOutParams.ProcessId
Â Â Â  Repair = objOutParams.ReturnValue
End Function</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.bahramov.com/2009/06/30/script-to-fix-the-error-with-start-up-of-automatic-updates-and-bits-services-eventid-7023-and-eventid-7024/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Script for remote reboot/shutdown, power off and more.</title>
		<link>http://www.bahramov.com/2009/06/30/script-for-remote-rebootshutdown-power-off-and-more/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.bahramov.com/2009/06/30/script-for-remote-rebootshutdown-power-off-and-more/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 11:13:26 +0000</pubDate>
		<dc:creator>Zaur Bahramov</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[VB]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://www.bahramov.com/?p=326</guid>
		<description><![CDATA[Script for remote reboot/shutdown, power off, etc.Â You must have proper rights on a remote computerÂ  for this script to work.

&#039; Script for remote reboot/shutdown, power off, etc.
&#039; You must have proper rights on a remote computer
&#039; for this script to work

Dim StationName
Dim OpSysSet
Dim Flags
Dim Reserved
StationName = InputBox(&#34;Insert the Name of the Station to be Shutdown.&#34;)
Set [...]]]></description>
			<content:encoded><![CDATA[<p>Script for remote reboot/shutdown, power off, etc.Â You must have proper rights on a remote computerÂ  for this script to work.</p>
<p><span id="more-326"></span>
<pre class="brush: vb.net">&#039; Script for remote reboot/shutdown, power off, etc.
&#039; You must have proper rights on a remote computer
&#039; for this script to work

Dim StationName
Dim OpSysSet
Dim Flags
Dim Reserved
StationName = InputBox(&quot;Insert the Name of the Station to be Shutdown.&quot;)
Set OpSysSet = GetObject(&quot;winmgmts:{impersonationLevel=impersonate,(RemoteShutdown)}//&quot; &amp; StationName).ExecQuery(&quot;select * from Win32_OperatingSystem where Primary=true&quot;)
&#039; Flags Action
&#039;Â  0Â Â Â  Logoff
&#039;Â  1Â Â Â  Shutdown
&#039;Â  2Â Â Â  Reboot
&#039;Â  4Â Â Â  Force
&#039;Â  8Â Â Â  Power Off
&#039; 16Â Â Â  Force If Hung
Flags = 8
Reserved = 0
For Each OpSys In OpSysSet
Â Â  OpSys.Win32Shutdown Flags,Reserved
Next</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.bahramov.com/2009/06/30/script-for-remote-rebootshutdown-power-off-and-more/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Script to manage Event Log files</title>
		<link>http://www.bahramov.com/2009/06/30/script-to-manage-event-log-files/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.bahramov.com/2009/06/30/script-to-manage-event-log-files/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 10:28:33 +0000</pubDate>
		<dc:creator>Zaur Bahramov</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[VB]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://www.bahramov.com/?p=314</guid>
		<description><![CDATA[This script will check the size of the Event Log files and if any of these files will have the size greater than defined value it will back it up and then clean it.


strComputer = &#34;.&#34;
Set objWMIService = GetObject(&#34;winmgmts:&#34; _
Â Â Â  &#38; &#34;{impersonationLevel=impersonate, (Backup, Security)}!\\&#34; _
Â Â Â Â Â Â Â  &#38; strComputer &#38; &#34;\root\cimv2&#34;)
Set colLogFiles = objWMIService.ExecQuery _
Â Â Â  (&#34;Select * [...]]]></description>
			<content:encoded><![CDATA[<p>This script will check the size of the Event Log files and if any of these files will have the size greater than defined value it will back it up and then clean it.</p>
<p><span id="more-314"></span></p>
<p><span></span>
<pre class="brush: vb.net">strComputer = &quot;.&quot;
Set objWMIService = GetObject(&quot;winmgmts:&quot; _
Â Â Â  &amp; &quot;{impersonationLevel=impersonate, (Backup, Security)}!\\&quot; _
Â Â Â Â Â Â Â  &amp; strComputer &amp; &quot;\root\cimv2&quot;)
Set colLogFiles = objWMIService.ExecQuery _
Â Â Â  (&quot;Select * from Win32_NTEventLogFile&quot;)
For Each objLogfile in colLogFiles
Â Â Â  If objLogFile.FileSize &gt; 100000 Then
Â Â Â Â Â Â  strBackupLog = objLogFile.BackupEventLog _
Â Â Â Â Â Â Â Â Â Â  (&quot;c:\scripts\&quot; &amp; objLogFile.LogFileName &amp; &quot;.evt&quot;)
Â Â Â Â Â Â  objLogFile.ClearEventLog()
Â Â Â  End If
Next</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.bahramov.com/2009/06/30/script-to-manage-event-log-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VB Script to query domain computers for currently logged in users</title>
		<link>http://www.bahramov.com/2009/06/30/vb-script-to-query-domain-computers-for-currently-logged-in-users/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.bahramov.com/2009/06/30/vb-script-to-query-domain-computers-for-currently-logged-in-users/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 09:34:42 +0000</pubDate>
		<dc:creator>Zaur Bahramov</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[Active Directory]]></category>

		<guid isPermaLink="false">http://www.bahramov.com/2009/06/30/vb-script-to-query-domain-computers-for-currently-logged-in-users/</guid>
		<description><![CDATA[Source: http://forum.vingrad.ru/forum/topic-154708/view-all.html
The script will query domain computers for logged on users on each computer


&#039; The script will query domain computers for logged on users
&#039; on each computer
On Error Resume Next

Const ADS_SCOPE_SUBTREE = 2

Set objRoot = GetObject(&#34;LDAP://RootDSE&#34;)
strDomainName = objRoot.Get(&#34;DefaultNamingContext&#34;)
Set objRoot = Nothing

strComputer = &#34;&#34;
Dim fso
Dim file

Set fso = CreateObject(&#34;Scripting.FileSystemObject&#34;)
Set file = fso.OpenTextFile (&#34;logged_user_list.txt&#34;, 2, True)
Set objShell [...]]]></description>
			<content:encoded><![CDATA[<div class="csharpcode">Source: <a title="http://forum.vingrad.ru/forum/topic-154708/view-all.html" href="http://forum.vingrad.ru/forum/topic-154708/view-all.html">http://forum.vingrad.ru/forum/topic-154708/view-all.html</a></div>
<div>The script will query domain computers for logged on users on each computer</div>
<div><span id="more-309"></span></div>
<div>
<pre class="brush: vb.net">&#039; The script will query domain computers for logged on users
&#039; on each computer
On Error Resume Next

Const ADS_SCOPE_SUBTREE = 2

Set objRoot = GetObject(&quot;LDAP://RootDSE&quot;)
strDomainName = objRoot.Get(&quot;DefaultNamingContext&quot;)
Set objRoot = Nothing

strComputer = &quot;&quot;
Dim fso
Dim file

Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set file = fso.OpenTextFile (&quot;logged_user_list.txt&quot;, 2, True)
Set objShell = CreateObject(&quot;WScript.Shell&quot;)

Set objConnection = CreateObject(&quot;ADODB.Connection&quot;)
Set objCommand = CreateObject(&quot;ADODB.Command&quot;)
objConnection.Provider = &quot;ADsDSOObject&quot;
objConnection.Open &quot;Active Directory Provider&quot;

Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = &quot;Select Name, Location from &#039;LDAP://&quot; &amp; strDomainName &amp; &quot;&#039;&quot; _
&amp; &quot;Where objectClass =&#039;computer&#039;&quot;
objCommand.Properties(&quot;Page Size&quot;) = 1000
objCommand.Properties(&quot;Searchscope&quot;) = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute

&#039;**********************************************************************************

objRecordSet.MoveFirst

Wscript.Echo &quot;Processing information. This might take several minutes.&quot;

Do Until objRecordSet.EOF
Â Â Â  strComputer = objRecordSet.Fields(&quot;Name&quot;).Value

&#039; Check computer online status by using PING
&#039; and analysing output

Â Â Â  Set objScriptExec = objShell.Exec(&quot;%comspec% /c ping.exe -n 1 &quot; &amp; strComputer)
Â Â Â  strPingResults = LCase(objScriptExec.StdOut.ReadAll)

&#039;Â Â Â  If computer responds, connect to WMI

Â Â Â  If InStr(strPingResults, &quot;ttl=&quot;) Then
Â Â Â Â  Set objWMIService = GetObject(&quot;winmgmts:&quot; _
Â Â Â  &amp; &quot;{impersonationLevel=impersonate}!\\&quot; &amp; strComputer &amp; &quot;\root\cimv2&quot;)
Â Â Â Â Â Â 
Â Â Â Â Â Â Â  Set colComputer = objWMIService.ExecQuery _
Â Â Â  (&quot;Select * from Win32_ComputerSystem&quot;)
Â Â 
&#039; List logged on users to file and screen

Â Â Â Â Â Â Â  For Each objComputer in colComputer
Â Â Â Â Â Â Â Â Â Â Â Â  WScript.Echo &quot;Logged-on &quot; &amp;strComputer &amp; &quot; user: &quot; &amp; objComputer.UserName
Â Â Â Â Â Â Â Â Â Â Â Â  file.WriteLine(&quot;Logged-on &quot; &amp;strComputer &amp; &quot; user: &quot; &amp; objComputer.UserName)
Â Â Â Â Â Â Â  Next
Â Â Â Â Â Â Â  objRecordSet.MoveNext
Â Â Â Â Â Â 
&#039; If computer does not respond then show message and continue to next

Â Â Â  Else
Â Â Â Â  WScript.Echo(strComputer &amp; &quot;: Not responding...&quot;)
Â Â Â Â Â Â Â  objRecordSet.MoveNext
Â Â Â  End If
Loop
</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.bahramov.com/2009/06/30/vb-script-to-query-domain-computers-for-currently-logged-in-users/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

