Running a command with Exec (VBScript)

This code can be found in Chapter 11 of Windows Server 2003 Security Cookbook

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the VBScript code from this site.

strServer = ""
strCommand = "netsh dhcp server " & strServer & " set auditlog d:\dhcp\audit"

WScript.Echo "Running command: " & strCommand
WScript.Echo
set objShell = CreateObject("Wscript.Shell")
set objProc  = objShell.Exec(strCommand)

Do
   WScript.Sleep 100
Loop Until objProc.Status <> 0

if objProc.ExitCode <> 0 then
   WScript.Echo "EXIT CODE: " & objProc.ExitCode
   WScript.Echo "ERROR: " & objProc.StdErr.ReadAll
end if

WScript.Echo "OUTPUT: " & objProc.StdOut.ReadAll

This code has been viewed 17513 times.

New from the creators of TechTasks.com: StatSheet.com