Subscribe to Windows IT Pro

 

Get Newsletters

  • Get the Latest News
  • Product Updates
  • Helpful Tricks
  • Productivity Tips

Subscribe Now!

December 01, 1999 12:00 AM

Rem

Windows IT Pro
InstantDoc ID #7707
Rating: (0)
Downloads
7707.zip

Do you have a scripting-related question or problem? You can send your question or problem to bobwells@winntmag.com.

I'm trying to programmatically create a Windows NT workstation computer account using Windows Scripting Host (WSH), VBScript, and Active Directory Service Interfaces (ADSI) 2.5. The new computer account appears in Server Manager for Domains after I run my script. However, when I try to add the workstation to the domain with the Control Panel Network applet, Identification Changes dialog box, I receive an error that reads Unable to connect to the domain controller for this domain. Have your administrator check your computer account on the domain. What am I missing?

You can't add the computer to the domain after running your script because you never set the initial computer account password. The script in Listing 1 demonstrates the process of creating the computer account and setting the initial computer account password. In the script, you need to change the following values to match your environment:

  • DomainName—the name of the domain that will contain the new computer account
  • Administrator—the name of the user account that has sufficient domain privileges to create computer accounts
  • Password—the previous user account's password
  • ComputerName—the name of the new computer account

I need to update an existing desktop shortcut for several thousand users. I used WSH to create the shortcut. Can I use WSH to update the existing shortcut, or do I need to delete the existing shortcut and create a new one?

WSH's Shell object doesn't provide a method to update an existing shortcut. As a result, you need to delete the existing shortcut and create a new one. Unfortunately, the Shell object doesn't provide a method to delete shortcuts either, so you need to use the Microsoft Scripting Runtime library's FileSystemObject to delete the existing shortcut. The example code in Listing 2 demonstrates deleting a desktop shortcut to Notepad. You can modify the example to delete your existing shortcut and then create a new shortcut with the Shell object's CreateShortcut method.

I was reviewing a WSH script that first navigates to a Web site and then uses sinking event subroutines. In this script, the scriptwriter calls Microsoft Internet Explorer (IE) but not the sinking event subroutines. What is activating these subroutines if the scriptwriter never calls them? Is the browser automatically calling them, or are they always present after you load and execute a script?

Similar to the way Windows applications (e.g., Microsoft Office, IE, Visio) can expose a programmable object model, applications can also expose events that represent asynchronous actions the application performs. An application triggers events in response to some other event or circumstance. Sinking events is the process of connecting to a special interface that the application implements. Through this interface, you receive any events that the application fires.

You use the CreateObject's strPrefix parameter to connect to the application's outgoing interface. This optional second parameter identifies a string that the system couples with the event name to call custom event handlers. You subsequently use the string prefix appended with the event name to create a custom event handler (i.e., a subroutine). From that point forward, providing you've defined the custom event handler, the system invokes the subroutine whenever the application fires the corresponding event. If you don't define a custom event handler for an event, the application calls a default handler.

In the case of IE, the system invokes subroutines whenever the application fires an event such as DownloadBegin, DownloadComplete, or DocumentComplete. IE has many intrinsic events, and you can find information about them on the Microsoft Developer Network (MSDN) Online Web Workshop at http://msdn.microsoft.com/ workshop/default.asp. You can find more information about CreateObject's strPrefix parameter in the WSH 2.0 documentation.

I need to manipulate different files, depending on the day of the week. For example, on Monday, I need to delete X files, and on Tuesday, I need to delete Y files. How can I script these file-manipulation tasks?

As Listing 3, page 9, shows, you can use VBScript's Now and DatePart functions in conjunction with a Select Case statement. You first use the Now function to obtain the current date and the DatePart function to return only the day of the week of that date. You then compare the integer that the DatePart function returns to VBScript's seven weekday constants to determine the day of the week. The Select Case statement compares the return value against a list of Case expressions representing the seven weekday constants. When the Select Case statement finds a match, it carries out the file-manipulation task that the Case clause defines. You can use the optional Case Else clause to call an error handler if no match occurs. (For more information about Select Case statements, see Dino Esposito, "Understanding VBScript: Statements," September 1999.)

Related Content:

ARTICLE TOOLS

Comments
  • hassan
    10 years ago
    May 02, 2002

    i am trying to write a program using activestate perl which can fetch a url and open the page in IE.now i want to use the Edit menu options to do SelectAll and Copy.after i Copy i want to Paste in the notepad to get the content. here i don't want to use those htmp parsers.
    i have written the script which opens a webpage but i am not able to automate the menu options. i used win32::setupsup perl module. but it's still not working
    please help

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

White Papers

Get your Windows 7 deployment off to the right start by implementing PC lockdown. A locked-down environment is easier and cheaper to support since users are less likely to make unnecessary changes to the core system configuration - read more here!

Essential Guides

Is your iSCSI "lossy"? The reality is that most off-the-shelf Ethernet hardware deployed for iSCSI can lose packets, resulting in slow performance or application downtime. Learn how to assess your current iSCSI infrastructure and engineer an advanced iSCSI SAN infrastructure.

Web Seminars

What's the best way to keep your network safe from malware? In this web seminar, security expert Greg Shields suggests an alternative method to the traditional blacklisting approach that is common with anti-virus and anti-malware solutions.

eLearning Series

We bring the experts direct to you to share their real-world perspective and expertise. During each event, three sessions stream in real time, so you can learn, ask questions, and get solutions.
Upcoming event: Getting the Most with Exchange 2010 with Paul Robichaux

Subscribe to Windows IT Pro!

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.