Bookmark and Share

In this post:

 

What's the Status of VBScript and Windows Script Host?

Hey, Scripting Guy! Question

Hey, Scripting Guy! Are VBScript and Windows Script Host still alive in 2010? Is there any way to get IntelliSense using Visual Studio 2008 for VBScript scripts? In addition, hey, I am not writing an ASP Web page script. All of the Microsoft pages that I see that talk about using Visual Studio for VBScript scripts assume the script has something to do with the Web. I just want IntelliSense and debugging for plain old Windows XP VBScript scripts. I do not want to write the scripts in Notepad.

Moreover, lots of MSDN pages point to the Windows Script Debugger, which doesn’t exist anymore. Nevertheless, because you guys aren’t responsible for all of MSDN, I won’t tell you which ones. I would appreciate any pointers you can send my way.


-- DW

 

Hey, Scripting Guy! AnswerHello DW,

Microsoft Scripting Guy Ed Wilson here. Both VBScript and the Windows Script Host are in maintenance mode. This means there is no new development work being done. The last changes made to VBScript were for Windows XP. The version of VBScript that ships with Windows Vista, Windows Server 2008 and Windows 7 contains no new features to the product. There were some bug fixes. I have never liked using Visual Studio to develop VBScripts. I had a friend that showed me how to do it once, and it was quite painful to make it work correctly and involved writing some macros that were added to custom buttons in Visual Studio. I use a commercial script editor myself, and it works really well. Some free script editors out there have features that support VBScript as well.

The VBScript debugger never worked really well, I use the debugging features from the commercial script editor I have because it works a lot like the debugger in Visual Studio. To be honest, I seldom need any more debugging for my scripts than a simple wscript.echo of a variable value. I tend to write my scripts in functions and subroutines, which makes them both easy to develop and troubleshoot when the occasion arises.

Windows PowerShell 2.0 ships with an ISE (integrated scripting environment) that has good IntelliSense and debugging capabilities.

 


Can I Promote UAC in Windows PowerShell?

Hey, Scripting Guy! Question

Hey, Scripting Guy! Is there a way of promoting UAC in Windows PowerShell? Like the sudo or su command.

 

-- DO

 

Hey, Scripting Guy! AnswerHello DO,

You can do something like the Elevate-Process function seen here.

Elevate-Process function

function elevate-process
{
                $file, [string]$arguments = $args;
                $psi = new-object System.Diagnostics.ProcessStartInfo $file;
                $psi.Arguments = $arguments;
                $psi.Verb = "runas";
                $psi.WorkingDirectory = get-location;
                [System.Diagnostics.Process]::Start($psi);
}
Set-Alias sudo elevate-process

You may also want to take a look at Michael’s power elevation toys


 

Help Me Customize This Script

Hey, Scripting Guy! Question

Hey, Scripting Guy! I read your How Can I Search for and Highlight Words in a Microsoft Word Document post, and I am curious about a small change to it that would make it a bit more functional for my purposes. I have downloaded some sample test questions from the FCC, and wanted to highlight all the lines in the document that end with an "@@" (used to indicate the line with the correct answer for the associated question). I have a couple of questions for you:

·         Can your script be modified to do this?

·         Can the script let me choose the highlight color to be used?

·         Can your script or any new script be made to work on Office for Mac (2008)?


-- ST

 

Hey, Scripting Guy! AnswerHello ST,

Yes I imagine the script can be modified. The line of the code you will need to change is this one:

 arrWords = Array("boldface", "the")

The above line of code looks for two words. The first word one is boldface, and the second word is the word the. If you want to look only for words ending in @@, I would make these changes:

strWordWord = "@@"

    objSelection.Find.Text = strWord
    objSelection.Find.Forward = TRUE
    objSelection.Find.MatchWholeWord = FALSE

    objSelection.Find.Replacement.Highlight = TRUE

    objSelection.Find.Execute ,,,,,,,,,,wdReplaceAll

Note that I got rid of the array and changed the matchwholeword property to false. The color of the highlight is easily modified and is mentioned in the article you referenced. It is copied here:

“Hey, all you had to do was ask. It is actually quite easy to assign a different color to your highlighter. To do that, start by picking a constant and value from the following table:” 

Constant
 Value
 
wdAuto
 0
 
wdBlack
 1
 
wdBlue
 2
 
wdBrightGreen
 4
 
wdByAuthor
 -1
 
wdDarkBlue
 9
 
wdDarkRed
 13
 
wdDarkYellow
 14
 
wdGray25
 16
 
wdGray50
 15
 
wdGreen
 11
 
wdNoHighlight
 0
 
wdPink
 5
 
wdRed
 6
 
wdTeal
 10
 
wdTurquoise
 3
 
wdViolet
 12
 
wdWhite
 8
 
wdYellow
 7
 

Somewhere near the start of your script, define a constant and assign it the corresponding value. To use turquoise, create the constant seen here:

Const wdTurquoise = 3

Then, after you’ve created an instance of the Word.Application object, create an instance of the Options object, assigning the chosen constant to the DefaultHighlightColorIndex property:

Set objOptions = objWord.Options
objOptions.DefaultHighlightColorIndex = wdTurquoise


I am not sure about using VBScript on a Mac because I have never owned one, and I do not have access to one for testing purposes. If the Mac includes the Windows Scripting Host, I imagine you could use the script on a Mac, but it is only a guess. Your best bet would be to test the script as it is currently written before making extensive modifications to it.

 

How Can I Find the Last Logged-On User on a Windows Vista Computer?

Hey, Scripting Guy! Question

Hey, Scripting Guy! I find your site to be very resourceful in my scripting career. I’m looking at your script you provided to help find the Name of the Last User to Log on to a Computer, but this script does not seems to apply to a Windows Vista workstation. I get a result of a blank value for both the DefaultUserName and DefaultDomainName properties. Do you have any ways around that? I’m checking the load of information through WMI on Vista computers in our organization, but cannot locate a similar field that would contain the same information.


-- LG

 

Hey, Scripting Guy! AnswerHello LG,

On my Windows Vista computer, it reports administrator for the user. I cannot tell you when the last time I logged on to the computer as the administrator. There is no WMI class that will provide you “the last person” to log on the computer. You can get current person, but not last person. Take a look at this Hey, Scripting Guy article to see another approach. It uses Windows PowerShell, but if you need VBScript, it could be easily adapted. What I do is create my own registry key. This way I know what is there. You could use such a thing to write username and time if you wish, but be aware in my scenario that I am using HKCU, which will of course change for each user. If you want to write the last user name to HKLM, you will need to modify the rights to the registry key to allow your authenticated user to write to it.

 

Well, this concludes another edition of Quick-Hits Friday. Join us tomorrow for the Weekend Scripter, as we delve into the mysteries of…well we will let that remain a mystery for now.

If you want to know exactly what we will be looking at tomorrow, 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 tomorrow. Until then, peace.

 

Ed Wilson and Craig Liebendorfer, Scripting Guys