Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,533 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,786 people online right now. Registration is fast and FREE... Join Now!




VB Script Question

 
Reply to this topicStart new topic

VB Script Question, formatting issue

longr59
12 Aug, 2008 - 08:45 AM
Post #1

New D.I.C Head
*

Joined: 20 Sep, 2007
Posts: 26


My Contributions
I have some script that pulls what software is installed on the machine and the date installed and dumps it to a csv file. Righr now it dumps app name and date in one collum seperated by a ;. I would like to make them each there own colum. Below is my code

CODE

strHost = "."
Const HKLM = &H80000002
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile("software_simple.csv", True)
objTextFile.WriteLine "Program Name" & ";" & "Installation date"
Set objReg = GetObject("winmgmts://" & strHost & "/root/default:StdRegProv")
Const strBaseKey = "Software\Microsoft\Windows\CurrentVersion\Uninstall\"
objReg.EnumKey HKLM, strBaseKey, arrSubKeys
For Each strSubKey In arrSubKeys
    intRet = objReg.GetStringValue(HKLM, strBaseKey & strSubKey, "DisplayName", strValue)
    If intRet <> 0 Then
        intRet = objReg.GetStringValue(HKLM, strBaseKey & strSubKey,        "QuietDisplayName", strValue)
    End If
    intRet1 = objReg.GetStringValue(HKLM, strBaseKey & strSubKey, "InstallDate", strValue2)
    If (strValue <> "") and (intRet = 0) Then
        objTextFile.WriteLine strValue & ";" & strValue2
    End If
Next
WScript.Echo "Done"
objTextFile.Close

User is offlineProfile CardPM
+Quote Post

longr59
RE: VB Script Question
13 Aug, 2008 - 06:18 AM
Post #2

New D.I.C Head
*

Joined: 20 Sep, 2007
Posts: 26


My Contributions
Never Mind I figured it out. lol Below is the edited code.

CODE

strHost = "."
Const HKLM = &H80000002
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile("software_simple.csv", True)
objTextFile.WriteLine "Program Name" & "," & "Installation date"
Set objReg = GetObject("winmgmts://" & strHost & "/root/default:StdRegProv")
Const strBaseKey = "Software\Microsoft\Windows\CurrentVersion\Uninstall\"
objReg.EnumKey HKLM, strBaseKey, arrSubKeys
For Each strSubKey In arrSubKeys
    intRet = objReg.GetStringValue(HKLM, strBaseKey & strSubKey, "DisplayName", strValue)
    If intRet <> 0 Then
        intRet = objReg.GetStringValue(HKLM, strBaseKey & strSubKey,        "QuietDisplayName", strValue)
    End If
    intRet1 = objReg.GetStringValue(HKLM, strBaseKey & strSubKey, "InstallDate", strValue2)
    If (strValue <> "") and (intRet = 0) Then
        objTextFile.WriteLine strValue & "," & strValue2
    End If
Next
WScript.Echo "Done"
objTextFile.Close


I also wrote a more in depth version code below
CODE

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile("software_ext.csv", True)
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery ("SELECT * FROM Win32_Product")
objTextFile.WriteLine "Caption" & "," & _
"Description" & "," & "Identifying Number" & "," & _
"Install Date" & "," & "Install Location" & "," & _
"Install State" & "," & "Name" & "," & _
"Package Cache" & "," & "SKU Number" & "," & "Vendor" & "," _
& "Version"
For Each objSoftware in colSoftware
objTextFile.WriteLine objSoftware.Caption & "," & _
objSoftware.Description & "," & _
objSoftware.IdentifyingNumber & "," & _
objSoftware.InstallDate & "," & _
objSoftware.InstallLocation & "," & _
objSoftware.InstallState & "," & _
objSoftware.Name & "," & _
objSoftware.PackageCache & "," & _
objSoftware.SKUNumber & "," & _
objSoftware.Vendor & "," & _
objSoftware.Version
Next
WScript.Echo "Done"
objTextFile.Close

User is offlineProfile CardPM
+Quote Post

thava
RE: VB Script Question
13 Aug, 2008 - 05:26 PM
Post #3

D.I.C Regular
Group Icon

Joined: 17 Apr, 2007
Posts: 450



Thanked: 18 times
Dream Kudos: 50
My Contributions
i thins if it is formatting issue
CODE

objTextFile.WriteLine strValue & ";" & strValue2

use the following ocde
CODE

objTextFile.WriteLine left(strValue +space(len),len) &  strValue2

here the len variable denote the maximum no of the data you want in the first column
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 10:13PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month