<?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>Wayne Zimmerman&#039;s Blog &#187; Code</title>
	<atom:link href="http://www.waynezim.com/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.waynezim.com</link>
	<description>My World of Tech, Life and Anything Else</description>
	<lastBuildDate>Sun, 05 Feb 2012 05:35:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Allow User To Run Applicaton as Administrator Without a Password</title>
		<link>http://www.waynezim.com/2009/09/allow-user-to-run-applicaton-as-administrator-without-a-password/</link>
		<comments>http://www.waynezim.com/2009/09/allow-user-to-run-applicaton-as-administrator-without-a-password/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 19:26:40 +0000</pubDate>
		<dc:creator>Wayne Zimmerman</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[administrator]]></category>
		<category><![CDATA[Computer]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[runas]]></category>
		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://www.waynezim.com/?p=465</guid>
		<description><![CDATA[A few days ago I came across a software application that just wouldn&#8217;t execute correctly without the user being an administrator on the computer. Since all of my users run as basic / limited users they were unable to use program. After contacting the vendor and looking for all type of rights that we could [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago I came across a software application that just wouldn&#8217;t execute correctly without the user being an administrator on the computer. Since all of my users run as basic / limited users they were unable to use program. After contacting the vendor and looking for all type of rights that we could grant the user so the could execute the program properly we were unable to fix it without making the user an administrator. So rather than making them an administrator or giving them the administrator password I made a little application that calls the other application as a run as but has the administrator credentials complied in. I realize that you can probably decompile the application and get the password, but for many users that is too much work, or they lack the expertise, so I view this as a small security issue. To further protect the account I made one that only exists on that computer. Below is the code that you can use to build a similar application it is only a few lines but it can solve a headache and keep a password relatively secure.</p>
<p>This is a VB.NET application<br />This application will produce an error if it is unable to login as that account or if the target program cannot be found.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p465code2'); return false;">View Code</a> VB</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4652"><td class="code" id="p465code2"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Public</span> Class Form1
    <span style="color: #000080;">Private</span> <span style="color: #000080;">Sub</span> Form1_Load(<span style="color: #000080;">ByVal</span> sender <span style="color: #000080;">As</span> System.<span style="color: #000080;">Object</span>, <span style="color: #000080;">ByVal</span> e <span style="color: #000080;">As</span> System.EventArgs) Handles MyBase.Load
        <span style="color: #000080;">Dim</span> DomainName <span style="color: #000080;">As</span> <span style="color: #000080;">String</span>
        <span style="color: #000080;">Dim</span> UserName <span style="color: #000080;">As</span> <span style="color: #000080;">String</span>
        <span style="color: #000080;">Dim</span> Password <span style="color: #000080;">As</span> <span style="color: #000080;">String</span>
        <span style="color: #000080;">Dim</span> SysPassword <span style="color: #000080;">As</span> System.Security.SecureString = <span style="color: #000080;">New</span> System.Security.SecureString()
        DomainName = System.Environment.GetEnvironmentVariable(<span style="color: #800000;">&quot;ComputerName&quot;</span>)
        UserName = <span style="color: #800000;">&quot;administrator&quot;</span>
        Password = <span style="color: #800000;">&quot;supersecretpassword&quot;</span>
&nbsp;
        <span style="color: #000080;">For</span> <span style="color: #000080;">Each</span> c <span style="color: #000080;">As</span> Char <span style="color: #000080;">In</span> Password
            SysPassword.AppendChar(c)
        <span style="color: #000080;">Next</span>
        SysPassword.MakeReadOnly()
&nbsp;
        Try
            System.Diagnostics.Process.Start(<span style="color: #800000;">&quot;notepad.exe&quot;</span>, UserName, SysPassword, DomainName)
        Catch ex <span style="color: #000080;">As</span> Exception
            MsgBox(ex.Message)
        <span style="color: #000080;">End</span> Try
        Me.<span style="color: #000080;">Close</span>()
    <span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span>
<span style="color: #000080;">End</span> Class</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.waynezim.com/2009/09/allow-user-to-run-applicaton-as-administrator-without-a-password/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Report Workstation Uptime in a CSV using Active Directory and VBS</title>
		<link>http://www.waynezim.com/2009/07/report-workstation-uptime-in-a-csv-using-active-directory-and-vbs/</link>
		<comments>http://www.waynezim.com/2009/07/report-workstation-uptime-in-a-csv-using-active-directory-and-vbs/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 19:56:09 +0000</pubDate>
		<dc:creator>Wayne Zimmerman</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Computer]]></category>
		<category><![CDATA[CSV]]></category>
		<category><![CDATA[Domain]]></category>
		<category><![CDATA[Report]]></category>
		<category><![CDATA[Uptime]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[VBscript]]></category>

		<guid isPermaLink="false">http://www.waynezim.com/?p=437</guid>
		<description><![CDATA[Have you ever been left wondering which computers on your domain have been neglected by their user and not restarted in forever? This is a question that come up in my office every once and a while. One of the easiest ways to solve this problem is to ask WMI for when the computer was [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever been left wondering which computers on your domain have been neglected by their user and not restarted in forever? This is a question that come up in my office every once and a while. One of the easiest ways to solve this problem is to ask WMI for when the computer was last restarted and subtract it from the current time. Also, while asking WMI questions you might as well ask which user is currently logged on the PC that way you know who to blame. This is exactly what the following script does for your domain. It grabs the list of workstations from the domain then queries WMI for the last time the computer is restarted and does some conversion and math and makes you an nice CSV that you can play with. </p>
<p><b>Script Configuration</b><br />
Before running this script there is some minor configuration that must be done so it can communicate with your Active Directory setup.
<ol>
<li>Find <code>objConnection.Open "Active Directory Server"</code> change <em>Active Directory Server</em> to the name of your Domain Controller</li>
<li>Find <code>objCommand.CommandText = _<br />
    "Select Name, Location from 'LDAP://OU=Workstations,DC=west,DC=domain,DC=edu' " _<br />
        &#038; "Where objectClass='computer'"</code> change <em>subdomain</em>, <em>domain</em>, and <em>suffix</em> to the name of your domain i.e. west domain edu (respectively)</li>
<li>Find <code>GetUptime objRecordSet.Fields("Name").Value, "C:\uptime.csv"</code> and change <em>C:\uptime.csv</em> to the location where you want the file saved. Be sure to save it with the extension CSV
</ol>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.waynezim.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=437&amp;download=GetUptime.vbs">GetUptime.vbs</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4374"><td class="code" id="p437code4"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Const</span> ADS_SCOPE_SUBTREE = 2
&nbsp;
<span style="color: #000080;">Set</span> objConnection = CreateObject(<span style="color: #800000;">&quot;ADODB.Connection&quot;</span>)
<span style="color: #000080;">Set</span> objCommand =   CreateObject(<span style="color: #800000;">&quot;ADODB.Command&quot;</span>)
objConnection.Provider = <span style="color: #800000;">&quot;ADsDSOObject&quot;</span>
objConnection.<span style="color: #000080;">Open</span> <span style="color: #800000;">&quot;Active Directory Server&quot;</span> 
&nbsp;
<span style="color: #000080;">Set</span> objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
    <span style="color: #800000;">&quot;Select Name, Location from 'OU=Workstations,DC=west,DC=domain,DC=edu' &quot;</span> _
        &amp; <span style="color: #800000;">&quot;Where objectClass='computer'&quot;</span>  
objCommand.Properties(<span style="color: #800000;">&quot;Page Size&quot;</span>) = 1000
objCommand.Properties(<span style="color: #800000;">&quot;Searchscope&quot;</span>) = ADS_SCOPE_SUBTREE 
<span style="color: #000080;">Set</span> objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
&nbsp;
<span style="color: #000080;">Do</span> <span style="color: #000080;">Until</span> objRecordSet.EOF
	GetUptime objRecordSet.Fields(<span style="color: #800000;">&quot;Name&quot;</span>).Value, <span style="color: #800000;">&quot;C:\uptime.csv&quot;</span>
    objRecordSet.MoveNext
<span style="color: #000080;">Loop</span>
&nbsp;
<span style="color: #000080;">Sub</span> GetUptime(strComputer, strFilename)
	<span style="color: #000080;">On</span> <span style="color: #000080;">Error</span> <span style="color: #000080;">Resume</span> <span style="color: #000080;">Next</span>
	<span style="color: #000080;">Set</span> StdOut = WScript.StdOut
&nbsp;
	<span style="color: #000080;">Set</span> objFSO = CreateObject(<span style="color: #800000;">&quot;scripting.filesystemobject&quot;</span>)
	<span style="color: #000080;">Set</span> logStream = objFSO.opentextfile(strFilename, 8, <span style="color: #000080;">True</span>)
&nbsp;
	<span style="color: #000080;">Set</span> oReg=GetObject(<span style="color: #800000;">&quot;winmgmts:{impersonationLevel=impersonate}!\\&quot;</span> &amp; strComputer &amp; <span style="color: #800000;">&quot;\root\default:StdRegProv&quot;</span>)
	<span style="color: #000080;">If</span> Err.Number <span style="color: #000080;">Then</span>
	      logStream.writeline(strComputer &amp; <span style="color: #800000;">&quot;,Offline&quot;</span>)
	      Err.Clear
	<span style="color: #000080;">Else</span>
		<span style="color: #000080;">Set</span> objWMIService = GetObject _
			(<span style="color: #800000;">&quot;winmgmts:\\&quot;</span> &amp; strComputer &amp; <span style="color: #800000;">&quot;\root\cimv2&quot;</span>)
		<span style="color: #000080;">Set</span> colOperatingSystems = objWMIService.ExecQuery _
			(<span style="color: #800000;">&quot;Select * from Win32_OperatingSystem&quot;</span>)
		<span style="color: #000080;">For</span> <span style="color: #000080;">Each</span> objOS <span style="color: #000080;">in</span> colOperatingSystems
			dtmBootup = objOS.LastBootUpTime
			dtmLastBootupTime = WMIDateStringToDate(dtmBootup)
			dtmSystemUptime = DateDiff(<span style="color: #800000;">&quot;h&quot;</span>, dtmLastBootUpTime, Now()) 
		<span style="color: #000080;">Next</span>
		<span style="color: #000080;">Set</span> objWMIService = GetObject _
			(<span style="color: #800000;">&quot;winmgmts:\\&quot;</span> &amp; strComputer &amp; <span style="color: #800000;">&quot;\root\cimv2&quot;</span>)
		<span style="color: #000080;">Set</span> colComputerSys = objWMIService.ExecQuery _
			(<span style="color: #800000;">&quot;Select UserName from Win32_ComputerSystem&quot;</span>)
		<span style="color: #000080;">For</span> <span style="color: #000080;">Each</span> objCS <span style="color: #000080;">in</span> colComputerSys
			username = objCS.UserName
			logStream.writeline(strComputer &amp; <span style="color: #800000;">&quot;,Online,&quot;</span> &amp; dtmSystemUptime &amp; <span style="color: #800000;">&quot;,&quot;</span> &amp; dtmLastBootupTime &amp; <span style="color: #800000;">&quot;,&quot;</span> &amp; username) 
		<span style="color: #000080;">Next</span>
&nbsp;
	<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
	logStream.<span style="color: #000080;">Close</span>
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span>
<span style="color: #000080;">Function</span> WMIDateStringToDate(dtmBootup)
    WMIDateStringToDate = <span style="color: #000080;">CDate</span>(Mid(dtmBootup, 5, 2) &amp; <span style="color: #800000;">&quot;/&quot;</span> &amp; _
         Mid(dtmBootup, 7, 2) &amp; <span style="color: #800000;">&quot;/&quot;</span> &amp; Left(dtmBootup, 4) _
         &amp; <span style="color: #800000;">&quot; &quot;</span> &amp; Mid (dtmBootup, 9, 2) &amp; <span style="color: #800000;">&quot;:&quot;</span> &amp; _
         Mid(dtmBootup, 11, 2) &amp; <span style="color: #800000;">&quot;:&quot;</span> &amp; Mid(dtmBootup, _
         13, 2))
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.waynezim.com/2009/07/report-workstation-uptime-in-a-csv-using-active-directory-and-vbs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Weekly Terminal Services Connection Report using VBS</title>
		<link>http://www.waynezim.com/2009/06/weekly-terminal-services-connection-report-using-vbs/</link>
		<comments>http://www.waynezim.com/2009/06/weekly-terminal-services-connection-report-using-vbs/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 15:47:14 +0000</pubDate>
		<dc:creator>Wayne Zimmerman</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Audit]]></category>
		<category><![CDATA[Email]]></category>
		<category><![CDATA[Event Log]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Remote Administration]]></category>
		<category><![CDATA[Remote Desktop Connection]]></category>
		<category><![CDATA[Report]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[SMTP]]></category>
		<category><![CDATA[Terminal Services]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[VBscript]]></category>

		<guid isPermaLink="false">http://www.waynezim.com/?p=314</guid>
		<description><![CDATA[A few weeks ago we had some state auditors come by and mention that we should review our logs for any sort of outside / vendor access. I knew that going to each server and reviewing the logs manually would be very time consuming and not really provide solid documentation that it was done. I [...]]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago we had some state auditors come by and mention that we should review our logs for any sort of outside / vendor access. I knew that going to each server and reviewing the logs manually would be very time consuming and not really provide solid documentation that it was done. I decided that the only way to solve this problem was with a report of some nature. I fired up my trusty Crystal Reports and started to view the logs using that, once I got in to more I realized that when I added the description field of the event log it always crashed Crystal Reports. This left me going to plan B which is writing the reports from scratch using Visual Basic Scripting language.</p>
<p>I already knew that you can use VBS to connect to WMI (Windows Management Interface) and view different parts of the system including the event log, so I spent the morning writing the report and parsing it down to the detail that I really needed. Then I decided to take it to the next level by adding in recursion for multiple servers and also set it up to send an HTML email so it is easy to review every week. Why every week you may ask, well in looking at my event log on my domain server I noticed that I start losing Security events at about 10-14 days out since it is authorizing so much, and a weekly task is a very manageable one.</p>
<p><b>Script Configuration</b></p>
<ol>
<li>Configure the servers that this script will report on. Modify the <em>Servers</em> array for each server that needs to be checked. (Note: all servers need the same login credentials for the script to work)</li>
<li>Find the <em>objMessage.From</em> field and update it with who the email is coming from</li>
<li>Find the <em>objMessage.To</em> Field and update with the email address of the person who will be receiving the report, if you have multiple addresses to send to separate them with a semi-colon (;)</li>
<li>Find the <em>(&#8220;http://schemas.microsoft.com/cdo/configuration/smtpserver&#8221;) = &#8220;smtp-relay.waynezim.com&#8221;</em> and update this with your SMTP server, if your server requires authentication you will need to modify this script to include that, a simple Google search should show you what needs to be changed.</li>
<li>This script should be setup to be a scheduled task on one of your servers, the credentials used in setting up the job will be used to connect to the other servers, this account needs to exist on all servers to view the Security Event Log and make the report.</li>
<li>To setup a scheduled task, go to your <em>Control Panel</em>, open <em>Scheduled Tasks</em>, right click <em>New > Scheduled Task</em>, name it, then right click and modify the <em>Properties</em>, <em>Browse</em> to where the script is saved, set the <em>Run as</em> at the bottom for the user that exists on all Servers and set the password. Then go to the <em>Schedule</em> tab and set it to <em>Weekly</em> and change it to run when you want it to.</li>
</ol>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.waynezim.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=314&amp;download=RemoteConnectionsReport.vbs">RemoteConnectionsReport.vbs</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3146"><td class="code" id="p314code6"><pre class="vbs" style="font-family:monospace;">Dim objWMI, objEvent ' Objects
Dim strComputer ' Strings
Dim intEvent, intNumberID, intRecordNum, colLoggedEvents
'--------------------------------------------
' Server List to Parse Logs
Dim Servers(5)
Servers(0) = &quot;server1&quot;
Servers(1) = &quot;server2&quot;
Servers(2) = &quot;server3&quot;
Servers(3) = &quot;server4&quot;
Servers(4) = &quot;server5&quot;
Servers(5) = &quot;server6&quot;
'--------------------------------------------
' Email Body Heading
HTMLMsg = &quot;&lt;html&gt;&lt;body&gt;&lt;h3&gt;Remote Desktop Connections from &quot; &amp; cDate(Now() - 7) &amp; &quot; to &quot; &amp; cDate(Now()) &amp; &quot;&lt;/h3&gt;&quot;
HTMLMsg = HTMLMsg &amp; &quot;&lt;table border=1&gt;&lt;tr&gt;&lt;td&gt;&lt;b&gt;Computer Name&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Logon Type&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Remote IP&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Date / Time&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;User&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&quot;
'--------------------------------------------
' Next section creates the file to store Events
' Then creates WMI connector to the Logs
&nbsp;
'Range Variable - Out of Loop for Common Report Time
WeekAgo = cDate(Now() - 7)
&nbsp;
'Start Each Computer Loop
For Each strComputer in Servers
' --------------------------------------------
' Set your variables for Events Loop
intEvent = 1
intRecordNum = 1
&nbsp;
Set objWMI = GetObject(&quot;winmgmts:&quot; _
&amp; &quot;{impersonationLevel=impersonate}!\\&quot; _
&amp; strComputer &amp; &quot;\root\cimv2&quot;)
Set colLoggedEvents = objWMI.ExecQuery _
(&quot;Select * from Win32_NTLogEvent Where Logfile = 'Security' AND EventCode = 528 AND TimeWritten &gt; '&quot; &amp; WeekAgo &amp; &quot;'&quot;)
' -----------------------------------------
' Next section loops through ID properties
intEvent = 1
	For Each objEvent in colLoggedEvents
&nbsp;
	HTMLMsg = HTMLMsg &amp; &quot;&lt;tr&gt;&lt;td&gt;&quot; &amp; objEvent.ComputerName &amp; &quot;&lt;/td&gt;&quot;
	LogonType = RTrim(Mid(objEvent.Message,InStr(objEvent.Message,&quot;Logon Type:&quot;)+12,2))
	If LogonType = 2 Then HTMLMsg = HTMLMsg &amp; &quot;&lt;td&gt;Interactive&lt;/td&gt;&quot; End if
	If LogonType = 3 Then HTMLMsg = HTMLMsg &amp; &quot;&lt;td&gt;Network&lt;/td&gt;&quot; End if
	If LogonType = 4 Then HTMLMsg = HTMLMsg &amp; &quot;&lt;td&gt;Batch&lt;/td&gt;&quot; End if
	If LogonType = 5 Then HTMLMsg = HTMLMsg &amp; &quot;&lt;td&gt;Service&lt;/td&gt;&quot; End if
	If LogonType = 7 Then HTMLMsg = HTMLMsg &amp; &quot;&lt;td&gt;Unlock&lt;/td&gt;&quot; End if
	If LogonType = 8 Then HTMLMsg = HTMLMsg &amp; &quot;&lt;td&gt;Network using Clear Text&lt;/td&gt;&quot; End if
	If LogonType = 9 Then HTMLMsg = HTMLMsg &amp; &quot;&lt;td&gt;New Credentials&lt;/td&gt;&quot; End if
	If LogonType = 10 Then HTMLMsg = HTMLMsg &amp; &quot;&lt;td&gt;Remote Interactive&lt;/td&gt;&quot; End if
	If LogonType = 11 Then HTMLMsg = HTMLMsg &amp; &quot;&lt;td&gt;Cached Interaction&lt;/td&gt;&quot; End if
&nbsp;
	IPlen = InStr(InStr(objEvent.Message,&quot;Source Network Address:&quot;)+24,objEvent.Message,&quot;	&quot;) - InStr(objEvent.Message,&quot;Source Network Address:&quot;) - 28
	RemoteAddress = RTrim(Mid(objEvent.Message,InStr(objEvent.Message,&quot;Source Network Address:&quot;)+24,IPlen))
	HTMLMsg = HTMLMsg &amp; &quot;&lt;td&gt;&quot; &amp; RemoteAddress &amp; &quot;&lt;/td&gt;&quot;
	EventTime = Mid(objEvent.TimeWritten, 5, 2) &amp; &quot;/&quot; &amp; Mid(objEvent.TimeWritten, 7, 2) &amp; &quot;/&quot; &amp; Mid(objEvent.TimeWritten, 1, 4) &amp; &quot; &quot; &amp; Mid(objEvent.TimeWritten, 9, 2) &amp; &quot;:&quot; &amp; Mid(objEvent.TimeWritten, 11, 2) &amp; &quot;.&quot; &amp; Mid(objEvent.TimeWritten, 13, 2)
	HTMLMsg = HTMLMsg &amp; &quot;&lt;td&gt;&quot; &amp; EventTime &amp; &quot;&lt;/td&gt;&quot;
	HTMLMsg = HTMLMsg &amp; &quot;&lt;td&gt;&quot; &amp; objEvent.User &amp; &quot;&lt;/td&gt;&lt;/tr&gt;&quot;
	intRecordNum = intRecordNum +1
	IntEvent = intEvent +1
&nbsp;
	Next
Next
&nbsp;
Set objMessage = CreateObject(&quot;CDO.Message&quot;)
objMessage.Subject = &quot;Remote Connections Report: &quot; &amp; cDate(Now())
objMessage.From = &quot;root@waynezim.com&quot;
objMessage.To = &quot;waynezim@waynezim.com&quot;
objMessage.HTMLBody = HTMLMsg
'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.
objMessage.Configuration.Fields.Item _
(&quot;http://schemas.microsoft.com/cdo/configuration/sendusing&quot;) = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
(&quot;http://schemas.microsoft.com/cdo/configuration/smtpserver&quot;) = &quot;smtp-relay.waynezim.com&quot;
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
(&quot;http://schemas.microsoft.com/cdo/configuration/smtpserverport&quot;) = 25
objMessage.Configuration.Fields.Update
'==End remote SMTP server configuration section==
&nbsp;
objMessage.Send
WScript.Quit</pre></td></tr></table></div>

<p><b>Report Preview</b><br />
If you need help decoding what Logon Type really means check out this <a href="http://www.windowsecurity.com/articles/Logon-Types.html">great article. </a></p>
<table border=0>
<tr>
<td>
<a href="http://www.waynezim.com/wp-content/uploads/2009/06/remote-connection-report-preview.png"><img src="http://www.waynezim.com/wp-content/uploads/2009/06/remote-connection-report-preview.png" alt="remote-connection-report-preview" title="remote-connection-report-preview" width="675" height="253" class="alignleft size-full wp-image-324" /></a></td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.waynezim.com/2009/06/weekly-terminal-services-connection-report-using-vbs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Remove Old Cached Roaming Profiles from Workstations</title>
		<link>http://www.waynezim.com/2009/06/how-to-remove-old-cached-roaming-profiles-from-workstations/</link>
		<comments>http://www.waynezim.com/2009/06/how-to-remove-old-cached-roaming-profiles-from-workstations/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 17:20:55 +0000</pubDate>
		<dc:creator>Wayne Zimmerman</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Cached]]></category>
		<category><![CDATA[Computer]]></category>
		<category><![CDATA[Profiles]]></category>
		<category><![CDATA[Roaming]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[VBscript]]></category>

		<guid isPermaLink="false">http://www.waynezim.com/?p=238</guid>
		<description><![CDATA[Earlier this year I was tasked with cleaning up the workstations on our network to help reduce the amount of time needed for our daily virus scan to complete. One of the issues I took on was cleaning up old cached profiles from the use of roaming profiles. This was not something I wanted to [...]]]></description>
			<content:encoded><![CDATA[<p>Earlier this year I was tasked with cleaning up the workstations on our network to help reduce the amount of time needed for our daily virus scan to complete. One of the issues I took on was cleaning up old cached profiles from the use of roaming profiles. This was not something I wanted to do manually for the 150 PCs that we have across our building, so I made a script that would look for profiles that had not been modified in the last 90 days and wasn&#8217;t a system account (localservice, networkservice, default user, all users). Also, an advantage of using a script to do this is it can produce a report of what it will remove without actually doing it. That way you can be sure that you are not deleting things that you do want to keep.</p>
<p>This script does depending on file and print sharing being turned on for the workstation so the script can access the administrative shares on each computer. It does make the assumption that your profiles are saved in the default windows location <em>C:\Documents and Settings\%username%</em> and that you are the administrator for the domain.</p>
<p><b>Configuration</b>
<ol>
<li>Be sure to update the LDAP string <code>'LDAP://OU=workstations,DC=subdomain,DC=domain,DC=com'</code> to match your Active Directory structure. The script needs to know where all the workstation are in Active Directory</li>
<li>Find <code>objConnection.Open "DomainController"</code> and modify the put your Domain Controller in place of <em>DomainController</em></li>
<li>Find <code>	OldProfile objRecordSet.Fields("Name").Value, "C:\deletedprofiles.csv"</code> and modify the filename to save the file where you and and named what you want, just be sure to leave the extension as CSV so it will open properly with your spreadsheet application.</li>
<li>Most Importantly &#8211; Comment out <code>fsoFolder.DeleteFolder objSubfolder, TRUE</code> if you just want a report of what it will delete when run, if not it is currently setup to remove the unwanted profiles</li>
</ol>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.waynezim.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=238&amp;download=RemoveOldCachedProfiles.vbs">RemoveOldCachedProfiles.vbs</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2388"><td class="code" id="p238code8"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Const</span> ADS_SCOPE_SUBTREE = 2
&nbsp;
<span style="color: #000080;">Set</span> objConnection = CreateObject(<span style="color: #800000;">&quot;ADODB.Connection&quot;</span>)
<span style="color: #000080;">Set</span> objCommand =   CreateObject(<span style="color: #800000;">&quot;ADODB.Command&quot;</span>)
objConnection.Provider = <span style="color: #800000;">&quot;ADsDSOObject&quot;</span>
objConnection.<span style="color: #000080;">Open</span> <span style="color: #800000;">&quot;shs-login&quot;</span>
&nbsp;
<span style="color: #000080;">Set</span> objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
    <span style="color: #800000;">&quot;Select Name, Location from 'LDAP://OU=workstations,DC=subdomain,DC=domain,DC=com' &quot;</span> _
        &amp; <span style="color: #800000;">&quot;Where objectClass='computer'&quot;</span>  
objCommand.Properties(<span style="color: #800000;">&quot;Page Size&quot;</span>) = 1000
objCommand.Properties(<span style="color: #800000;">&quot;Searchscope&quot;</span>) = ADS_SCOPE_SUBTREE 
<span style="color: #000080;">Set</span> objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
&nbsp;
<span style="color: #000080;">Do</span> <span style="color: #000080;">Until</span> objRecordSet.EOF
	OldProfile objRecordSet.Fields(<span style="color: #800000;">&quot;Name&quot;</span>).Value, <span style="color: #800000;">&quot;C:\deletedprofiles.csv&quot;</span>
    objRecordSet.MoveNext
<span style="color: #000080;">Loop</span>
&nbsp;
<span style="color: #000080;">Sub</span> OldProfile(strComputer, strFilename)
	<span style="color: #000080;">On</span> <span style="color: #000080;">Error</span> <span style="color: #000080;">Resume</span> <span style="color: #000080;">Next</span>
	<span style="color: #000080;">Set</span> StdOut = WScript.StdOut
&nbsp;
	<span style="color: #000080;">Set</span> objFSO = CreateObject(<span style="color: #800000;">&quot;scripting.filesystemobject&quot;</span>)
	<span style="color: #000080;">Set</span> logStream = objFSO.opentextfile(strFilename, 8, <span style="color: #000080;">True</span>)
&nbsp;
	<span style="color: #000080;">Set</span> oReg=GetObject(<span style="color: #800000;">&quot;winmgmts:{impersonationLevel=impersonate}!\\&quot;</span> &amp; strComputer &amp; <span style="color: #800000;">&quot;\root\default:StdRegProv&quot;</span>)
	<span style="color: #000080;">If</span> Err.Number <span style="color: #000080;">Then</span>
	      logStream.writeline(strComputer &amp; <span style="color: #800000;">&quot;,Offline&quot;</span>)
	      Err.Clear
	<span style="color: #000080;">Else</span>
		<span style="color: #000080;">On</span> <span style="color: #000080;">Error</span> <span style="color: #000080;">Resume</span> <span style="color: #000080;">Next</span>
		<span style="color: #000080;">Set</span> objShell = CreateObject(<span style="color: #800000;">&quot;Shell.Application&quot;</span>)
		<span style="color: #000080;">Set</span> fsoFolder = CreateObject(<span style="color: #800000;">&quot;Scripting.FileSystemObject&quot;</span>)
&nbsp;
		root = <span style="color: #800000;">&quot;\\&quot;</span> &amp; strComputer &amp;<span style="color: #800000;">&quot;\C$\Documents and Settings&quot;</span>
&nbsp;
		<span style="color: #000080;">Set</span> objFolder = fsoFolder.GetFolder(root)
		<span style="color: #000080;">Set</span> colSubfolders = objFolder.Subfolders
&nbsp;
			<span style="color: #000080;">For</span> <span style="color: #000080;">Each</span> objSubfolder <span style="color: #000080;">in</span> colSubfolders
				<span style="color: #000080;">If</span> (lcase(objSubfolder.Name) &lt;&gt; <span style="color: #800000;">&quot;localservice&quot;</span> <span style="color: #000080;">AND</span> lcase(objSubfolder.Name) &lt;&gt; <span style="color: #800000;">&quot;networkservice&quot;</span>_
					<span style="color: #000080;">AND</span> lcase(objSubfolder.Name) &lt;&gt; <span style="color: #800000;">&quot;default user&quot;</span> <span style="color: #000080;">AND</span> lcase(objSubfolder.Name) &lt;&gt; <span style="color: #800000;">&quot;all users&quot;</span>) <span style="color: #000080;">then</span>
&nbsp;
						<span style="color: #000080;">If</span> (DateDiff(<span style="color: #800000;">&quot;D&quot;</span>, objSubfolder.DateLastModified, <span style="color: #000080;">Date</span>()) &gt; 90) <span style="color: #000080;">then</span>
							logStream.writeline(strComputer &amp; <span style="color: #800000;">&quot;,Online,Delete,&quot;</span> &amp; objSubfolder &amp; <span style="color: #800000;">&quot;,&quot;</span> &amp; objSubfolder.DateLastModified)
							fsoFolder.DeleteFolder objSubfolder, <span style="color: #000080;">TRUE</span>
						<span style="color: #000080;">else</span>
							logStream.writeline(strComputer &amp; <span style="color: #800000;">&quot;,Online,Active,&quot;</span> &amp; objSubfolder &amp; <span style="color: #800000;">&quot;,&quot;</span> &amp; objSubfolder.DateLastModified)
						<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
				<span style="color: #000080;">else</span>
					logStream.writeline(strComputer &amp; <span style="color: #800000;">&quot;,Online,System,&quot;</span> &amp; objSubfolder &amp; <span style="color: #800000;">&quot;,&quot;</span> &amp; objSubfolder.DateLastModified)
				<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
			<span style="color: #000080;">Next</span>
	<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
	logStream.<span style="color: #000080;">Close</span>
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.waynezim.com/2009/06/how-to-remove-old-cached-roaming-profiles-from-workstations/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>List All Active Directory User Accounts in a CSV</title>
		<link>http://www.waynezim.com/2009/05/list-all-active-directory-user-accounts-in-a-csv/</link>
		<comments>http://www.waynezim.com/2009/05/list-all-active-directory-user-accounts-in-a-csv/#comments</comments>
		<pubDate>Wed, 20 May 2009 20:51:03 +0000</pubDate>
		<dc:creator>Wayne Zimmerman</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[CSV]]></category>
		<category><![CDATA[Domain]]></category>
		<category><![CDATA[User Accounts]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[VBscript]]></category>

		<guid isPermaLink="false">http://www.waynezim.com/?p=185</guid>
		<description><![CDATA[We all know maintaining hundreds of user accounts can be frustrating especially when it comes to audit time and you need a good list of information to pass on to an auditor. Well today I am your savory, this simple script will produce you a list of users with some detailed information that can make [...]]]></description>
			<content:encoded><![CDATA[<p>We all know maintaining hundreds of user accounts can be frustrating especially when it comes to audit time and you need a good list of information to pass on to an auditor. Well today I am your savory, this simple script will produce you a list of users with some detailed information that can make audits or documentation much easier. The script creates a Comma Separated Values file or CSV that you can edit in Microsoft Excel or any standard spreadsheet application so you can customize the information before adding it to your report or audit. Below are the specific fields that this script will provide detail on for your Active Directory Users.
<p><b>User Details</b>
<ul>
<li>Name</li>
<li>Description</li>
<li>Profile Path</li>
<li>Home Drive</li>
<li>Account Disabled</li>
<li>Password Required</li>
<li>User Changable Password</li>
<li>Password Expires</li>
<li>SmartCard Required</li>
<li>Login Count</li>
<li>Last Login (date)</li>
<li>Last Password Change (date)</li>
<li>Created (date)</li>
<li>Modified (date)</li>
</ul>
<p><b>Script Configuration</b><br />
Before running this script there is some minor configuration that must be done so it can communicate with your Active Directory setup.
<ol>
<li>Find <code>objConnection.Open "Active Directory Server"</code> change <em>Active Directory Server</em> to the name of your Domain Controller</li>
<li>Find <code>objCommand.CommandText = _<br />
    "SELECT Name, description, profilePath, homeDrive, distinguishedName,userAccountControl FROM 'LDAP://dc=subdomain,dc=domain,dc=suffix' WHERE objectCategory='user'"</code> change <em>subdomain</em>, <em>domain</em>, and <em>suffix</em> to the name of your domain i.e. west consco com (respectively)</li>
<li>Find <code>Set logStream = objFSO.opentextfile("C:\domainusers.csv", 8, True)</code> and change <em>C:\domainusers.csv</em> to the location where you want the file saved. Be sure to save it with the extension CSV
</ol>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.waynezim.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=185&amp;download=ListUserAccounts.vbs">ListUserAccounts.vbs</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p18510"><td class="code" id="p185code10"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">On</span> <span style="color: #000080;">Error</span> <span style="color: #000080;">Resume</span> <span style="color: #000080;">Next</span>
<span style="color: #000080;">Const</span> ADS_SCOPE_SUBTREE = 2
&nbsp;
<span style="color: #000080;">Const</span> ADS_UF_ACCOUNTDISABLE = &amp;H0002 
<span style="color: #000080;">Const</span> ADS_UF_PASSWD_NOTREQD = &amp;H0020 
<span style="color: #000080;">Const</span> ADS_UF_PASSWD_CANT_CHANGE = &amp;H0040 
<span style="color: #000080;">Const</span> ADS_UF_DONT_EXPIRE_PASSWD = &amp;H10000 
<span style="color: #000080;">Const</span> ADS_UF_SMARTCARD_REQUIRED = &amp;H40000 
&nbsp;
<span style="color: #000080;">Set</span> objConnection = CreateObject(<span style="color: #800000;">&quot;ADODB.Connection&quot;</span>)
<span style="color: #000080;">Set</span> objCommand =   CreateObject(<span style="color: #800000;">&quot;ADODB.Command&quot;</span>)
objConnection.Provider = <span style="color: #800000;">&quot;ADsDSOObject&quot;</span>
objConnection.<span style="color: #000080;">Open</span> <span style="color: #800000;">&quot;Active Directory Server&quot;</span>
<span style="color: #000080;">Set</span> objCommand.ActiveConnection = objConnection
&nbsp;
objCommand.Properties(<span style="color: #800000;">&quot;Page Size&quot;</span>) = 1000
objCommand.Properties(<span style="color: #800000;">&quot;Searchscope&quot;</span>) = ADS_SCOPE_SUBTREE 
&nbsp;
objCommand.CommandText = _
    <span style="color: #800000;">&quot;SELECT Name, description, profilePath, homeDrive, distinguishedName,userAccountControl FROM 'LDAP://dc=subdomain,dc=domain,dc=suffix' WHERE objectCategory='user'&quot;</span>  
<span style="color: #000080;">Set</span> objRecordSet = objCommand.Execute
&nbsp;
objRecordSet.MoveFirst
<span style="color: #000080;">Set</span> objFSO = CreateObject(<span style="color: #800000;">&quot;scripting.filesystemobject&quot;</span>)
<span style="color: #000080;">Set</span> logStream = objFSO.opentextfile(<span style="color: #800000;">&quot;C:\domainusers.csv&quot;</span>, 8, <span style="color: #000080;">True</span>)
logStream.writeline(<span style="color: #800000;">&quot;Name,Description,Profile Path,Home Drive,Account Disabled,Password Required,User Changable Password,Password Expires,SmartCard Required,Login Count,Last Login,Last Password Change,Created,Modified&quot;</span>)
<span style="color: #000080;">Do</span> <span style="color: #000080;">Until</span> objRecordSet.EOF
&nbsp;
	strDN = objRecordset.Fields(<span style="color: #800000;">&quot;distinguishedName&quot;</span>).Value 
	<span style="color: #000080;">Set</span> objUser = GetObject (<span style="color: #800000;">&quot;LDAP://&quot;</span> &amp; strDN)
&nbsp;
	<span style="color: #000080;">If</span> objRecordset.Fields(<span style="color: #800000;">&quot;userAccountControl&quot;</span>).Value <span style="color: #000080;">AND</span> ADS_UF_ACCOUNTDISABLE <span style="color: #000080;">Then</span>
		Text = <span style="color: #800000;">&quot;Yes&quot;</span>
	<span style="color: #000080;">Else</span>
		Text = <span style="color: #800000;">&quot;No&quot;</span>
	<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
	<span style="color: #000080;">If</span> objRecordset.Fields(<span style="color: #800000;">&quot;userAccountControl&quot;</span>).Value <span style="color: #000080;">AND</span> ADS_UF_PASSWD_NOTREQD <span style="color: #000080;">Then</span>
		Text = Text &amp; <span style="color: #800000;">&quot;,No&quot;</span>
	<span style="color: #000080;">Else</span>
		Text = Text &amp; <span style="color: #800000;">&quot;,Yes&quot;</span>
	<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
	<span style="color: #000080;">If</span> objRecordset.Fields(<span style="color: #800000;">&quot;userAccountControl&quot;</span>).Value <span style="color: #000080;">AND</span> ADS_PASSWORD_CANT_CHANGE <span style="color: #000080;">Then</span>
		Text = Text &amp; <span style="color: #800000;">&quot;,No&quot;</span>
	<span style="color: #000080;">Else</span>
		Text = Text &amp; <span style="color: #800000;">&quot;,Yes&quot;</span>
	<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>	 
	<span style="color: #000080;">If</span> objRecordset.Fields(<span style="color: #800000;">&quot;userAccountControl&quot;</span>).Value <span style="color: #000080;">AND</span> ADS_UF_DONT_EXPIRE_PASSWD <span style="color: #000080;">Then</span>
		Text = Text &amp; <span style="color: #800000;">&quot;,No&quot;</span>
	<span style="color: #000080;">Else</span>
		Text = Text &amp; <span style="color: #800000;">&quot;,Yes&quot;</span>
	<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
	<span style="color: #000080;">If</span> objRecordset.Fields(<span style="color: #800000;">&quot;userAccountControl&quot;</span>).Value <span style="color: #000080;">AND</span> ADS_UF_SMARTCARD_REQUIRED <span style="color: #000080;">Then</span>
		Text = Text &amp; <span style="color: #800000;">&quot;,Yes&quot;</span>
	<span style="color: #000080;">Else</span>
		Text = Text &amp; <span style="color: #800000;">&quot;,No&quot;</span>
	<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
	logStream.writeline(objRecordset.Fields(<span style="color: #800000;">&quot;Name&quot;</span>).Value &amp; <span style="color: #800000;">&quot;,&quot;</span>_
		&amp; objRecordset.Fields(<span style="color: #800000;">&quot;description&quot;</span>).Value &amp; <span style="color: #800000;">&quot;,&quot;</span>_
		&amp; objRecordset.Fields(<span style="color: #800000;">&quot;profilePath&quot;</span>).Value &amp; <span style="color: #800000;">&quot;,&quot;</span>_
		&amp; objRecordset.Fields(<span style="color: #800000;">&quot;homeDrive&quot;</span>).Value &amp; <span style="color: #800000;">&quot;,&quot;</span>_
		&amp; text &amp; <span style="color: #800000;">&quot;,&quot;</span>_
		&amp; objUser.logonCount &amp; <span style="color: #800000;">&quot;,&quot;</span>_
		&amp; objUser.LastLogin &amp; <span style="color: #800000;">&quot;,&quot;</span>_
		&amp; objUser.PasswordLastChanged &amp; <span style="color: #800000;">&quot;,&quot;</span>_
		&amp; objUser.whenCreated &amp; <span style="color: #800000;">&quot;,&quot;</span>_
		&amp; objUser.whenChanged &amp; <span style="color: #800000;">&quot;,&quot;</span>_
		)
&nbsp;
    objRecordSet.MoveNext
<span style="color: #000080;">Loop</span>
logStream.<span style="color: #000080;">Close</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.waynezim.com/2009/05/list-all-active-directory-user-accounts-in-a-csv/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Passing Parameters to VB Script to Map Network Drives</title>
		<link>http://www.waynezim.com/2009/05/passing-parameters-to-vb-script-to-map-network-drives/</link>
		<comments>http://www.waynezim.com/2009/05/passing-parameters-to-vb-script-to-map-network-drives/#comments</comments>
		<pubDate>Tue, 05 May 2009 01:39:56 +0000</pubDate>
		<dc:creator>Wayne Zimmerman</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Group Policy]]></category>
		<category><![CDATA[Logon]]></category>
		<category><![CDATA[map drives]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[Startup]]></category>

		<guid isPermaLink="false">http://www.waynezim.com/?p=61</guid>
		<description><![CDATA[The other day I got an instant message from a fellow network administrator asking for a script that would map drives to by simply passing parameters from command line. This caused me to go into Google mode checking how parameters are passed in to Visual Basic Script and then applying the basic network drive mapping [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I got an instant message from a fellow network administrator asking for a script that would map drives to by simply passing parameters from command line. This caused me to go into Google mode checking how parameters are passed in to Visual Basic Script and then applying the basic network drive mapping script. Now I feel that only the proper thing to do is share it with everyone out there that is looking for the same thing he was. This is a very simple script that does something equally simple. Hopefully this will simply some of the group policies that are out there.
<p>Usage: mapme.vbs Z //server/share<br />This would result in passing Z as the drive letter and mapping it to the UNC path of //server/share</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.waynezim.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=61&amp;download=mapme.vbs">mapme.vbs</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6112"><td class="code" id="p61code12"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Set</span> objArgs = WScript.Arguments
<span style="color: #000080;">Set</span> objNetwork = WScript.CreateObject(<span style="color: #800000;">&quot;WScript.Network&quot;</span>)
objNetwork.MapNetworkDrive  objArgs(0) &amp; <span style="color: #800000;">&quot;:&quot;</span> , objArgs(1)</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.waynezim.com/2009/05/passing-parameters-to-vb-script-to-map-network-drives/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remove Temporary Files at Logoff</title>
		<link>http://www.waynezim.com/2009/04/remove-temporary-files-at-logoff/</link>
		<comments>http://www.waynezim.com/2009/04/remove-temporary-files-at-logoff/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 19:17:02 +0000</pubDate>
		<dc:creator>Wayne Zimmerman</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Domain]]></category>
		<category><![CDATA[Group Policy]]></category>
		<category><![CDATA[Logoff]]></category>
		<category><![CDATA[Temp]]></category>
		<category><![CDATA[Temp Files]]></category>
		<category><![CDATA[Temporary Files]]></category>
		<category><![CDATA[Temporary Internet Files]]></category>
		<category><![CDATA[User Accounts]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[VBscript]]></category>

		<guid isPermaLink="false">http://www.waynezim.com/?p=55</guid>
		<description><![CDATA[Over time users tend to open a lot of items programs that write little files to be used just once to print a document or a small setting for a program. These items build up over time and cause your computer to run slower due to your antivirus solution scanning it, your hard drive taking [...]]]></description>
			<content:encoded><![CDATA[<p>Over time users tend to open a lot of items programs that write little files to be used just once to print a document or a small setting for a program. These items build up over time and cause your computer to run slower due to your antivirus solution scanning it, your hard drive taking longer to find a free space of disk to write your new file or has to spend more time gathering up fragments of your file from in between these temp files. The solution here is pretty simple, these files need to go, and probably the easiest solution is the remove them when the user logs off. This doesn&#8217;t require anymore time for the user and typically isn&#8217;t a problem since most computers are logged on and off once a day.
<p>This script will remove the most common temporary folder for the user as well as remove any of the temporary internet files that they have gathered while surfing the web. When we implemented this script we noticed that the antivirus scan time and how many files it scanned were significantly reduced providing a better and faster workstation for your users. This script should be placed in the Group Policy for users as one of their logoff script.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.waynezim.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=55&amp;download=cleantemp.vbs">cleantemp.vbs</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5514"><td class="code" id="p55code14"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Const</span> TEMPORARY_INTERNET_FILES = &amp;H20&amp;
<span style="color: #000080;">dim</span> intDepth
&nbsp;
<span style="color: #000080;">Set</span> objShell = CreateObject(<span style="color: #800000;">&quot;Shell.Application&quot;</span>)
<span style="color: #000080;">Set</span> objFSO = CreateObject(<span style="color: #800000;">&quot;Scripting.FileSystemObject&quot;</span>)
&nbsp;
<span style="color: #008000;">'Clean User Temporary Intenet Files
</span><span style="color: #000080;">Set</span> objNameSpace = objShell.Namespace(TEMPORARY_INTERNET_FILES)
<span style="color: #000080;">Set</span> objFolderItem = objNameSpace.Self
<span style="color: #000080;">set</span> objFolder=objFSO.GetFolder(objFolderItem.Path)
intDepth=0
RemoveFolder objFolder
&nbsp;
<span style="color: #008000;">'Clean User Temp Files
</span><span style="color: #000080;">Const</span> TemporaryFolder = 2
<span style="color: #000080;">Set</span> tempFolder = objFSO.GetSpecialFolder(TemporaryFolder)
RemoveFolder tempFolder
&nbsp;
&nbsp;
<span style="color: #000080;">sub</span> RemoveFolder(objFolder)
	<span style="color: #008000;">' Recursively remove files and folders
</span>	intDepth=intDepth+1
	<span style="color: #000080;">on</span> <span style="color: #000080;">error</span> <span style="color: #000080;">resume</span> <span style="color: #000080;">next</span>
	<span style="color: #000080;">for</span> <span style="color: #000080;">each</span> objFile <span style="color: #000080;">in</span> objFolder.Files
		objFile.Delete <span style="color: #000080;">true</span>
	<span style="color: #000080;">next</span>
	Err.Clear
	<span style="color: #000080;">on</span> <span style="color: #000080;">error</span> <span style="color: #000080;">goto</span> 0
	<span style="color: #000080;">for</span> <span style="color: #000080;">each</span> objSubfolder <span style="color: #000080;">in</span> objFolder.SubFolders
		RemoveFolder objSubFolder
	<span style="color: #000080;">next</span>
	intDepth=intDepth-1
	<span style="color: #000080;">if</span> intDepth&lt;&gt;0 <span style="color: #000080;">then</span><span style="color: #008000;">' Don't delete top-level folder
</span>		<span style="color: #000080;">on</span> <span style="color: #000080;">error</span> <span style="color: #000080;">resume</span> <span style="color: #000080;">next</span>
		objFolder.Delete <span style="color: #000080;">true</span> 
		err.Clear
		<span style="color: #000080;">on</span> <span style="color: #000080;">error</span> <span style="color: #000080;">goto</span> 0
	<span style="color: #000080;">end</span> <span style="color: #000080;">if</span>
<span style="color: #000080;">end</span> <span style="color: #000080;">sub</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.waynezim.com/2009/04/remove-temporary-files-at-logoff/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remote Shutdown / Logoff Script using WMI</title>
		<link>http://www.waynezim.com/2009/04/remote-shutdown-logoff-script-using-wmi/</link>
		<comments>http://www.waynezim.com/2009/04/remote-shutdown-logoff-script-using-wmi/#comments</comments>
		<pubDate>Tue, 21 Apr 2009 13:21:23 +0000</pubDate>
		<dc:creator>Wayne Zimmerman</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Domain]]></category>
		<category><![CDATA[Force]]></category>
		<category><![CDATA[Logoff]]></category>
		<category><![CDATA[Restart]]></category>
		<category><![CDATA[Shutdown]]></category>
		<category><![CDATA[User Accounts]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[VBscript]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://www.waynezim.com/?p=49</guid>
		<description><![CDATA[Have you ever been sitting at your desk working very hard trying to getting some business analytics report finished for your administrative team, only to be interrupted by the everyday user unable to log on the machine because someone else locked it. Then you have to get up and walk down there and manually login [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever been sitting at your desk working very hard trying to getting some business analytics report finished for your administrative team, only to be interrupted by the everyday user unable to log on the machine because someone else locked it. Then you have to get up and walk down there and manually login and unlock the workstation. Well this is now a thing of the past for you if you have enabled WMI and have a domain or common credentials on your network. This script will simply allow you to unlock a workstation with out getting up from your desk. Unfortunately, I didn&#8217;t write this script but I use it about every other day to unlock a workstation. It has a few good options to allow you to either Logoff / Reboot / Shutdown the workstation. This can also be helpful when the user has locked up the PC and can&#8217;t get it to restart, you can send a command from the workstation you are at for that one to restart. In way you end up using this script it will only save you time, I found it to be very reliable and super fast for resolving the locked computer situation. Also, please browse though the code as it is well commented and you can get a greater understanding of how it exactly works.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.waynezim.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=49&amp;download=remoteshutdown.vbs">remoteshutdown.vbs</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4916"><td class="code" id="p49code16"><pre class="vb" style="font-family:monospace;"><span style="color: #008000;">'/'|| Remote Shutdown.vbs
</span><span style="color: #008000;">'||
</span><span style="color: #008000;">'|| Created by Harvey Hendricks, MCSE, A+,
</span><span style="color: #008000;">'|| March 2001
</span><span style="color: #008000;">'||
</span><span style="color: #008000;">'|| email: hhendrks@aramco.com
</span><span style="color: #008000;">'|| hhend@swbell.net
</span><span style="color: #008000;">'||
</span><span style="color: #008000;">'||
</span><span style="color: #008000;">'|| Based on techniques and ideas from:
</span><span style="color: #008000;">'|| SMS admin, SMS Installer, &amp; WMI forums -&gt; http://www.myITforum.com/forums
</span><span style="color: #008000;">'|| Win32 Scripting -&gt; http://cwashington.netreach.net/
</span><span style="color: #008000;">'|| Microsoft Windows Script Technologies -&gt; http://msdn.microsoft.com/scripting
</span><span style="color: #008000;">'|| Microsoft Online Library -&gt; http://msdn.microsoft.com/library/default.asp
</span><span style="color: #008000;">'|| Microsoft VBScript 5.5 documentation
</span><span style="color: #008000;">'|| and Microsoft WMI SDK
</span><span style="color: #008000;">'||
</span><span style="color: #008000;">'||~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
</span><span style="color: #008000;">'|| SCRIPT LOGIC FLOW:
</span><span style="color: #008000;">'|| Collects computername from user, calls function to ping the computername
</span><span style="color: #008000;">'|| to determine if it is accessible, if not then display message and exit
</span><span style="color: #008000;">'|| otherwise continue.
</span><span style="color: #008000;">'|| Collects desired action to perform from the user, does error checking on
</span><span style="color: #008000;">'|| the input to determine if it is acceptable, if not then display message
</span><span style="color: #008000;">'|| and exit otherwise continue.
</span><span style="color: #008000;">'|| Set variables and output messages based on the action chosen. Calls
</span><span style="color: #008000;">'|| Win32Shutdown with the appropriate variable. Displays success message
</span><span style="color: #008000;">'|| and exits
</span><span style="color: #008000;">'||
</span><span style="color: #008000;">'|| Uses WMI Win32Shutdown method from the Win32_OperatingSystem class
</span><span style="color: #008000;">'|| to perform different logoff / powerdown / reboot functions
</span><span style="color: #008000;">'||
</span><span style="color: #008000;">'|| Testing found the following values to be effective on Win32Shutdown:
</span><span style="color: #008000;">'|| Action decimal binary
</span><span style="color: #008000;">'|| Logoff 0 0000
</span><span style="color: #008000;">'|| Force Logoff 4 0100
</span><span style="color: #008000;">'|| Reboot 2 0010
</span><span style="color: #008000;">'|| Force Reboot 6 0110
</span><span style="color: #008000;">'|| Powerdown 8 1000
</span><span style="color: #008000;">'|| Force Powerdown 12 1100
</span><span style="color: #008000;">'||
</span><span style="color: #008000;">'|| Notice that the third bit from the right appears to be the &quot;FORCE&quot; bit.
</span><span style="color: #008000;">'||
</span><span style="color: #008000;">'|| A value of 1 will do a shutdown, ending at the &quot;It is safe to turn
</span><span style="color: #008000;">'|| off your computer&quot; screen. I have no use for this and did not test it.
</span><span style="color: #008000;">'||
</span><span style="color: #008000;">'||
</span><span style="color: #008000;">'||NOTES: - tested under Windows 2000 Pro. with ACPI compliant systems -
</span><span style="color: #008000;">'|| SHOULD work under Windows NT4 without modification IF the
</span><span style="color: #008000;">'|| system has compatible versions of WSH / WMI / VBscripting
</span><span style="color: #008000;">'||
</span><span style="color: #008000;">'||Logoff / Powerdown / Reboot:
</span><span style="color: #008000;">'|| Does not work if a password protected screen saver is active or
</span><span style="color: #008000;">'|| there is data to save. Either way the system waits for user input.
</span><span style="color: #008000;">'||
</span><span style="color: #008000;">'||Force Logoff / Force Powerdown / Force Reboot:
</span><span style="color: #008000;">'|| Does not work if a password protected screen saver is active, will wait
</span><span style="color: #008000;">'|| for user input. Otherwise will close open applications without saving data.
</span><span style="color: #008000;">'||
</span><span style="color: #008000;">'\/~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
</span>
&nbsp;
<span style="color: #008000;">'/\/\/\/\/\/\/\/\/\/\/\/\/\/\ start function /\/\/\/\/\/\/\/\/\/\/\/\/\/'\/\/\/\/\/\/\/\/\/\/\/\/\/\/\______________/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
</span><span style="color: #000080;">function</span> Ping(<span style="color: #000080;">byval</span> strName)
<span style="color: #000080;">dim</span> objFSO, objShell, objTempFile, objTS
<span style="color: #000080;">dim</span> sCommand, sReadLine
<span style="color: #000080;">dim</span> bReturn
&nbsp;
<span style="color: #000080;">set</span> objShell = WScript.CreateObject(<span style="color: #800000;">&quot;Wscript.Shell&quot;</span>)
<span style="color: #000080;">set</span> objFSO = CreateObject(<span style="color: #800000;">&quot;Scripting.FileSystemObject&quot;</span>)
&nbsp;
<span style="color: #008000;">'Set default return value
</span>bReturn = <span style="color: #000080;">false</span>
&nbsp;
<span style="color: #008000;">'Create command line to ping and save results to a temp file
</span>sCommand = <span style="color: #800000;">&quot;cmd /c ping.exe -n 3 -w 1000 &quot;</span> &amp; strName &amp; <span style="color: #800000;">&quot; &gt; temp.txt&quot;</span>
&nbsp;
<span style="color: #008000;">'Execute the command
</span>objShell.run sCommand, 0, <span style="color: #000080;">true</span>
&nbsp;
<span style="color: #008000;">'Get the temp file
</span><span style="color: #000080;">set</span> objTempFile = objFSO.GetFile(<span style="color: #800000;">&quot;temp.txt&quot;</span>)
<span style="color: #000080;">set</span> objTS = objTempFile.OpenAsTextStream(1)
&nbsp;
<span style="color: #008000;">'Loop through the temp file to see if &quot;reply from&quot; is found,
</span><span style="color: #008000;">'if it is then the ping was successful
</span><span style="color: #000080;">do</span> <span style="color: #000080;">while</span> objTs.AtEndOfStream &lt;&gt; <span style="color: #000080;">true</span>
sReadLine = objTs.ReadLine
<span style="color: #000080;">if</span> instr(lcase(sReadLine), <span style="color: #800000;">&quot;reply from&quot;</span>) &gt; 0 <span style="color: #000080;">then</span>
bReturn = <span style="color: #000080;">true</span>
<span style="color: #000080;">exit</span> <span style="color: #000080;">do</span>
<span style="color: #000080;">end</span> <span style="color: #000080;">if</span>
<span style="color: #000080;">loop</span>
&nbsp;
<span style="color: #008000;">'Close temp file and release objects
</span>objTS.<span style="color: #000080;">close</span>
objTempFile.delete
<span style="color: #000080;">set</span> objTS = <span style="color: #000080;">nothing</span>
<span style="color: #000080;">set</span> objTempFile = <span style="color: #000080;">nothing</span>
<span style="color: #000080;">set</span> objShell = <span style="color: #000080;">nothing</span>
<span style="color: #000080;">set</span> objFSO = <span style="color: #000080;">nothing</span>
&nbsp;
<span style="color: #008000;">'Return value
</span>Ping = bReturn
<span style="color: #000080;">end</span> <span style="color: #000080;">function</span>
<span style="color: #008000;">'/\/\/\/\/\/\/\/\/\/\/\/\/\/\ end function /\/\/\/\/\/\/\/\/\/\/\/\/\/'\/\/\/\/\/\/\/\/\/\/\/\/\/\/\______________/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
</span>
&nbsp;
&nbsp;
<span style="color: #008000;">'/\/\/\/\/\/\/\/\/\/\/\ Start Main body of script /\/\/\/\/\/\/\/\/\/\/\/'\/\/\/\/\/\/\/\/\/\/\/\_________________________/\/\/\/\/\/\/\/\/\/\/\/\/
</span><span style="color: #008000;">'Get computer name to operate on
</span>ComputerName=InputBox(<span style="color: #800000;">&quot;Enter the Machine name of the computer&quot;</span> &amp; vbCRLF _
&amp; <span style="color: #800000;">&quot;you wish to Shutdown / Reboot / Logoff&quot;</span>, _
<span style="color: #800000;">&quot;Remote Shutdown / Reboot / Logoff&quot;</span>, _
<span style="color: #800000;">&quot;ComputerName&quot;</span>)
&nbsp;
<span style="color: #008000;">'if Cancel selected - exit
</span><span style="color: #000080;">If</span> (ComputerName = <span style="color: #800000;">&quot;&quot;</span>) <span style="color: #000080;">Then</span> Wscript.Quit
&nbsp;
<span style="color: #008000;">'change the name to uppercase
</span>ComputerName=UCase(ComputerName)
&nbsp;
<span style="color: #008000;">'ping the computername to see if it is accessible
</span>bPingtest = ping(Computername)
&nbsp;
<span style="color: #000080;">If</span> bPingtest = <span style="color: #000080;">FALSE</span> <span style="color: #000080;">Then</span>
y = msgbox (<span style="color: #800000;">&quot;'&quot;</span> &amp; ComputerName &amp; <span style="color: #800000;">&quot;' is not accessible!&quot;</span> &amp; vbCRLF _
&amp; <span style="color: #800000;">&quot;It may be offline or turned off.&quot;</span> &amp; vbCRLF _
&amp; <span style="color: #800000;">&quot;Check the name for a typo.&quot;</span> &amp; vbCRLF, _
vbCritical, ComputerName &amp; <span style="color: #800000;">&quot; NOT RESPONDING&quot;</span>)
Wscript.Quit
<span style="color: #000080;">end</span> <span style="color: #000080;">IF</span>
&nbsp;
<span style="color: #008000;">'Get the action desired
</span>Action=InputBox( _
<span style="color: #800000;">&quot;Select Action to perform on &quot;</span> &amp; ComputerName &amp; vbCRLF &amp; vbCRLF _
&amp; <span style="color: #800000;">&quot; 1 - Logoff&quot;</span> &amp; vbCRLF _
&amp; <span style="color: #800000;">&quot; 2 - Force Logoff ( NO SAVE )&quot;</span> &amp; vbCRLF _
&amp; <span style="color: #800000;">&quot; 3 - Powerdown&quot;</span> &amp; vbCRLF _
&amp; <span style="color: #800000;">&quot; 4 - Force Powerdown ( NO SAVE )&quot;</span> &amp; vbCRLF _
&amp; <span style="color: #800000;">&quot; 5 - Reboot&quot;</span> &amp; vbCRLF _
&amp; <span style="color: #800000;">&quot; 6 - Force Reboot ( NO SAVE )&quot;</span> &amp; vbCRLF &amp; vbCRLF _
&amp; <span style="color: #800000;">&quot;NOTE:&quot;</span> &amp; vbCRLF _
&amp; <span style="color: #800000;">&quot; Using Force will close windows&quot;</span> &amp; vbCRLF _
&amp; <span style="color: #800000;">&quot; without saving changes!&quot;</span>, _
<span style="color: #800000;">&quot;Select action to perform on &quot;</span> &amp; ComputerName, <span style="color: #800000;">&quot;&quot;</span>)
&nbsp;
<span style="color: #008000;">'if Cancel selected - exit
</span><span style="color: #000080;">If</span> (Action = <span style="color: #800000;">&quot;&quot;</span>) <span style="color: #000080;">Then</span> Wscript.Quit
&nbsp;
<span style="color: #008000;">'error check input
</span><span style="color: #000080;">If</span> (INSTR(<span style="color: #800000;">&quot;1234567&quot;</span>,Action)=0) <span style="color: #000080;">OR</span> (Len(Action)&gt;1) <span style="color: #000080;">then</span>
y = msgbox(<span style="color: #800000;">&quot;Unacceptable input passed -- '&quot;</span> &amp; Action &amp; <span style="color: #800000;">&quot;'&quot;</span>, _
vbOKOnly + vbCritical, <span style="color: #800000;">&quot;That was SOME bad input!&quot;</span>)
Wscript.Quit
<span style="color: #000080;">end</span> <span style="color: #000080;">if</span>
&nbsp;
<span style="color: #008000;">' set flag to disallow action unless proper input is achieved, 1 =&gt; go 0 =&gt; nogo
</span>flag = 0
&nbsp;
<span style="color: #008000;">'set variables according to computername and action
</span><span style="color: #000080;">Select</span> <span style="color: #000080;">Case</span> Action
<span style="color: #000080;">Case</span> 1 <span style="color: #008000;">'Logoff
</span>x = 0
strAction = <span style="color: #800000;">&quot;Logoff sent to &quot;</span> &amp; ComputerName
flag = 1
<span style="color: #000080;">Case</span> 2 <span style="color: #008000;">'Force Logoff
</span>x = 4
strAction = <span style="color: #800000;">&quot;Force Logoff sent to &quot;</span> &amp; ComputerName
flag = 1
<span style="color: #000080;">Case</span> 3 <span style="color: #008000;">'Powerdown
</span>x = 8
strAction = <span style="color: #800000;">&quot;Powerdown sent to &quot;</span> &amp; ComputerName
flag = 1
<span style="color: #000080;">Case</span> 4 <span style="color: #008000;">'Force Powerdown
</span>x = 12
strAction = <span style="color: #800000;">&quot;Force Powerdown sent to &quot;</span> &amp; ComputerName
flag = 1
<span style="color: #000080;">Case</span> 5 <span style="color: #008000;">'Reboot
</span>x = 2
strAction = <span style="color: #800000;">&quot;Reboot sent to &quot;</span> &amp; ComputerName
flag = 1
<span style="color: #000080;">Case</span> 6 <span style="color: #008000;">'Force Reboot
</span>x = 6
strAction = <span style="color: #800000;">&quot;Force Reboot sent to &quot;</span> &amp; ComputerName
flag = 1
<span style="color: #000080;">Case</span> 7 <span style="color: #008000;">'Test dialog boxes
</span>y = msgbox(<span style="color: #800000;">&quot;Test complete&quot;</span>, vbOKOnly + vbInformation, <span style="color: #800000;">&quot;Dialog Box Test Complete&quot;</span>)
flag = 0
<span style="color: #000080;">Case</span> <span style="color: #000080;">Else</span> <span style="color: #008000;">'Default -- should never happen
</span>y = msgbox(<span style="color: #800000;">&quot;Error occurred in passing parameters.&quot;</span> _
&amp; vbCRLF &amp; <span style="color: #800000;">&quot; Passed '&quot;</span> &amp; Action &amp; <span style="color: #800000;">&quot;'&quot;</span>, _
vbOKOnly + vbCritical, <span style="color: #800000;">&quot;PARAMETER ERROR&quot;</span>)
flag = 0
<span style="color: #000080;">End</span> <span style="color: #000080;">Select</span>
&nbsp;
<span style="color: #008000;">'check flag
</span><span style="color: #008000;">' if equal 1 (TRUE) then perform Win32Shutdown action on remote PC
</span><span style="color: #008000;">' and display a confirmation message
</span><span style="color: #008000;">' if not equal 1 (FALSE) then skip the action and script ends
</span><span style="color: #000080;">if</span> flag <span style="color: #000080;">then</span>
<span style="color: #000080;">Set</span> OpSysSet=GetObject(<span style="color: #800000;">&quot;winmgmts:{(Debug,RemoteShutdown)}//&quot;</span> _
&amp; ComputerName &amp; <span style="color: #800000;">&quot;/root/cimv2&quot;</span>).ExecQuery( _
<span style="color: #800000;">&quot;Select * from Win32_OperatingSystem where Primary=true&quot;</span>)
<span style="color: #000080;">for</span> <span style="color: #000080;">each</span> OpSys <span style="color: #000080;">in</span> OpSysSet
OpSys.Win32Shutdown(x)
y = msgbox(strAction,vbOKOnly + vbInformation,<span style="color: #800000;">&quot;Mission Accomplished&quot;</span>)
<span style="color: #000080;">next</span>
<span style="color: #000080;">end</span> <span style="color: #000080;">If</span>
&nbsp;
<span style="color: #008000;">'Release objects
</span><span style="color: #000080;">set</span> OpSys = <span style="color: #000080;">nothing</span>
<span style="color: #000080;">set</span> OpSysSet = <span style="color: #000080;">nothing</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.waynezim.com/2009/04/remote-shutdown-logoff-script-using-wmi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Showing Active Directory Location</title>
		<link>http://www.waynezim.com/2009/04/showing-active-directory-location/</link>
		<comments>http://www.waynezim.com/2009/04/showing-active-directory-location/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 15:18:59 +0000</pubDate>
		<dc:creator>Wayne Zimmerman</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Domain]]></category>
		<category><![CDATA[User Accounts]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[VBscript]]></category>

		<guid isPermaLink="false">http://www.waynezim.com/?p=27</guid>
		<description><![CDATA[I have a very simple script for you today that will allow you to configure settings based on where a users and computers are within your Active Directory. This is very helpful when you are determining internet settings, file / printer connections and even desktop icons, but before you do all that you need a [...]]]></description>
			<content:encoded><![CDATA[<p>I have a very simple script for you today that will allow you to configure settings based on where a users and computers are within your Active Directory. This is very helpful when you are determining internet settings, file / printer connections and even desktop icons, but before you do all that you need a simple script to look up what your location / membership is in the directory. It will provide you with at path that is easily searched with string commands and can help diagnose why some users don&#8217;t get all the correct settings. This script returns to popup events, the first one gives you computer location: cn=nameofcomputer,ou=admin,dc=domain,dc=local and user location cn=username,ou=it,dc=domain,dc=local these are the strings you would search to determine who got which settings. Later I will show you how to use these settings to add icons, map drives, and map printers.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.waynezim.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=27&amp;download=ADLocation.vbs">ADLocation.vbs</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2718"><td class="code" id="p27code18"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Set</span> Network = WScript.CreateObject(<span style="color: #800000;">&quot;WScript.Network&quot;</span>)
<span style="color: #000080;">Set</span> objNetwork = CreateObject(<span style="color: #800000;">&quot;WScript.Network&quot;</span>) 
 compname = Network.ComputerName
 domname  = <span style="color: #800000;">&quot;domain&quot;</span>
&nbsp;
 <span style="color: #000080;">Set</span> oNet = CreateObject(<span style="color: #800000;">&quot;Wscript.Network&quot;</span>)
 <span style="color: #000080;">Set</span> oTrans = CreateObject(<span style="color: #800000;">&quot;NameTranslate&quot;</span>)
 oTrans.Init 1, domname
 oTrans.<span style="color: #000080;">Set</span> 3, domname &amp;<span style="color: #800000;">&quot;\&quot;</span>&amp; compname &amp;<span style="color: #800000;">&quot;$&quot;</span>
 sAdsPath = oTrans.<span style="color: #000080;">Get</span>(1)
 <span style="color: #000080;">Set</span> oNet = <span style="color: #000080;">Nothing</span>
 <span style="color: #000080;">Set</span> oTrans = <span style="color: #000080;">Nothing</span>
 sAdsPath = LCase(sAdsPath)
wscript.echo <span style="color: #800000;">&quot;Computer Location: &quot;</span> &amp; sAdsPath
&nbsp;
&nbsp;
<span style="color: #000080;">Set</span> objNetwork = CreateObject(<span style="color: #800000;">&quot;WScript.Network&quot;</span>) 
<span style="color: #000080;">Set</span> objUser = CreateObject(<span style="color: #800000;">&quot;ADSystemInfo&quot;</span>)
<span style="color: #000080;">Set</span> CurrentUser = GetObject(<span style="color: #800000;">&quot;LDAP://&quot;</span> &amp; objUser.UserName)
colGroups = CurrentUser.memberOf
userlocation = lcase(objUser.UserName)
&nbsp;
wscript.echo <span style="color: #800000;">&quot;User Location: &quot;</span>  &amp; userlocation</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.waynezim.com/2009/04/showing-active-directory-location/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Allow Users on Domain to Control Power Settings</title>
		<link>http://www.waynezim.com/2009/04/allow-users-on-domain-to-control-power-settings/</link>
		<comments>http://www.waynezim.com/2009/04/allow-users-on-domain-to-control-power-settings/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 15:55:07 +0000</pubDate>
		<dc:creator>Wayne Zimmerman</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Command Line]]></category>
		<category><![CDATA[Computer]]></category>
		<category><![CDATA[Domain]]></category>
		<category><![CDATA[Group Policy]]></category>
		<category><![CDATA[regexe.ini]]></category>
		<category><![CDATA[Registry]]></category>
		<category><![CDATA[Startup]]></category>

		<guid isPermaLink="false">http://www.waynezim.com/?p=20</guid>
		<description><![CDATA[In some domain environments you need to allow some control back to the users where they can manage it best. A perfect example of this is Power Settings, by default a normal domain user does not have the rights to control the power settings on the PC. This can lead to the computer turning off [...]]]></description>
			<content:encoded><![CDATA[<p>In some domain environments you need to allow some control back to the users where they can manage it best. A perfect example of this is Power Settings, by default a normal domain user does not have the rights to control the power settings on the PC. This can lead to the computer turning off the monitor or going to standby at inopportune times. A way to solve this problem is by modifying the registry so any user authenticated / interactive user can modify these settings. To do this you need to use the regini.exe, it allows you to modify permissions in the registry from command line. Basically anything under registry key: (HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg\) need to be given permissions to be modify by the user. Below I have included some code that needs to be placed in a text file for parameters to pass to regini.exe during workstation start up.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.waynezim.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=20&amp;download=allowpowerconfig.txt">allowpowerconfig.txt</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2020"><td class="code" id="p20code20"><pre class="text" style="font-family:monospace;">HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg [1 5 7 11 17 21]
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg\GlobalPowerPolicy [1 5 7 11 17 21]
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg\PowerPolicies [1 5 7 11 17 21]
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg\PowerPolicies\0 [1 5 7 11 17 21]
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg\PowerPolicies\1 [1 5 7 11 17 21]
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg\PowerPolicies\2 [1 5 7 11 17 21]
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg\PowerPolicies\3 [1 5 7 11 17 21]
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg\PowerPolicies\4 [1 5 7 11 17 21]
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg\PowerPolicies\5 [1 5 7 11 17 21]
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg\ProcessorPolicies [1 5 7 11 17 21]
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg\ProcessorPolicies\0 [1 5 7 11 17 21]
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg\ProcessorPolicies\1 [1 5 7 11 17 21]
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg\ProcessorPolicies\2 [1 5 7 11 17 21]
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg\ProcessorPolicies\3 [1 5 7 11 17 21]
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg\ProcessorPolicies\4 [1 5 7 11 17 21]
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg\ProcessorPolicies\5 [1 5 7 11 17 21]</pre></td></tr></table></div>

<p>Once you have this file made save it Machine Startup Scripts directory for Group Policy. Then add the following entry to the Group Policy (shown below) and the users should now be able to modify their computers power settings.<br /><div id="attachment_21" class="wp-caption alignnone" style="width: 394px"><img src="http://www.waynezim.com/wp-content/uploads/2009/04/regini-gp.gif" alt="Regini.exe with Parameter" title="regini-gp" width="384" height="195" class="size-full wp-image-21" /><p class="wp-caption-text">Regini.exe with Parameter</p></div><br />For more detail on parameters or what exactly regini.exe can do for you hop on over to <a href="http://support.microsoft.com/kb/237607">Microsoft KB 237607</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.waynezim.com/2009/04/allow-users-on-domain-to-control-power-settings/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

