vbscript - VB Scripting to excel -
i desk technical @ company , trying create vb login script gather various things user , computer , create or amend excel spread sheet on network drive. little background programming, not programmer. knowledge limited understand programming logic. far have been able frankenstein vbs script various sources online of own programming. here snag. want list of network drives of user single cell within excel. i've tried no success.
closest can listing 1 (the last) network drive. other issue i've been having not list of member of groups ad. know super novice willing learn , understand. great! here code:
set wshshell = wscript.createobject("wscript.shell") set objargs = wscript.arguments set fso = createobject("scripting.filesystemobject") set oshell = createobject("wscript.shell") set env = oshell.environment("process") strcomputer = env.item("computername") set objexcel = createobject("excel.application") objexcel.visible = true set objworkbook = objexcel.workbooks.add() set objworksheet = objworkbook.worksheets(1) objexcel.worksheets(2).delete objexcel.worksheets(2).delete objexcel.activeworkbook.windows(1).caption = outputfile strout = "" getosinfo sub getosinfo() on error resume next objexcel.worksheets(1).activate objexcel.worksheets(1).name = "computer info" objexcel.cells(1, 1).value = "computer name" objexcel.cells(2, 1).value = "computer name system" objexcel.cells(3, 1).value = "ip(s) system" objexcel.cells(4, 1).value = "logon name" objexcel.cells(5, 1).value = "operating system" objexcel.cells(6, 1).value = "last bootup time" objexcel.cells(7, 1).value = "install date" objexcel.cells(8, 1).value = "manufacturer" objexcel.cells(9, 1).value = "serial number" objexcel.cells(10, 1).value = "model" objexcel.cells(11, 1).value = "mapped drives" objexcel.cells(12, 1).value = "member of group(s)" objexcel.cells(13, 1).value = "amt. of storage allocated" objexcel.cells(14, 1).value = "# of processors" objexcel.cells(15, 1).value = "processor type" objexcel.cells(16, 1).value = "memory (gb)" colvar=2 set objwmiservice = getobject("winmgmts:" & "{impersonationlevel=impersonate}!\\" & strcomputer & "\root\cimv2") if err.number <> 0 objexcel.cells(1, colvar).value = strcomputer objexcel.cells(2, colvar).value = "error # " & cstr(err.number) & " " & err.description printout "error # " & cstr(err.number) & " " & err.description colvar = colvar+1 err.clear else objexcel.activeworkbook.windows(1).caption = "getting win32_operatingsystem " & strcomputer set coloperatingsystems = objwmiservice.execquery ("select * win32_operatingsystem") objexcel.activeworkbook.windows(1).caption = "getting win32_bios " & strcomputer set colbios = objwmiservice.execquery ("select * win32_bios") objexcel.activeworkbook.windows(1).caption = "getting win32_computersystem " & strcomputer set colcomputersystem = objwmiservice.execquery ("select * win32_computersystem") objexcel.activeworkbook.windows(1).caption = "getting win32_networkadapterconfiguration " & strcomputer set colnetworkadapterconfiguration = objwmiservice.execquery ("select * win32_networkadapterconfiguration") objexcel.activeworkbook.windows(1).caption = "getting win32_mappedlogicaldisk " & strcomputer set objnetwork = wscript.createobject("wscript.network") objexcel.activeworkbook.windows(1).caption = "getting win32_processor info " & strcomputer set colproc = objwmiservice.execquery("select * win32_processor") each objos in coloperatingsystems objexcel.activeworkbook.windows(1).caption = "setting computer name " & strcomputer objexcel.cells(1, colvar).value = strcomputer objexcel.activeworkbook.windows(1).caption = "setting last boot time " & strcomputer set dtmconverteddate = createobject("wbemscripting.swbemdatetime") dtmconverteddate.value = objos.installdate dtminstalldate = dtmconverteddate.getvardate objexcel.cells(7, colvar).value = dtminstalldate temparray = split(objos.name, "|") objexcel.cells(6, colvar).value = temparray(0) dtmconverteddate.value = objos.lastbootuptime dtmboottime = dtmconverteddate.getvardate objexcel.cells(5, colvar).value = dtmboottime next each objbios in colbios objexcel.activeworkbook.windows(1).caption = "setting bios info " & strcomputer objexcel.cells(9, colvar).value = objbios.serialnumber next each objcs in colcomputersystem objexcel.activeworkbook.windows(1).caption = "setting manufacturer info " & strcomputer objexcel.cells(8, colvar).value = objcs.manufacturer objexcel.activeworkbook.windows(1).caption = "setting model info " & strcomputer objexcel.cells(10, colvar).value = objcs.model objexcel.activeworkbook.windows(1).caption = "setting name wmi " & strcomputer objexcel.cells(2, colvar).value = objcs.name objexcel.activeworkbook.windows(1).caption = "setting total physical memory " & strcomputer objexcel.cells(16, colvar).value = round(objcs.totalphysicalmemory/1024/1024/1024,2) next each objnetadapter in colnetworkadapterconfiguration objexcel.activeworkbook.windows(1).caption = "getting ip addresses " & strcomputer ipaddress = objnetadapter.ipaddress = 0 ubound(ipaddress) if iplist = "" iplist = ipaddress(i) else iplist = iplist & ", " & ipaddress(i) end if next objexcel.cells(3, colvar).value = iplist next set coldrives = objnetwork.enumnetworkdrives = 0 coldrives.count-1 step 2 objexcel.cells(11, colvar).value = coldrives.item(i) & vbtab & coldrives.item (i + 1) next err.clear struser = strcomputer & "$" objexcel.activeworkbook.windows(1).caption = "getting ad group info " & strcomputer set objroot = getobject("ldap://rootdse") defaultnc = objroot.get("defaultnamingcontext") computerdn = finduser(struser, defaultnc) ouarray = split(computerdn,",") = 1 ubound(ouarray) if ou = "" ou = ouarray(i) else ou = ou & "," & ouarray(i) end if next set objwmi = getobject("winmgmts:\\" & strcomputer & "\root\cimv2") set colitems = objwmi.execquery("select * win32_computersystem") each objitem in colitems strusers = objitem.username next objexcel.cells(4, colvar).value = strusers 'ou set dicseengroup = createobject("scripting.dictionary") strgroups = displaygroups(computerdn,"",dicseengroup) arygroups = split(strgroups,"cn=") strgroups = "" = 2 ubound(arygroups) strgroups = strgroups & ", " & arygroups(i) next objexcel.cells(12, colvar).value = right(strgroups,len(strgroups) -2) err.clear stroutput = getdrivelettersandsize(strcomputer) objexcel.cells(13, colvar).value = left(stroutput,len(stroutput)-2) proccount = 0 objexcel.activeworkbook.windows(1).caption = "setting number of processors " & strcomputer each processor in colproc proccount = proccount + 1 procname = processor.name next objexcel.cells(14, colvar).value = proccount objexcel.cells(15, colvar).value = trim(procname) strout = "" iplist = "" ou = "" colvar = colvar+1 end if objexcel.cells.select objexcel.cells.entirecolumn.autofit objexcel.range("b2").select objexcel.activewindow.freezepanes = true objworksheet.columns("b:b").horizontalalignment = -4131 objexcel.activeworkbook.windows(1).caption = "finished gathering computer info" end sub function finduser(byval username, byval domain) on error resume next set cn = createobject("adodb.connection") set cmd = createobject("adodb.command") set rs = createobject("adodb.recordset") cn.open "provider=adsdsoobject;" cmd.activeconnection=cn cmd.commandtext="select adspath 'ldap://" & domain & "' samaccountname = '" & username & "'" set rs = cmd.execute if err<>0 finduser="error connecting active directory database:" & err.description 'wscript.quit else if not rs.bof , not rs.eof rs.movefirst finduser = rs(0) else finduser = "not found" end if end if cn.close end function function displaygroups ( strobjectadspath, strspaces, dicseengroup) set objobject = getobject(strobjectadspath) 'strout must global variable strout = strout & strspaces & objobject.name on error resume next ' doing avoid error when memberof empty if isarray( objobject.get("memberof") ) colgroups = objobject.get("memberof") else colgroups = array( objobject.get("memberof") ) end if each strgroupdn in colgroups if not dicseengroup.exists(strgroupdn) dicseengroup.add strgroupdn, 1 displaygroups "ldap://" & strgroupdn, strspaces & " ", dicseengroup end if next err.clear displaygroups = strout end function function getdrivelettersandsize(strcomputer) on error resume next set objwmiservice = getobject("winmgmts://" & strcomputer & "/root/cimv2") if err.number getdrivelettersandsize = "error # " & cstr(err.number) & " " & err.description & " " err.clear else on error goto 0 set colitems = objwmiservice.execquery("select * win32_logicaldisk drivetype=3", , 48) each objitem in colitems getdrivelettersandsize = getdrivelettersandsize & objitem.name & " " & round(getdrivesizetotal(strcomputer,objitem.name)/1024/1024/1024,2) & "gb, " next end if end function function getdrivesizetotal(strcomputer, drvletter) on error resume next set objwmiservice = getobject("winmgmts://" & strcomputer & "/root/cimv2") strtemp = strcomputer if err.number getdrivesizetotal = "0" err.clear else on error goto 0 set colitems = objwmiservice.execquery("select * win32_logicaldisk drivetype=3", , 48) each objitem in colitems if ucase(objitem.name) = ucase(drvletter) getdrivesizetotal = objitem.size end if next end if end function
i don't intend work through code shall concentrate on question:
i want list of network drives of user single cell within excel.
you use string concatenation ampersand & operator:
range("a1").value = range("a1").value & " " & "c:"
replace "c:" whatever variable contains current drive letter.
Comments
Post a Comment