Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

Windows Management Instrumentation (WMI)


Recommended Posts

Not sure if any of you VBS/IT guys have played with the Windows Management Instrumentation (WMI) for XP but it's pretty powerful stuff, below is a real simple example. I added some links to MSDN for more WMI info to wet your scripting appetites!

 

code:

'///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

'//

'// Author: Mick George [email protected]

'// Date: 09/12/2003 10:09 PM

'// File Name: WMI Enumerate MC9.vbs

'//

'// Description: Enumerate All MC9 files in selected folder using Windows Management Instrumentation (WMI)

'//

'// Comments: This script runs under WinXP and Windows 2003 Server (download needed for Win98/WinNT)

'//

'//

'//

'//

'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 

 

Const DEF_LOCALHOST = "."

 

' -- Start Script

Call Main()

 

 

' ////////////////////

' Sub Declaration

' ////////////////////

Sub Main()

 

Dim colFiles, objWMIService, objFile, objFolder

Dim strSearchPath, strSQL

 

' -- Prompt for a folder

objFolder = BrowseEx

 

' -- OK?

If objFolder = vbNullString Then Exit Sub

 

' -- Format it

objFolder = Replace(objFolder, "", "")

 

' -- Remove drive letter, really needs more validation

If InStr(2, objFolder, ":") > 0 Then objFolder = Mid(objFolder, 3, 999)

 

' -- Make a connection

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!" & DEF_LOCALHOST & "rootcimv2")

 

' -- Build SQL

strSQL = "Select * from CIM_DataFile where path = '" & objFolder & "'"

 

' -- Get our files collection

Set colFiles = objWMIService.ExecQuery(strSQL)

 

' -- Ask

If colFiles.Count = 0 Then

ShowString "No files in selected folder"

Exit Sub

Else

If askYesNo(colFiles.Count & " found in folder, do you want to continue?") = mcMSG_NO Then Exit Sub

End If

 

' -- Iterate all files

For Each objFile In colFiles

If Right(UCase(objFile.Name), 4) = ".MC9" Then

If Not OpenMC(objFile.Name) Then

ShowString "Failed to open drawing " & objFile.Name

Else

Call NewMC(False)

End If

End If

Next

 

 

End Sub

 

 

Public Function BrowseEx

 

Const WINDOW_HANDLE = 0

Const NO_OPTIONS = 0

 

Dim objShell, objFolder, objFolderItem

 

Set objShell = CreateObject("Shell.Application")

 

On Error Resume Next

Set objFolder = objShell.BrowseForFolder (WINDOW_HANDLE, "Select a folder:", NO_OPTIONS, "Desktop")

 

Set objFolderItem = objFolder.Self

 

If Err Then

Set BrowseEx = vbNullString

Err.Clear

Exit Function

End If

 

BrowseEx = objFolderItem.Path

 

 

End Function

 

[ 12-11-2003, 04:11 PM: Message edited by: Mick from CNC Software, Inc. ]

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...