Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 17th, 2005, 5:08 AM   #1
FelixM
Newbie
 
Join Date: May 2005
Posts: 7
Rep Power: 0 FelixM is on a distinguished road
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.
FelixM is offline   Reply With Quote
Old May 17th, 2005, 6:51 AM   #2
FelixM
Newbie
 
Join Date: May 2005
Posts: 7
Rep Power: 0 FelixM is on a distinguished road
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/]
FelixM is offline   Reply With Quote
Old May 17th, 2005, 9:39 AM   #3
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
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
Berto is offline   Reply With Quote
Old May 17th, 2005, 9:52 AM   #4
LOI Kratong
Professional Programmer
 
Join Date: May 2005
Location: Woo - Boot Sector!
Posts: 294
Rep Power: 4 LOI Kratong is on a distinguished road
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
LOI Kratong is offline   Reply With Quote
Old May 17th, 2005, 9:57 AM   #5
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
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
Berto is offline   Reply With Quote
Old May 17th, 2005, 10:02 AM   #6
FelixM
Newbie
 
Join Date: May 2005
Posts: 7
Rep Power: 0 FelixM is on a distinguished road
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.
FelixM is offline   Reply With Quote
Old May 17th, 2005, 10:24 AM   #7
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
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
Berto is offline   Reply With Quote
Old May 17th, 2005, 10:27 AM   #8
FelixM
Newbie
 
Join Date: May 2005
Posts: 7
Rep Power: 0 FelixM is on a distinguished road
Ah me see's. Ta.
FelixM is offline   Reply With Quote
Old May 17th, 2005, 1:51 PM   #9
LOI Kratong
Professional Programmer
 
Join Date: May 2005
Location: Woo - Boot Sector!
Posts: 294
Rep Power: 4 LOI Kratong is on a distinguished road
Ye sorry, i was half asleep when i posted, sorry just ignore me, most people do...
__________________
www.heldtogether.co.uk
LOI Kratong is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:52 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC