Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: System Information Sample Code
vicki perris, Amdahl
; ================================================================= ; ; This script will do the following: ; * if an individual system is selected off the ; menu, either by selecting the current system ; or another individual system by name or ip ; address, this information will be listed: ; system name service pack level ; system IP address bios date ; bios version number of cpu's ; printer shares detail information on each cpu ; file shares user(s) logged on to the system ; what system type this is ; ; ; * if a domain is selected off the menu, this information ; will be listed for the pdc, bdc's, member servers, and ; non-pdc/bdc/server systems: ; system name system IP address ; service pack level bios date ; bios version ; ; for domain summary reports, the user can sort output by ; bios date, host name, or service pack level. ; ; after a report is generated, users can edit or delete ; the report, or append subsequent reports to it. ; ; AddExtender("wwwnt34I.dll") AddExtender("wwsop34I.dll") AddExtender("wwwsk34I.dll") gosub startup :editdisp ; Define the dialog format EditFormat=`WWWDLGED,5.0` EditCaption=`Script ID: System Information` EditX=220 EditY=05 EditWidth=175 EditHeight=190 EditNumControls=25 Edit01=`030,005,090,DEFAULT,STATICTEXT,DEFAULT," System Information Report"` Edit02=`030,020,120,DEFAULT,STATICTEXT,DEFAULT," Produce a report listing information about:"` Edit03=`015,030,050,DEFAULT,RADIOBUTTON,reqtype,"Current System:",1` Edit04=`067,032,090,DEFAULT,STATICTEXT,DEFAULT,"%sysname%"` Edit05=`015,040,090,DEFAULT,RADIOBUTTON,reqtype,"Specify one system by name:",2` Edit06=`105,040,065,DEFAULT,EDITBOX,onesys,""` Edit07=`015,052,090,DEFAULT,RADIOBUTTON,reqtype,"Specify one system by ip address:",3` Edit08=`105,052,065,DEFAULT,EDITBOX,oneipaddr,""` Edit09=`015,065,050,DEFAULT,RADIOBUTTON,reqtype,"Current Domain:",4` Edit10=`067,067,090,DEFAULT,STATICTEXT,DEFAULT,"%domname%"` Edit11=`015,075,090,DEFAULT,RADIOBUTTON,reqtype,"Specify one domain by name:",5` Edit12=`105,075,065,DEFAULT,EDITBOX,onedom,""` Edit13=`015,088,090,DEFAULT,STATICTEXT,DEFAULT,"For domain reports, sort output by:"` Edit14=`105,087,040,DEFAULT,RADIOBUTTON,sortby,"Bios Date",1` Edit15=`105,095,065,DEFAULT,RADIOBUTTON,sortby,"Host Name (default)",2` Edit16=`105,103,080,DEFAULT,RADIOBUTTON,sortby,"Service Pack Level",3` Edit17=`015,113,080,DEFAULT,STATICTEXT,DEFAULT,"Request Status:"` Edit18=`015,120,210,DEFAULT,STATICTEXT,DEFAULT,"%reportstatus%"` Edit19=`015,128,210,DEFAULT,STATICTEXT,DEFAULT,"%filestatus%"` Edit20=`015,134,120,DEFAULT,RADIOBUTTON,rptaction,"Append to last output report created (default)",1` Edit21=`015,144,100,DEFAULT,RADIOBUTTON,rptaction,"Edit last output report created",2` Edit22=`015,154,100,DEFAULT,RADIOBUTTON,rptaction,"Delete last output report created",3` Edit23=`010,166,052,DEFAULT,PUSHBUTTON,DEFAULT,"&Cancel",0` Edit24=`071,166,025,DEFAULT,PUSHBUTTON,DEFAULT,"OK",5` Edit25=`105,166,052,DEFAULT,PUSHBUTTON,DEFAULT,"Reset",100` while @TRUE retval = Dialog("Edit") if retval == "100" gosub resetbuttons endif if rptaction == "3" then goto filedelete if rptaction == "2" then goto fileedit if rptaction == "1" && reqtype != "99" then gosub fileappend rptdate = TimeDate() ; so date is as accurate as possible on each rpt if reqtype == "1" then goto currsys1 if reqtype == "2" then goto onesysbyname if reqtype == "3" then goto onesysbyip if reqtype == "4" || reqtype == "5" then goto rpt1dom reportstatus = "No report type selected. Make a selection then hit enter" gosub resetbuttons endwhile :cancel if IsDefined(output) FileClose(output) endif exit ; =========================================================================== :currsys1 rptsys = sysname if !IsDefined(output) then gosub filenew ; splvl = "" regtouse = "@REGMACHINE" :rpt1 errormode(@off) splvl = RegQueryValue(%regtouse%,"Software\Microsoft\Windows NT\CurrentVersion\[CSDVersion]") if splvl == "0" then splvl = " " sysbiosver = RegQueryMulSz(%regtouse%,"Hardware\Description\System\[SystemBiosVersion]",@TAB) sysbiosdate = RegQueryValue(%regtouse%,"Hardware\Description\System\[SystemBiosDate]") ; ; find each cpu and get a total of all cpus ; cpulist = "" for i = 0 to 7 cpu%i% = RegQueryValue(%regtouse%,"Hardware\Description\System\CentralProcessor\%i%\[Identifier]") if cpu%i% != "0" then cpulist = StrCat(cpulist,cpu%i%,@tab) next numcpus = ItemCount(cpulist,@tab) ; ; find who is logged on to the system ; userson1 = wntCurrUsers("%rptsys%",1) if userson1 != "" numusers = ItemCount(userson1,@tab) userson = ItemSort(userson1,@tab) endif ; ; get file system shares on this system ; sysshares1 = wntResources2("\\%rptsys%",2,1,1,"Microsoft Windows Network") if sysshares1 != "" numshares = ItemCount(sysshares1,@tab) sysshares = ItemSort(sysshares1,@tab) endif ; ; get printer shares on this system ; prtshares1 = wntResources2("\\%rptsys%",2,2,1,"Microsoft Windows Network") if prtshares1 != "" numprtshares = ItemCount(prtshares1,@tab) prtshares = ItemSort(prtshares1,@tab) endif ; errormode(@on) FileWrite(output,"%crlf%===============================================================") FileWrite(output," System Information: %rptsys%") FileWrite(output," Report Time/Date: %rptdate% %crlf%") if ipaddr == "" || splvl == "0" || sysbiosdate == "0" || sysbiosver == "0" FileWrite(output," One or more pieces of system information could not be obtained") FileWrite(output," check system name/type/availability. Must be windows NT system.%crlf%") endif FileWrite(output," IP Address: %ipaddr%") FileWrite(output," Service Pack Level: %splvl%") FileWrite(output," Bios Date: %sysbiosdate%") FileWrite(output," Bios Version: %sysbiosver%") FileWrite(output," Number of CPUs: %numcpus%") for i = 1 to numcpus currcpu = ItemExtract(i,cpulist,@tab) FileWrite(output," CPU%i%: %currcpu%") next ; ; report on who is logged on to the system ; FileWrite(output," %crlf%====================================================================") if userson1 == "" FileWrite(output,"%crlf% No users currently logged on to %rptsys% %crlf%") else FileWrite(output,"%crlf% Domain\Name of users logged on to:") FileWrite(output," %rptsys%%crlf%") for i = 1 to numusers auser = ItemExtract(i,userson,@tab) FileWrite(output," %auser%") next endif ; ; report on system type ; srvrtype = wntServerType("\\%rptsys%") if srvrtype == "4" then srvrtype = "Windows NT " if srvrtype == "3" then srvrtype = "Windows 95/later" if srvrtype == "2" then srvrtype = "Workgroup " if srvrtype == "1" || srvrtype == "0" then srvrtype = "Not Determined " FileWrite(output," %crlf%====================================================================") FileWrite(output,"%crlf% Type of system: %srvrtype%") ; ; report on print shares ; FileWrite(output," %crlf%====================================================================") if prtshares1 == "" FileWrite(output,"%crlf% No print shares offered by %rptsys% %crlf%") else FileWrite(output,"%crlf% Number of print shares offered by %rptsys%: %numprtshares%") FileWrite(output,"%crlf%Print Share Name Associated printer") FileWrite(output,"------------------------------ --------------------------") for i = 1 to numprtshares aptr = ItemExtract(i,prtshares,@tab) ; the share name aptr2 = StrFix("%aptr%"," ",25) ; the share name fixed to 25 chars sleng = StrLen(rptsys) + 4 ; subtract for input to wntshareinfo aptr3 = StrSub(aptr,sleng,StrLen(aptr) ) ; set name for wntshareinfo aptrname = wntShareInfo("%rptsys%","%aptr3%",0,1) ; get 'real resource name ind1 = StrIndexNc(aptrname,",",1, @FWDSCAN) aptrname2 = StrSub(aptrname,1,ind1 - 1) ; run wntShareInfo here to get name of folder ; associated with the share FileWrite(output,"%aptr2% %aptrname2%") next endif ; ; report on file system shares shares ; FileWrite(output," ====================================================================") if sysshares1 == "" FileWrite(output,"%crlf% No file shares offered by %rptsys% %crlf%") else FileWrite(output,"%crlf% Number of file shares offered by %rptsys%: %numshares%") FileWrite(output,"%crlf%Share Name Associated Directory") FileWrite(output,"------------------------------ --------------------------") for i = 1 to numshares ashare = ItemExtract(i,sysshares,@tab) sleng = StrLen(rptsys) + 4 ashare2 = StrSub(ashare,sleng,StrLen(ashare) ) adir = wntShareInfo("%rptsys%","%ashare2%",0,1) adir2 = StrReplace(adir," ","") ashare2 = StrFix("%ashare%"," ",30) ; run wntShareInfo here to get name of folder ; associated with the share FileWrite(output,"%ashare2% %adir2%") next endif reportstatus = "Report complete" gosub resetbuttons ; ============================================================================ ; check to make sure the system name is valid, then go to one-system reporting ; :onesysbyname if StrLen(onesys) == "0" reportstatus = "System name must be specified goto editdisp endif rptsys = onesys if !IsDefined(output) then gosub filenew errormode(@off) ipaddr = wxHost2Addr(onesys) errormode(@on) if StrLen(ipaddr) == "0" reportstatus = "IP address for: %onesys% could not be obtained." goto editdisp endif errormode(@off) regtouse = RegConnect("%onesys%", @REGMACHINE) errormode(@on) if regtouse == "0" reportstatus = "Could not connect to registry on system: %onesys%" goto editdisp endif goto rpt1 ; ============================================================================ ; check to make sure the ip address is valid, then go to one-system reporting ; :onesysbyip if StrLen(oneipaddr) == "0" reportstatus = "IP address must be specified" goto editdisp endif errormode(@off) host = wxAddr2Host(oneipaddr) errormode(@on) if StrLen(host) == "0" reportstatus = "Host name for IP: %oneipaddr% could not be obtained." goto editdisp endif rptsys = host errormode(@off) regtouse = RegConnect("%host%", @REGMACHINE) errormode(@on) if regtouse == "0" reportstatus = "Could not connect to registry on system: %oneipaddr%" goto editdisp endif if !IsDefined(output) then gosub filenew goto rpt1 ; =========================================================================== ; check to make sure domain is valid, then pull information :rpt1dom systypes = "" systext = "" ; could add a dynamic time/date node to these names tfile01 = "c:\temp\SummaryInfo.t1.txt" tfile02 = "c:\temp\SummaryInfo.t2.txt" if reqtype == "4" then domname = Environment("USERDOMAIN") if reqtype == "5" if StrLen(onedom) == "0" reportstatus = "Domain name must be specified" goto editdisp endif domname = onedom endif rptsys = domname if !IsDefined(output) then gosub filenew if sortby == "1" then sortcol = "59" ; sort by bios date if sortby == "2" then sortcol = "1" ; sort by hostname if sortby == "3" then sortcol = "48" ; sort by service pack level astatusbar(0,"Processing..","Starting domain list..","10",0) systypes = StrCat(systypes,"8",@TAB) ; pdc systext = StrCat(systext," Primary Domain Controller",@TAB) systypes = StrCat(systypes,"16",@TAB) ; bdcs systext = StrCat(systext," Backup Domain Controllers",@TAB) systypes = StrCat(systypes,"32768",@TAB) ; non-bdc/pdc servers systext = StrCat(systext," Non-pdc/bdc Servers",@TAB) systypes = StrCat(systypes,"4096",@TAB) ; windows NT either wkstn or server systext = StrCat(systext," NT, non-servers",@TAB) numtypes = ItemCount(systypes,@TAB) fto = FileOpen(tfile01,"WRITE") errormode(@off) dompdc = wntGetDc("","%domname%",1) errormode(@on) if dompdc == "0" reportstatus = "PDC for domain %domname% could not be located" Message("SystemInfo","Domain pdc could not be located, run terminating. %crlf% 'SystemInfo' cannot be run while logged on locally.") astatusbar(2,"Domain %domname%" ,"%currtext%%crlf%%x% of %srvrcount%, Hold down shift key to interrupt",%srvrcount%,%x%) gosub resetbuttons endif :ctlrinfo For i = 1 to numtypes currtype = ItemExtract(i,systypes,@TAB) currtext = ItemExtract(i,systext,@TAB) FileWrite(output,"%crlf%=======================================================================================") FileWrite(output,"Domain: %domname% - %currtext%") FileWrite(output," Report Time/Date: %rptdate% %crlf%") FileWrite(output," System Name IP Address SP Level Bios Date Bios Version%crlf%") servers = wntServerList("%dompdc%","%domname%",%currtype%) srvrcount = ItemCount(servers,@TAB) for x = 1 to srvrcount currsys = ItemExtract(x,servers,@tab) currsyslen = StrLen(currsys) ipquerysys = StrSub(currsys,3,(currsyslen - 2)) ipaddr = wxHost2Addr(ipquerysys) astatusbar(1,"Domain %domname%" ,"%currtext%%crlf%%x% of %srvrcount%, Hold down shift key to interrupt",%srvrcount%,%x%) if IsKeyDown(@SHIFT) Message("%SN%","Listing interrupted by user") FileWrite(output," %crlf% Listing not complete - interrupted by user") astatusbar(2,"Domain %domname%" ,"Processing interrupted",%srvrcount%,%x%) goto endrtn endif errormode(@off) rmtreg = RegConnect("%currsys%", @REGMACHINE) errormode(@on) if rmtreg == "" FileWrite(output,"Could not connect to registry on system %currsys%") goto nextsys endif errormode(@off) splvl = RegQueryValue(rmtreg,"Software\Microsoft\Windows NT\CurrentVersion\[CSDVersion]") if splvl == "0" then splvl = " " sysbiosver = RegQueryMulSz(rmtreg,"Hardware\Description\System\[SystemBiosVersion]",@TAB) sysbiosdate = RegQueryValue(rmtreg,"Hardware\Description\System\[SystemBiosDate]") errormode(@on) if splvl == "" FileWrite(output,"No sp level obtained" goto nextsys endif currsyst = StrSub(currsys,3,17) currsys1 = StrFix("%currsyst%"," ",15) ipaddr1 = StrFix("%ipaddr%"," ",16) splvl1 = StrFix("%splvl%"," ",16) sysbiosdate2 = StrFix("%sysbiosdate%"," ",9) FileWrite(fto," %currsys1% %ipaddr1% %splvl1% %sysbiosdate2% %sysbiosver%") :nextsys next ; srvrcount FileClose(output) FileClose(fto) runhidewait("cmd",'cmd /c "sort /+%sortcol% < %tfile01% > %tfile02%"') FileAppend(tfile02,fn) output = FileOpen(fn,"APPEND") fto = FileOpen(tfile01,"WRITE") next ; numtypes :endrtn astatusbar(2,"Domain %domname%" ,"%currtext%%crlf%%x% of %srvrcount%, Hold down shift key to interrupt",%srvrcount%,%x%) reportstatus = "Report complete" FileClose(fto) FileDelete(tfile01) FileDelete(tfile02) gosub resetbuttons ; =========================================================================== ; setup work ; find this script's place in the universe ; :startup pdc = wntGetDc("","",1) ; obtain primary domain controller sysinfo = WinSysInfo() ; pull current system info sysname = ItemExtract(1,sysinfo,@tab) ; get current system name ipaddr = wxHost2Addr(sysname) ; get current system ip address domname = Environment("USERDOMAIN") ; get current domain cr = Num2Char(13) lf = Num2Char(10) crlf = StrCat(cr,lf) ; set initial variables reportstatus = "" filestatus = "" ; ; reset the dialog buttons and variables ; :resetbuttons reqtype = "99" ; report request type rptaction = "99" ; report action sortby = "2" onedom = "" onesys = "" oneipaddr = "" goto editdisp ; ============================================================================ ; subroutines ; :filedelete ; ; if user wants to delete ; if !IsDefined(output) reportstatus = "No output report to delete" gosub resetbuttons else FileClose(output) FileDelete("%fn%") filestatus = "File %fn% deleted" reportstatus = "No current output report" drop(output,fn) gosub resetbuttons endif ; ; if user wants to edit ; :fileedit if !IsDefined(output) reportstatus = "No output report to edit" gosub resetbuttons else FileClose(output) Runwait("notepad.exe","%fn%") output = FileOpen("%fn%","APPEND") gosub resetbuttons endif ; ; if user wants to append ; :fileappend if !IsDefined(output) filestatus = "No file available to append to" gosub resetbuttons endif return ; ; if user must define an output file ; :filenew fn = AskFileName("SystemInfo.%rptsys%.txt","c:\temp","AllFiles|*.txt","SystemInfo.%rptsys%.txt",0) output = FileOpen("%fn%","WRITE") filestatus = "Output file: %fn%" return
Article ID: W14498
Filename: System Information Reports Menu.txt
File Created: 2001:03:01:12:45:52
Last Updated: 2001:03:01:12:45:52