Solved

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

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
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 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 video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

12 Experts available now in Live!

Get 1:1 Help Now