+ Post New Thread
Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
Scripts Thread, vbs file manipulation in Coding and Web Development; Originally Posted by Steve21 Use Write for writing, or writeline for write+newline e.g. objTS.Write "NewStuff" Steve cheers again...
  1. #16


    Join Date
    Mar 2009
    Location
    Leeds
    Posts
    6,591
    Thank Post
    228
    Thanked 856 Times in 735 Posts
    Rep Power
    296
    Quote Originally Posted by Steve21 View Post
    Use Write for writing, or writeline for write+newline

    e.g. objTS.Write "NewStuff"

    Steve
    cheers again

  2. #17

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,765
    Thank Post
    3,274
    Thanked 1,053 Times in 974 Posts
    Rep Power
    365
    @Steve21

    Scratch the previous comment, found this : http://www.computerperformance.co.uk/Logon/WSH_FSO.htm

    To get text into the file, I have selected two methods to append data to the file, WriteLine and Write. WriteLine adds a carriage return and so makes a complete line of text. Whereas write, just adds text but creates no end of line marker.
    Last edited by mac_shinobi; 7th March 2014 at 02:47 PM.

  3. #18


    Join Date
    Mar 2009
    Location
    Leeds
    Posts
    6,591
    Thank Post
    228
    Thanked 856 Times in 735 Posts
    Rep Power
    296
    right got both halves of the script together and working BUT atm if a pc adds its data for a second time it seems to break if its not the last line of the file (so i can run the script on many pcs once and the last pc as many times as i like but if i run it on the first pc in the file the output is odd instead doing a newline it adds the first column to the last column of the privious line then new collums for the rest so the next pc on the same line as the edited one so i end up with

    02:3E,LIB-01,LENOVO,3543B1G,Intel(R) Core(TM) i3-3220 CPU @ 3.30GHz,4 GB,448 GB,381 GB,serial,Microsoft Windows 7 Enterprise ,bought,years,expires,location # 60:6C:66:C8B:8C # F8:0F:41:8D:6F:17 # 60:6C:66:C8B:88,LIB-02,LENOVO,3543B1G,Intel(R) Core(TM) i3-3220 CPU @ 3.30GHz,4 GB,448 GB,380 GB,serial,Microsoft Windows 7 Enterprise ,bought,years,expires,location

    istead of 2 distinct lines

    Code:
    'gather pc info 
    'On Error Resume Next
    'gather pc info v0
    'j stead jan 2014
    Option Explicit
    'setup section
    'generic variables
    
    dim wmi,strComputerName,objWMIService,wshNetwork,colitems
    dim existing,newdata, filenamepath, outputArray, message, found, tobefilled, findstring, headers,objfs,objts
    dim strcontents, arrlines,i
    set WMI = GetObject("winmgmts:\\.\root\cimv2")
    Set wshNetwork = WScript.CreateObject( "WScript.Network" )
    strComputerName = wshNetwork.ComputerName
    
    'mac address variables
    dim macadd, nictype, nad, nads
    set Nads = WMI.ExecQuery("Select * from Win32_NetworkAdapter where physicaladapter=true")
    
    'computer name variables
    dim intMemory,objPhysicalMemory
    
    'ram variables
    dim colPhysicalMemory,ram
    Set objWMIService = GetObject("winmgmts:\\" & strComputerName & "\root\CIMV2") 
    Set colPhysicalMemory = objWMIService.ExecQuery("Select * From Win32_PhysicalMemory")
    
    'pcinfo variables 
    dim pcmake,pcmodel,objitem
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
    
    'cpu variables
    dim colcpu,cpu
    Set colcpu = objWMIService.ExecQuery("Select * from Win32_Processor")
    
    'os variables
    dim colOperatingSystems, operatingsystem, operatingsystemno, objOperatingSystem,splevel,installdate
    Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
    
    'serial no variables
    dim colbios,objbios,serialno
    Set colBIOS = objWMIService.ExecQuery("Select * From Win32_BIOS")
    
    'does stuff
    
    'mac address(s) and nic type
    for each Nad in Nads
        if not isnull(Nad.MACAddress) then 
    		'Wscript.Echo Nad.description, Nad.MACAddress
    		macadd=macadd & " # " & Nad.MACAddress
    		'nictype=nictype & " # " & Nad.description
    	end if
    next 
    nictype=Replace(nictype,",","")
    'wscript.echo macadd," ; " , nictype
    
    'get pc name
    'WScript.Echo "Computer Name: " & strComputerName
    
    'ram
    If Not colPhysicalMemory Is Nothing Then
    	 intMemory = 0
    	 For Each objPhysicalMemory In colPhysicalMemory
    		 intMemory = intMemory + Int(objPhysicalMemory.Capacity)
    	 Next
    	 ram = (intMemory / 1024 / 1024 /1024 ) & " GB"
    	 'wscript.echo ram
    End If
    
    'make-model
    For Each objItem In colItems 
    	pcmake= objItem.Manufacturer
    	pcmake= Replace(pcmake,",","")
    	pcmodel = objItem.Model
    	pcmodel = Replace(pcmodel,",","")
    	'wscript.echo pcmake & " # " & pcmodel
    Next
    
    'cpu
    For Each objItem in colcpu
        cpu = objItem.Name
    	'wscript.echo cpu
    Next
    
    'os
    For Each objOperatingSystem in colOperatingSystems
        operatingsystem = objOperatingSystem.Caption
    	splevel=objOperatingSystem.ServicePackMajorVersion
    	operatingsystemno = objOperatingSystem.Version
    	installdate=objOperatingSystem.InstallDate
    	'wscript.echo "os=" & operatingsystem &" sp= " & splevel & " osnumber " & operatingsystemno & " installed " & installdate
    	Next
    	
    	'serialno
    	If Not colBIOS Is Nothing Then
    	 For Each objBIOS in colBIOS
    		 serialno = objBIOS.SerialNumber
    		 'wscript.echo serialno
    	 Next
    End If
    
    'hdd capacity
    dim objhdd,coldisks, hddcapacity, hddfree
    set coldisks = objWMIService.ExecQuery("Select * From Win32_LogicalDisk")
    for each objhdd in coldisks
    	If objhdd.DeviceID = "C:" Then
    		hddcapacity = int(objhdd.Size/1073741824) & " GB"
    		hddfree = int(objhdd.freespace/1073741824) & " GB"
    		'wscript.echo hddfree
    	end if
    next
    
    newdata = macadd & "," & strComputerName & "," & pcmake & "," & pcmodel & "," & cpu & "," & ram & "," & hddcapacity & "," & hddfree & ","  & serialno &"," & operatingsystem &","
    
    Found="0"
    FindString=macadd
    filenamepath="g:\test\test.csv"
    headers = "mac,name,make,model,cpu,ram size,hdd size,hdd free,serialno,windows version,dop,years warranty,warranty expires,location"
    tobefilled= "bought,years,expires,location"
    
    Set objFS = CreateObject("Scripting.FileSystemObject")
    
    If objFS.FileExists(filenamepath) Then
    	'wscript.echo "file exists"
    else
    	'wscript.echo "no file here"
    	Set objFS = objFS.CreateTextFile(filenamepath)
    	objFS.close
    	Set objFS = CreateObject("Scripting.FileSystemObject")
    	Set objFS = objFS.OpenTextFile(filenamepath, 2)
    	objFS.write headers
    	objFS.close
    end if
    
    Set objFS = CreateObject("Scripting.FileSystemObject")
    
    Set objTS = objFS.OpenTextFile(filenamepath, 1)
    strContents = objTS.ReadAll
    objTS.Close
    
    arrLines = Split(strContents, vbNewLine)
    Set objTS = objFS.OpenTextFile(filenamepath, 2)
    
    For i=0 To UBound(arrLines)
       If instr(arrLines(i),findstring) Then
    	Found="1"
    	outputArray = split(arrLines(i),",")
    	objTS.write NewData & outputArray(10) & "," & outputArray(11) & "," & outputArray(12)& "," & outputArray(13)
       else
    	objTS.Writeline arrLines(i)
       End If
    Next
    
    If Found="0" then
    	objTS.Write newdata & tobefilled
    end if
    wscript.echo "the end?"

  4. #19

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,696
    Thank Post
    335
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    Quote Originally Posted by sted View Post
    right got both halves of the script together and working BUT atm if a pc adds its data for a second time it seems to break if its not the last line of the file (so i can run the script on many pcs once and the last pc as many times as i like but if i run it on the first pc in the file the output is odd instead doing a newline it adds the first column to the last column of the privious line then new collums for the rest so the next pc on the same line as the edited one so i end up with

    02:3E,LIB-01,LENOVO,3543B1G,Intel(R) Core(TM) i3-3220 CPU @ 3.30GHz,4 GB,448 GB,381 GB,serial,Microsoft Windows 7 Enterprise ,bought,years,expires,location # 60:6C:66:C8B:8C # F8:0F:41:8D:6F:17 # 60:6C:66:C8B:88,LIB-02,LENOVO,3543B1G,Intel(R) Core(TM) i3-3220 CPU @ 3.30GHz,4 GB,448 GB,380 GB,serial,Microsoft Windows 7 Enterprise ,bought,years,expires,location

    istead of 2 distinct lines

    Code:
    For i=0 To UBound(arrLines)
       If instr(arrLines(i),findstring) Then
    	Found="1"
    	outputArray = split(arrLines(i),",")
    	objTS.writeline NewData & outputArray(10) & "," & outputArray(11) & "," & outputArray(12)& "," & outputArray(13)
       else
    	objTS.Writeline arrLines(i)
       End If
    Next
    As in that? So it keeps them on seperate lines rather than editting same line?

    Steve

  5. Thanks to Steve21 from:

    sted (12th March 2014)

  6. #20


    Join Date
    Mar 2009
    Location
    Leeds
    Posts
    6,591
    Thank Post
    228
    Thanked 856 Times in 735 Posts
    Rep Power
    296
    cheers i think id tried every concievable way of changing write for writeline but that one

    script now seems to be working fine ive set it as a startup script at one of my schools and will see what happens over the next week or so. Assuming it works like it appears to next project is webifying the csv lol

  7. #21

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,696
    Thank Post
    335
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    Quote Originally Posted by sted View Post
    cheers i think id tried every concievable way of changing write for writeline but that one

    script now seems to be working fine ive set it as a startup script at one of my schools and will see what happens over the next week or so. Assuming it works like it appears to next project is webifying the csv lol
    haha always the way. Can change things a hundred times and it's still one evil one hiding somewhere At least its sorted!

    Steve

  8. #22


    Join Date
    Mar 2009
    Location
    Leeds
    Posts
    6,591
    Thank Post
    228
    Thanked 856 Times in 735 Posts
    Rep Power
    296
    Quote Originally Posted by Steve21 View Post
    haha always the way. Can change things a hundred times and it's still one evil one hiding somewhere At least its sorted!

    Steve
    till i decide it needs to be in powershell for no aparant reason hopefully yes lol

  9. #23


    Join Date
    Mar 2009
    Location
    Leeds
    Posts
    6,591
    Thank Post
    228
    Thanked 856 Times in 735 Posts
    Rep Power
    296
    now even got the web frontend working
    it seems to add random blank lines to the csv but ive decied meh i can either a ignore them or b delete them lol

    pcdata1web.jpg

SHARE:
+ Post New Thread
Page 2 of 2 FirstFirst 12

Similar Threads

  1. Visio Shortcut Opens Multiple VBS Files?
    By DaveP in forum How do you do....it?
    Replies: 0
    Last Post: 14th July 2010, 12:48 PM
  2. Preventing Bat and vbs files
    By BSOD in forum Windows Server 2000/2003
    Replies: 7
    Last Post: 28th January 2010, 06:18 PM
  3. Encrypting VBS files
    By Newton in forum Scripts
    Replies: 2
    Last Post: 28th April 2009, 02:37 PM
  4. Kids Running VBS files
    By tomscaper in forum Scripts
    Replies: 8
    Last Post: 9th January 2008, 12:36 PM
  5. VBS File takes long time to load 1st time?
    By Samson in forum Scripts
    Replies: 3
    Last Post: 4th September 2007, 07:40 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •