{"id":7528,"date":"2021-11-24T10:10:04","date_gmt":"2021-11-24T10:10:04","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/?post_type=question&#038;p=7528"},"modified":"2021-11-24T10:10:55","modified_gmt":"2021-11-24T10:10:55","slug":"vbs-output-to-csv-format","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/programming\/vbs-output-to-csv-format\/24701.html","title":{"rendered":"Vbs Output To Csv Format"},"content":{"rendered":"<p>thanks for allowing me to join this forum<\/p>\n<p>the given below a vbs script which i googled and got which will take input from a text file compare with wmi for patches and gives output whether patches are installed or not&#8230;<\/p>\n<p>now i want to make some modifications in the script:-<\/p>\n<p>(a) the PCs hostname should me taken automatically from host commad and user no need to enter hostname<br \/>\n(b) Instead of showing output in open exel file, i want the output to be redirected to some csv file.<\/p>\n<p>thanks in advance<\/p>\n<p>the script follows :-<\/p>\n<p>&nbsp;<\/p>\n<p>strComputer = InputBox (&#8220;Enter Machine Name&#8221;)<\/p>\n<p>&nbsp;<\/p>\n<p>Set objExcel = CreateObject(&#8220;Excel.Application&#8221;)<\/p>\n<p>objExcel.Visible = True<\/p>\n<p>objExcel.Workbooks.Add<\/p>\n<p>intRow = 2<\/p>\n<p>&nbsp;<\/p>\n<p>objExcel.Cells(1, 1).Value = &#8220;HotFix&#8221;<\/p>\n<p>objExcel.Cells(1, 2).Value = strHotFixId &amp; &#8221; Install Date&#8221;<\/p>\n<p>&nbsp;<\/p>\n<p>Set Fso = CreateObject(&#8220;Scripting.FileSystemObject&#8221;)<\/p>\n<p>Set InputFile = fso.OpenTextFile(&#8220;patches.Txt&#8221;)<\/p>\n<p>Do While Not (InputFile.atEndOfStream)<\/p>\n<p>strHotFixId = InputFile.ReadLine<\/p>\n<p>&nbsp;<\/p>\n<p>Set objWMIService = GetObject(&#8220;winmgmts:\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\cimv2&#8221;)<br \/>\nSet colItems = objWMIService.ExecQuery( _<br \/>\n&#8220;Select * from Win32_QuickFixEngineering Where HotFixID ='&#8221; &amp; strHotFixId &amp; &#8220;&#8216;&#8221;)<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>If colItems.Count &gt; 0 Then<\/p>\n<p>For Each objItem In colItems<\/p>\n<p>objExcel.Cells(intRow, 1).Value = strHotFixId<\/p>\n<p>objExcel.Cells(intRow, 2).Value = objItem.InstalledOn<\/p>\n<p>Next<\/p>\n<p>Else<\/p>\n<p>objExcel.Cells(intRow, 1).Value = strHotFixId<\/p>\n<p>objExcel.Cells(intRow, 2).Value = &#8220;Not Installed&#8221;<\/p>\n<p>If objExcel.Cells(intRow, 2).Value = &#8220;Not Installed&#8221; Then<\/p>\n<p>objExcel.Cells(intRow, 1).Font.ColorIndex = 3<\/p>\n<p>objExcel.Cells(intRow, 2).Font.ColorIndex = 3<\/p>\n<p>Else<\/p>\n<p>End If<\/p>\n<p>End If<\/p>\n<p>&nbsp;<\/p>\n<p>intRow = intRow + 1<\/p>\n<p>Loop<\/p>\n<p>objExcel.Range(&#8220;A1:B1&#8221;).Select<\/p>\n<p>objExcel.Cells.HorizontalAlignment = 2<\/p>\n<p>objExcel.Selection.Interior.ColorIndex = 19<\/p>\n<p>objExcel.Selection.Font.ColorIndex = 11<\/p>\n<p>objExcel.Selection.Font.Bold = True<\/p>\n<p>objExcel.Cells.EntireColumn.AutoFit<\/p>\n<p>&nbsp;<\/p>\n<p>MsgBox &#8220;Done&#8221;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"iawp_total_views":1},"question-category":[55],"question_tags":[],"class_list":["post-7528","question","type-question","status-publish","hentry","question-category-programming"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question\/7528","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question"}],"about":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/comments?post=7528"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=7528"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=7528"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=7528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}