Solved

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

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

691 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