Solved

Call Batch File or run DOS Command from VB/WMI Script?

Posted on 2004-04-22
2
4,206 Views
Last Modified: 2013-12-03
Hi,

I wrote a WMI Script that renames/ip's a computer per its Mac Address and want to know if there is a way to call a batch file using VB/WMI?  I want the script to call the Netdom command so I can add the computers to the domain and then have the script reboot.  I found some code that adds a computer to the domain; however, it doesn't seem to work well with our setup.  The netdom utility seems to work a lot better.

Also, if possible, can the WMI script delete the batchfile after it runs it and possibly delete itself before rebooting?

I have little to no knowledge in programming, so any help will be appreciated!

Thanks!
0
Comment
Question by:jkrech17
2 Comments
 
LVL 5

Accepted Solution

by:
drnick earned 500 total points
ID: 10896295
i have no clue to wmi,
but know vb by name,

i think in vb you can import the ShellExecute api and run it.

Private Declare Function ShellExecute _
    Lib "shell32.dll" Alias "ShellExecuteA" ( _
    ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long

you can then also use shellexecute to run "del mybat.bat"

i hope that helped,
for further info on shellexecute you can lookup msdn,
drnick
0
 

Author Comment

by:jkrech17
ID: 10896699
Hi -- you led me in the right direction -- here is what worked in WMI

set objWMIService = GetObject("winmgmts://" & Computer)
set objShell = WScript.CreateObject("WScript.Shell")
  objShell.Run"cmd.exe /C test.bat", 1, TRUE


Thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Save copy of document in Word 4 74
display png images in VB6 4 381
Slow process to read Excel 15 113
File Watcher and Deleter with Email notification 5 92
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now