?
Solved

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

Posted on 2004-04-22
2
Medium Priority
?
4,216 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
drnick earned 2000 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
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…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

752 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