+ Post New Thread
Results 1 to 2 of 2
Scripts Thread, Tidy Script Up in Coding and Web Development; Basically collates all the info I require, appends said info to a text file, changes the file extension to a ...
  1. #1

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,849
    Thank Post
    3,365
    Thanked 1,062 Times in 982 Posts
    Rep Power
    366

    Tidy Script Up

    Basically collates all the info I require, appends said info to a text file, changes the file extension to a csv file.

    Currently no checks regards to directory to ensure there is a directory named logs ( that is easy enough to do )

    Is there anyway of tidying this up etc

    Code:
    const HKEY_CURRENT_USER = &H80000001const HKEY_LOCAL_MACHINE = &H80000002
    Const ForReading = 1, ForWriting = 2, ForAppending = 8 
    strComputer = "."
    Set StdOut = WScript.StdOut
    Dim username, Model, serial, asset, hdd, manu
    Dim strRAM
    dim filesys, filetxt
    Dim usbPath, FullPath
    Set objNetwork = CreateObject("Wscript.Network")
    username = objNetwork.username
    strComputer = objNetwork.ComputerName
    usbPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "")
    FullPath = usbPath & "logs\"
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
    For Each Item In colItems
    manu = Item.Manufacturer
        model = Item.Model
    Next
    Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS")
    For Each objItem in colItems
        serial = objItem.SerialNumber
       
    Next
    
    
    Set colItems = objWMIService.ExecQuery("Select * from Win32_SystemEnclosure")
    For Each objItem in colItems
        asset =  objItem.SMBIOSAssetTag
    Next
    
    
    Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
    
    
    strKeyPath = "HARDWARE\DESCRIPTION\System\CentralProcessor\0"
    strValue = "ProcessorNameString"
     
    objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValue,strScriptStatus
    
    
    
    
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemory",,48)
    For Each objItem in colItems
    strRAM = FormatNumber((objItem.Capacity/1048576)/1024,2) & " Gb RAM"
    
    
       
    Next
    
    
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk")
    For Each objDisk in colDisks
         
    If objDisk.DeviceID = "C:" Then
        Select Case objDisk.DriveType
            Case 3
    			hdd = Int(objDisk.Size/1073741824) & " Gb"
        End Select
    	End If
    Next
    
    
    
    
    Set filesys = CreateObject("Scripting.FileSystemObject")
    Set filetxt = filesys.OpenTextFile(FullPath & ucase(username) & ".txt" , ForAppending, True) 
    filetxt.WriteLine "Username,Manufacturer,Serial Number,Model,Computer Name,RAM,HDD,Asset Tag,Processor"
    filetxt.WriteLine ucase(username) & "," & manu & "," & serial & "," & model & "," & strComputer & "," & strRAM & "," & hdd & "," & asset & "," & strScriptStatus
    filetxt.Close 
    
    
    msgbox ucase(username) & vbcrlf & manu & vbcrlf & model & vbcrlf & serial & vbcrlf & asset & vbcrlf & vbcrlf & strComputer & vbcrlf & strScriptStatus & vbcrlf & strRAM & vbcrlf & hdd
    
    
    wscript.sleep 1000
    
    
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set FileList = objWMIService.ExecQuery ("ASSOCIATORS OF {Win32_Directory.Name='" & usbPath & "logs" & "'} Where ResultClass = CIM_DataFile")
    For Each objFile In FileList
        If objFile.Extension = "txt" Then
            strNewName = objFile.Drive & objFile.Path & _
                objFile.FileName & "." & "csv"
            errResult = objFile.Rename(strNewName)
    		If errResult <> "0" Then
            Wscript.Echo errResult
    		else
    		Wscript.Echo "Conversion to CSV Completed"
    		End If
        End If
    Next
    
    
    Set objMemory = Nothing
    Set objWMIService = Nothing

  2. #2

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,849
    Thank Post
    3,365
    Thanked 1,062 Times in 982 Posts
    Rep Power
    366

SHARE:
+ Post New Thread

Similar Threads

  1. Logos - Tidying them up
    By bodminman in forum How do you do....it?
    Replies: 3
    Last Post: 7th January 2011, 09:41 PM
  2. Tidying Up and found this....
    By mattx in forum Windows
    Replies: 3
    Last Post: 16th September 2007, 08:43 AM
  3. Printer script not running at start up
    By richard in forum Scripts
    Replies: 11
    Last Post: 29th May 2007, 07:39 PM
  4. Tidying up ISA 2004
    By eejit in forum Windows
    Replies: 2
    Last Post: 29th January 2007, 01:20 PM
  5. Replies: 5
    Last Post: 5th March 2006, 01:22 PM

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
  •