Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


December 01, 1999

Rem


RSS
Subscribe to Windows IT Pro | See More Task Automation Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here

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.)

End of Article



Reader Comments
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

hassan May 02, 2002


You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
CES 2009: Ballmer Announces Windows 7, Windows Live, Live Search Milestones

During his first-ever Consumer Electronics Show (CES) 2009 keynote address last night in Las Vegas, Microsoft CEO Steve Ballmer announced the pending public availability of a feature-complete Windows 7, the final version of Windows Live Essentials, and ...

Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

Where is Microsoft NetMeeting in Windows XP?

...


Task Automation Whitepapers Essential Guide to E-discovery and Recovery for Microsoft Exchange

Continuous Data Protection and Recovery for Microsoft Exchange

Protecting (You and) Your Data with Exchange Server 2007

Related Events Virtualization Forum: Optimizing Storage, Networks, Desktops, and Security

Cloud Computing Forum: Integrating Software, Server and Storage as a Service into Your Enterprise IT Delivery Model

Virtualization Forum: Optimizing Storage, Networks, Desktops, and Security

Check out our list of Free Email Newsletters!

Task Automation eBooks Spam Fighting and Email Security for the 21st Century

A Guide to Windows Certification and Public Keys

Keeping Your Business Safe from Attack: Patch Management

Related Task Automation Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2009 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing