Solved

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

Posted on 2004-04-22
2
4,207 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

815 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

8 Experts available now in Live!

Get 1:1 Help Now