![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: May 2005
Posts: 7
Rep Power: 0
![]() |
2 things, 1 prob easy, other not
****You can ignore this - have fixed the bit I thought was hard - would like to get the easy bit done - see follow up post.****
I want to save the following IP address into the created textfile - what's wrong with this code? Second thing, perhaps not so eay - how would I save the file as the given IP address? Dim outFile ' Header line for screen output strMsg = IPconfig strComputer = "." Set objWMIService = GetObject( _ "winmgmts:\\" & strComputer & "\root\cimv2") Set IPConfigSet = objWMIService.ExecQuery _ ("Select IPAddress from Win32_NetworkAdapterConfiguration ") For Each IPConfig in IPConfigSet If Not IsNull(IPConfig.IPAddress) Then For i=LBound(IPConfig.IPAddress) _ to UBound(IPConfig.IPAddress) WScript.Echo IPConfig.IPAddress(i) Next End If Next dim FSobj set FSobj=CreateObject("Scripting.FileSystemObject") set outFile= FSobj.CreateTextFile("outFile.txt", 2, True) outFile.write strMsg outFile.Close WScript.Echo "Output stored to outFile.txt in same directory as script." Last edited by FelixM; May 17th, 2005 at 6:52 AM. |
|
|
|
|
|
#2 |
|
Newbie
Join Date: May 2005
Posts: 7
Rep Power: 0
![]() |
Have fixed the difficult (for me!) naming the file, will post full file so you can see the 2nd part - appending the IP address to the already created text file. This should be easy, am working on now, if someone could post a solution before then though I'd be chuffed!
'[code] ' Check command line parameters Select Case WScript.Arguments.Count Case 0 ' Default if none specified is local computer (".") Set objWMIService = GetObject( "winmgmts://./root/cimv2" ) Set IPConfigSet = objWMIService.ExecQuery _ ("Select IPAddress from Win32_NetworkAdapterConfiguration ") For Each IPConfig in IPConfigSet If Not IsNull(IPConfig.IPAddress) Then For i=LBound(IPConfig.IPAddress) _ to UBound(IPConfig.IPAddress) WScript.Echo IPConfig.IPAddress(i) Next End If Next Set colItems = objWMIService.ExecQuery( "Select * from Win32_ComputerSystem", , 48 ) For Each objItem in colItems strComputer = objItem.name Next Case 1 ' Command line parameter can either be a computer ' name or "/?" to request online help strComputer = UCase( Wscript.Arguments(0) ) if InStr( strComputer, "?" ) > 0 Then Syntax Case Else ' Maximum is 1 command line parameter Syntax End Select Dim outFile ' Header line for screen output strMsg = vbCrLf & "Hardware summary for " & strComputer & ":" & vbCrLf & vbCrLf ' Enable error handling On Error Resume Next ' Connect to specified computer Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" ) ' Display error number and description if applicable If Err Then ShowError ' Query processor properties Set colItems = objWMIService.ExecQuery( "Select * from Win32_Processor", , 48 ) ' Display error number and description if applicable If Err Then ShowError ' Prepare display of results For Each objItem in colItems strMsg = strMsg & "Processor(s)" & vbCrLf _ & " Name: " _ & Strip( objItem.Name ) & vbCrLf _ & " Manufacturer: " _ & objItem.Manufacturer & vbCrLf _ & " Description: " _ & objItem.Description & vbCrLf _ & " Current Clock Speed: " _ & objItem.CurrentClockSpeed & " MHz" _ & vbCrLf & vbCrLf Next ' Query memory properties Set colItems = objWMIService.ExecQuery( "Select * from Win32_LogicalMemoryConfiguration", , 48 ) ' Display error number and description if applicable If Err Then ShowError ' Prepare display of results For Each objItem in colItems strMsg = strMsg & "Memory" & vbCrLf _ & " Total Physical Memory: " _ & Int( ( objItem.TotalPhysicalMemory + 1023 ) / 1024 ) _ & " MB" & vbCrLf & vbCrLf Next ' Query harddisk properties Set colItems = objWMIService.ExecQuery( "Select * from Win32_DiskDrive", , 48 ) ' Display error number and description if applicable If Err Then ShowError ' Prepare display of results For Each objItem in colItems strMsg = strMsg & "Harddisk(s)" & vbCrLf _ & " Manufacturer: " _ & objItem.Manufacturer & vbCrLf _ & " Model: " _ & objItem.Model & vbCrLf _ & " Size: " _ & Int( ( objItem.Size + 536870912 ) / 1073741824 ) _ & " GB" & vbCrLf & vbCrLf Next ' Query video adapter properties Set colItems = objWMIService.ExecQuery( "Select * from Win32_VideoController", , 48 ) ' Display error number and description if applicable If Err Then ShowError ' Prepare display of results For Each objItem in colItems strMsg = strMsg & "Video" & vbCrLf _ & " Name: " _ & objItem.Name & vbCrLf _ & " Description: " _ & objItem.Description & vbCrLf _ & " Video Processor: " _ & objItem.VideoProcessor & vbCrLf _ & " Adapter RAM: " _ & Int( ( objItem.AdapterRAM + 524288 ) / 1048576 ) _ & " MB" & vbCrLf _ & " Video Mode Description: " _ & objItem.VideoModeDescription & vbCrLf & vbCrLf Next ' Display results WScript.Echo strMsg dim FSobj set FSobj=CreateObject("Scripting.FileSystemObject") set outFile= FSobj.CreateTextFile(strComputer &".txt", 2, True) outFile.write strMsg outFile.Close WScript.Echo "Output stored to in text file on K:\General\IT\Assets" 'Done WScript.Quit(0) Sub ShowError() strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf & _ Err.Description & vbCrLf & vbCrLf Syntax End Sub Sub Syntax() strMsg = strMsg & vbCrLf _ & "Hardware.vbs, Version 1.11" & vbCrLf _ & "Display basic hardware summary for " _ & "any computer on the network" & vbCrLf & vbCrLf _ & "Usage: CSCRIPT //NOLOGO HARDWARE.VBS " _ & "[ computer_name ]" & vbCrLf & vbCrLf _ & "Where: " & Chr(34) & "computer_name" & Chr(34) _ & " is the optional name of a remote" & vbCrLf _ & " computer (default is local computer " _ & "name)" & vbCrLf & vbCrLf _ & "Written by Rob van der Woude" & vbCrLf _ & "http://www.robvanderwoude.com" & vbCrLf & vbCrLf _ & "Created with Microsoft's Scriptomatic tool" & vbCrLf _ & "http://www.microsoft.com/technet/treeview/default.asp" _ & "?url=/technet/scriptcenter/WMImatic.asp" & vbCrLf WScript.Echo strMsg WScript.Quit(1) End Sub Private Function Strip( strInput ) Do While Left( strInput, 1 ) = " " strInput = Mid( strInput, 2 ) Loop Strip = strInput End Function '[code/] |
|
|
|
|
|
#3 |
|
Programming Guru
![]() |
instead of [code/] its [/code]
__________________
"Put your hand on a hot stove for a minute, and it seems like an hour. Sit with a pretty girl for an hour, and it seems like a minute. THAT'S relativity." - Albert Einstein |
|
|
|
|
|
#4 |
|
Professional Programmer
Join Date: May 2005
Location: Woo - Boot Sector!
Posts: 294
Rep Power: 4
![]() |
Is that the only problem, that seems rather silly, a lot of hard code and a simple error. It's not even like it's a typo, it's sort of in the wrong place! I'm sorry, now i'm just talking for the sake of it...
![]()
__________________
www.heldtogether.co.uk |
|
|
|
|
|
#5 |
|
Programming Guru
![]() |
Reply to Kratong (sorry OP)....
But yes the code tags do make a lot of difference, it formats the code properly so it makes it easier to read and see if there are any silly errors with loops and everything, as in that format it has no tabbing which I think to everyprogrammer is something they hate to see ......
__________________
"Put your hand on a hot stove for a minute, and it seems like an hour. Sit with a pretty girl for an hour, and it seems like a minute. THAT'S relativity." - Albert Einstein |
|
|
|
|
|
#6 |
|
Newbie
Join Date: May 2005
Posts: 7
Rep Power: 0
![]() |
No no no no guys, no!
I only put the [code] in because the sticky post told me to - it's got nothing to do with my code. What I want to have happen is twofold.
1st Save the file in a remote location - ie. K:\General rather than in the folder where the script was executed. 2nd Add in the IP address to the output file. |
|
|
|
|
|
#7 |
|
Programming Guru
![]() |
Yes i understand that but i bet your code is nicly tabbed etc etc :/
it
does
this
__________________
"Put your hand on a hot stove for a minute, and it seems like an hour. Sit with a pretty girl for an hour, and it seems like a minute. THAT'S relativity." - Albert Einstein |
|
|
|
|
|
#8 |
|
Newbie
Join Date: May 2005
Posts: 7
Rep Power: 0
![]() |
Ah me see's. Ta.
|
|
|
|
|
|
#9 |
|
Professional Programmer
Join Date: May 2005
Location: Woo - Boot Sector!
Posts: 294
Rep Power: 4
![]() |
Ye sorry, i was half asleep when i posted, sorry just ignore me, most people do...
__________________
www.heldtogether.co.uk |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|