10/10/2007, 02h26
|
#5
|
|
|
Re: Output PC Name, Serial #, IP, and , OS to CSV
On Oct 9, 9:09 pm, Hickory <Hick...@discussions.microsoft.com> wrote:
> Thank you so much for that, Dveit. It now sucessfully writes a csv file 
> But I can't get is to write the data that I need into the file. Not only
> that, Every time it can't ping a computer, a dialog box pops up, when it
> finds a serial # a box pops up, when it finds the OS version, a box pops up
> and I have to click ok every time that happens. Is there a way to have a
> simple "Please wait..." and not have anything pop up and have it write all
> information to the file?
>
> I am very new at writing vbs and I know next to nothing about its commands
> that correspond with WMI. I am very good at writing dos batch files, but I
> can't get the results I want with that method.
>
> My current code is as follows:
> again, thank you very much for the response
> ----------------------------------------------
>
> On Error Resume Next
>
> intStartingAddress = 1
> intEndingAddress = 255
> strSubnet = "192.168.90."
>
> Const WbemAuthenticationLevelPktPrivacy = 6
>
> strCredentials = InputBox _
> ("Please enter the user name, a blank space, and then the password:", _
> "Enter User Credentials")
>
> If strCredentials = "" Then
> Wscript.Quit
> End If
>
> arrCredentials = Split(strCredentials," ")
> strUser = arrCredentials(0)
> strPassword = arrCredentials(1)
> strNamespace = "root\cimv2"
>
> For i = intStartingAddress to intEndingAddress
> strComputer = strSubnet & i
>
> Set objShell = CreateObject("WScript.Shell")
> strCommand = "%comspec% /c ping -n 2 -w 300 " & strComputer & ""
> Set objExecObject = objShell.Exec(strCommand)
>
> Do While Not objExecObject.StdOut.AtEndOfStream
> strText = objExecObject.StdOut.ReadAll()
> If Instr(strText, "Reply") > 0 Then
>
> Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
> Set objWMIService = objwbemLocator.ConnectServer _
> (strComputer, strNamespace, strUser, strPassword)
> objWMIService.Security_.authenticationLevel =
> WbemAuthenticationLevelPktPrivacy
>
> '
> ================================================== ===================
> winmgmt1 = "winmgmts:{impersonationLevel=impersonate}!//"& strComputer &""
> Set SerialN = GetObject( winmgmt1 ).InstancesOf ("Win32_BIOS")
>
> For each Serial in SerialN
> WScript.Echo "Serial Number: " & Serial.SerialNumber
> Next
>
> Const ForWriting = 2
>
> Dim strFileHeader, strFileContents, strSomeLineDataCSVFormatted
> Dim strFilePath
>
> strFilePath = "c:\scripts\testfile.csv"
> strFileHeader = "MachineName,OS,SerialNumber"
> strFileContents = strFileHeader & vbCrLf
> strFileContents = strFileContents & strSomeDataCSVFormatted & vbCrLf
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objFileCreate = objFSO.CreateTextFile(strFilePath)
> objFileCreate.Close
> Set objFileWrite = objFSO.OpenTextFile(strFilePath, ForWriting)
> objFileWrite.Write strFileContents
> objFileWrite.Close
>
> '
> ================================================== ===================
>
> Set colItems = objWMIService.ExecQuery _
> ("Select * From Win32_OperatingSystem")
> For Each objItem in ColItems
> Wscript.Echo strComputer & ": " & objItem.Caption
> Next
>
> '
> ================================================== ===================
> ' End
> '
> ================================================== ===================
>
> Else
> Wscript.Echo strComputer & " could be not reached."
> End If
> Loop
> Next
>
> -----------------------------------------------
>
>
>
> "dveit" wrote:
> > For previous tasks like this I usually just build out the file contents
> > using a CSV format, create the text file with a .csv file extension, then
> > write the contents to the file. Sample:
>
> > Const ForWriting = 2
>
> > Dim strFileHeader, strFileContents, strSomeLineDataCSVFormatted
> > Dim strFilePath
>
> > strFilePath = "c:\testfile.csv"
> > strFileHeader = "MachineName,OS,SerialNumber"
> > strFileContents = strFileHeader & vbCrLf
> > strFileContents = strFileContents & strSomeDataCSVFormatted & vbCrLf
> > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > Set objFileCreate = objFSO.CreateTextFile(strFilePath)
> > objFileCreate.Close
> > Set objFileWrite = objFSO.OpenTextFile(strFilePath, ForWriting)
> > objFileWrite.Write strFileContents
> > objFileWrite.Close- Hide quoted text -
>
> - Show quoted text -
When you run your script run it under cscript, ie : C:\>cscript
script.vbs
run cscript alone to see usage, such as cscript //h:cscript to make
cscript your default host
-J
www.pooradmin.com
|
|
|
|