WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

wNT
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Shutdown All NT Servers


ADSI Example:
sAdsiPath="LDAP://rootDSE"
sValue=dsGetProperty(sAdsiPath,"defaultNamingContext") 
sDomainDNS=StrCat("LDAP://",sValue)
domain=dsGetProperty("LDAP://rootDSE","defaultNamingContext")
sFilter = "(objectCategory=computer)"
sResult = dsFindPath(sDomainDNS, sFilter)
count = ItemCount(sResult,@tab)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;For each computer
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
For i =  1 to count
	sAdsiPath = ItemExtract(i,sResult,@tab)
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	;get computer name
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	sProperty = "name" 
	computer = dsGetProperty(sAdsiPath, sProperty)
	;Message("Debugging",computer)
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	;Ping machine to check if available
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	ret = ipPing(computer,15)
	if ret == 0
		;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
		;Unsuccessful Ping
		;Display Error message
		;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
		err=ipGetLastErr()
		Message(StrCat("Unable to Ping: ", computer),StrCat("Error: ",err))
	else
		;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
		;Successful Ping
		;Force shutdown with 5 second message
		;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
		ErrorMode(@off)
		;ret = wntShutdown( computer, "System is being shut down", 5, @TRUE, @FALSE)
		ErrorMode(@cancel)
		if ret == 0
			err=LastError()
			Message(StrCat("Unable to Shutdown: ", computer),StrCat("Error: ",err))
		endif
	endif
Next
Exit


Windows NT Network Example:

AddExtender("WWWNT34i.DLL");Win32 Network Extender
AddExtender("wwipg34i.dll");IP Grabber Extender

;return a list of all Windows NT (either workstation or server)
servers = wntServerList("","",4096)

;Get machine name only for ping (remove \\)
machinename = StrReplace(machine, "\\","")

;Ping machine to check if available
ret = ipPing(machinename,15)
if ret == 0
  ;Unsuccessful Ping
  ;Display Error message
  err=ipGetLastErr()
  Message(StrCat("Unable to Ping: ", machinename),StrCat("Error: ",err))
else
   ;Successful Ping
	;Force shutdown with 5 second message
	ErrorMode(@off)
	ret = wntShutdown( machine, "System is being shut down", 5, @TRUE, @FALSE)
	ErrorMode(@cancel)
	if ret == 0
		err=LastError()
		Message(StrCat("Unable to Shutdown: ", machine),StrCat("Error: ",err))
	endif
endif
exit

Article ID:   W16522
File Created: 2005:02:18:12:21:14
Last Updated: 2005:02:18:12:21:14