Bookmark and Share

In this post:

 

How Can I Change the Internet Explorer Title Bar?

Hey, Scripting Guy! Question

Hey, Scripting Guy! In which programming language should I write to change the Internet Explorer title bar?


-- NN

Hey, Scripting Guy! Answer

Hello NN,

You can use VBScript, Jscript, Windows PowerShell, or anything you wish. For Internet Explorer, you can add the following registry key:

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main

This registry key is seen in the following image:

Image of the registry key

In Windows 7 this registry key already exists, and you can simply modify it. In Windows XP, you will need to add the key. Because of your e-mail, I wrote a Windows PowerShell script that will change the Internet Explorer title. I posted the Modify Title of Internet Explorer script in the TechNet Script Center Gallery.

 

How Can I Create a Password Based on the User's First Name and Last Name?

Hey, Scripting Guy! Question

Hey, Scripting Guy! You have answered this question before: How Can I Set a User’s Password and Then Require Them to Change That Password the Next Time They Log On? How about this variation: How can I set a first-use password for all 600 new students (users) in the 4th grade organizational unit (OU) and then require them to change that password the next time they log on? I would like for the first-use password to be “FirstInitial”“LastInitial”

I am sure there is an answer, and I wish I had time to figure it out all by myself.


-- WB

 

Hey, Scripting Guy! Answer

Hello WB,

Using the article, you will need to modify the section of the code seen here:

objUser.SetPassword objUser.sAMAccountName

What you will need to do is to retrieve their first name, and then store it in a variable. Then do the same thing with the last name.

The first name is called GivenName, and the last name is called SN. So the code would look like this:

firstName = objUser.GivenName
lastName = objUser.SN

Now you need to use the Mid function from VBScript to retrieve the first initial. The Mid function is talked about on MSDN. Here is a script I wrote that illustrates using the Mid function:

CreatePasswordFromInitials.vbs

'==========================================================================
'
'
' NAME: CreatePasswordFromInitials.vbs
'
' AUTHOR: ed wilson , MrEd
' DATE  : 9/30/2009
'
' COMMENT:
'
'==========================================================================

firstName = "Ed"
lastName = "Wilson"
fi = Mid(firstName,1,1)
li = Mid(lastName,1,1)
password = fi + li
WScript.Echo password

 

How Can I Bail Out a For...Next Loop When the Number 15 Is Reached?

Hey, Scripting Guy! Question

Hey, Scripting Guy! How do I tell a For loop to cycle through the numbers 1–20, but to exclude the number 15? I have tried so many variants. Please help! To help you out, I am listing some of the things I tried that did not work.

For i = 1 to 20 Not 15

For i = 1 to14 & 16 to 20

For i = 1 to 20 <> 15

For I = 1 to 20 SKIP 15


-- CW

Hey, Scripting Guy! Answer

Hello CW,

You cannot directly do this. Inside your For loop, what you will need to do is place an If statement that tests for the value of your iterator i in your example. If i is equal to 15, then skip your code inside the loop. On second thought, an easier approach is to test for the value of i at the bottom of your loop. If i is equal to 14, then i equals 15. The really cool part of the Skip15.vbs script is that the For statement automatically increments the iterator by 1. If you set the value of i to 16, the script will skip two numbers. The Skip15.vbs script is seen here.

Skip15.vbs

For i = 1 To 20
 WScript.Echo i
 If i = 14 Then i = 15
Next

When the Skip.15.vbs script is run, the following results are seen:

Image of results of running the script

 

 

How Can I Modify an Executable File's Compatibility Check?

Hey, Scripting Guy! Question

  Hey, Scripting Guy!  Could you tell me if it's possible to modify an “executable file” compatibility attribute, “Run this program as an administrator”? If so, what may the object name be called?


-- CC

Hey, Scripting Guy! Answer

 Hello CC, I do not think you can do this by using standard scripting techniques. However, by using Orca you might be able to do what you need. You should also take a look at the application compatibility tool kit. A new one is made for each version of the OS.  The one for Windows 7 is already available.


 

How Can I Check for Open TCP Ports on a Remote Host?

Hey, Scripting Guy! Question

Hey, Scripting Guy! I have a scenario where I need to check whether the destination TCP ports are accessible from a remote system.

I am looking for a script that will take the list of host name and port as input, and check if the ports are accessible by using Telnet to the specific TCP port. I have this script in UNIX; however, I am not familiar with performing the same in Windows. I am sending you my UNIX script to give you a better idea of what I am trying to accomplish.

è

#!/bin/ksh

for i in `cat servers.txt`

do

HOST=$(echo ${i}|awk -F: '{print $1}')

PORT=$(echo ${i}|awk -F: '{print $2}')

echo | telnet $HOST $PORT

done

è


-- RK

 

Hey, Scripting Guy! Answer

Hello RK,

On Windows XP you can do this using the NetDiagnostics WMi class. I just uploaded a script to the TechNet Script Center Gallery that I wrote while I was teaching a VBScript class in Mexico City.

 

 

How Can I Check for the Drive Letter of a CD-ROM?

Hey, Scripting Guy! Question

Hey, Scripting Guy! First of all, I love the Scripting Guy and the way he writes!! He has a great sense of humor!!! The script from this Hey Scripting Guy article does not return the CD drive letter (like it says it does) but rather the "C:\" drive every time, no matter which PC I put the CD into. Any ideas why?

-- JW

Hey, Scripting Guy! Answer

Hello JW, I am glad you like the sense of humor. That script does not return the drive of the CD-ROM necessarily. It returns the drive letter from which the script was launched. In the e-mail from RKG, his script was on a CD-ROM and he wanted to know the drive letter where the script was runningin his case the CD-ROM.

If you are running the script from your C: drive, it will always return C:. If you are running it from your D: drive, the script will always return D:. If you have it on a portable USB drive, and do not know what the drive letter is, it will tell you. This is in fact the purpose of the script: to tell you from where the script is being launched. It is useful in situations when, for instance, you have the script on a USB drive and want to copy files from your computer to the USB drive, but you do not know the letter of the USB drive. You would include this code at the top of your script to obtain the drive letter of the USB drive, and then begin your copy operation. For simply determining the drive letter of your CD-ROM drive, you could use this script from the Script Gallery.

 

How Can I Remotely Acces a COM Object? 

Hey, Scripting Guy! Question

Hey, Scripting Guy! Is there a way to access COM objects remotely? I've been Binging around for hours and not finding any help on the Web. The code seen here works fine when I run it locally. However, I am trying to run the code remotely on servers that do not have Windows PowerShell at this time. Here is the code:

$NetworkConnectionsMask = 0x31

$Shell = New-Object -com shell.application $NetworkConnections = $Shell.Namespace($NetworkConnectionsMask)

$NetworkConnections.Items() | where {

[body]


-- DL

Hey, Scripting Guy! Answer

 Hello DL, Your code will not work remotely. There is no way to access COM objects remotely with Windows PowerShell. In Windows PowerShell 2.0, you will be able to run the script remotely, but it’s not possible in Windows PowerShell 1.0.

 

Well, we have reached the end of this week's Quick-Hits Friday post. It also ends our week of Hey, Scripting Guy! posts.

If you want to know exactly what we will be scripting next week, follow us on Twitter or Facebook. If you have any questions, send e-mail to us at scripter@microsoft.com or post your questions on the Official Scripting Guys Forum. See you next week. Have an awesome weekend. Take care, and we look forward to seeing you on Monday.


Ed Wilson and Craig Liebendorfer, Scripting Guys