Windows scripts

Using the clipboard in WSH

Friday, July 25th, 2008

How to get the text from the clipboard

set objIE = CreateObject(”InternetExplorer.Application”)
objIE.Navigate(”about:blank”)
textFromClipboard = objIE.document.parentwindow.clipboardData.GetData(”text”)
objIE.Quit
WScript.Echo textFromClipboard

How to put the text into clipboard

textIntoClipboard = “Some text” & VbCrLf & “Some more text”
 
Set objIE = WScript.CreateObject(”InternetExplorer.Application”)
objIE.Navigate “about:blank”
Do Until objIE.ReadyState = 4
        WScript.Sleep 100
Loop
 
objIE.document.ParentWindow.ClipboardData.SetData “text”, textIntoClipboard
objIE.Quit

The detailed explanation could be found here.

Office: check if PowerPoint is running

Sunday, January 20th, 2008

Dim objAPP, sMsg
On Error Resume Next
Set objAPP = GetObject(, “PowerPoint.Application”)
If TypeName(objAPP) = “Empty” Then
    sMsg = “not started”
Else
    sMsg = “started”
End If
MsgBox “PowerPoint is ” & sMsg, vbInformation, “PowerPoint”
if sMsg = “started” then objAPP.Visible = true

WMI: list of the methods and properties

Saturday, January 19th, 2008

strComputer = “.”
Set objWMIService=GetObject(”winmgmts:{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2″)
 
For Each objclass in objWMIService.SubclassesOf()
    intCounter=0
    If Left(objClass.Path_.Class,5) = “Win32″ Then
        For Each Qualifier in objClass.Qualifiers_
            If UCase(Trim(Qualifier.Name)) = “ASSOCIATION” Then
                intCounter = 1
            End If
  [...]

WMI: get the information about the system

Thursday, January 17th, 2008

Option Explicit
On Error Resume Next
Dim strComputer, objWMIService
Dim colItems, objItem
strComputer = “.”
Set objWMIService = GetObject(”winmgmts:{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2″)
Set colItems = objWMIService.ExecQuery (”Select * from Win32_OperatingSystem”)
For Each objItem in colItems
WScript.Echo “Machine Name: ” & objItem.CSName & VbCr & _
“===================================” & vbCr & _
“Description: ” & objItem.Description & VbCr & _
“Manufacturer: ” & [...]

WMI+VBS: how to get the domain name

Monday, January 14th, 2008

Option Explicit
On Error Resume Next
Dim strComputer, objNetwork, objWMIService
Dim colItems, objItem
Set objNetwork = WScript.CreateObject(”WScript.Network”)
strComputer = objNetwork.ComputerName
WScript.Echo “Computer = ” & strComputer
Set objWMIService = GetObject(”winmgmts:{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2″)
Set colItems = objWMIService.ExecQuery (”Select * from Win32_ComputerSystem”)
For Each objItem in colItems
 Wscript.Echo “Domain = ” & objItem.domain
Next

There is also WMI FAQ on Microsoft site.

WHERE command for DOS

Thursday, August 23rd, 2007

If You need the analog of Unix ‘which’ command and do not have Resource Kit, the following batch file will help.
The code was found on www.ss64.com
Published with the permission of the author, Clay Calvert.
@echo off
SETLOCAL
(set WF=)
:: Look for file in the current directory
for %%a in (”" %PATHEXT:;= %) do (
if not defined WF if exist [...]

Start sqlplus in Windows .BAT script

Monday, February 6th, 2006

Here is the example of emulating “HERE-documents” in Windows shell.
@ECHO OFF
FIND “/*%none% some_label”

Keep on coding