Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Computer Name

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,35571
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Computer Name
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Computer Name - 6/20/2006 12:39:29 AM   
  jljr23

 

Posts: 3
Score: 0
Joined: 6/19/2006
Status: offline
Ok I have figured out my problem before. I have multiple computers I'm running the script on and have no way of telling which computer it is running on. Can someone tell me how I can configure it to display the name of the computer. Here is the script I am using:

Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
strComputer = "."
strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
strEntry1a = "DisplayName"
strEntry1b = "QuietDisplayName"
strEntry2 = "InstallDate"
strEntry3 = "VersionMajor"
strEntry4 = "VersionMinor"
strEntry5 = "EstimatedSize"
Wscript.Echo "Name:" & 'strComputer'
Set objReg = GetObject("winmgmts://" & strComputer & _
"/root/default:StdRegProv")
objReg.EnumKey HKLM, strKey, arrSubkeys
WScript.Echo "Installed Applications" & VbCrLf
For Each strSubkey In arrSubkeys
intRet1 = objReg.GetStringValue(HKLM, strKey & strSubkey, _
  strEntry1a, strValue1)
If intRet1 <> 0 Then
   objReg.GetStringValue HKLM, strKey & strSubkey, _
    strEntry1b, strValue1
End If
If strValue1 <> "" Then
   WScript.Echo VbCrLf & "Display Name: " & strValue1
End If
objReg.GetStringValue HKLM, strKey & strSubkey, _
  strEntry2, strValue2
If strValue2 <> "" Then
   WScript.Echo "Install Date: " & strValue2
End If
objReg.GetDWORDValue HKLM, strKey & strSubkey, _
  strEntry3, intValue3
objReg.GetDWORDValue HKLM, strKey & strSubkey, _
  strEntry4, intValue4
If intValue3 <> "" Then
    WScript.Echo "Version: " & intValue3 & "." & intValue4
End If
objReg.GetDWORDValue HKLM, strKey & strSubkey, _
  strEntry5, intValue5
If intValue5 <> "" Then
   WScript.Echo "Estimated Size: " & Round(intValue5/1024, 3) & " megabytes"
End If
Next

I just need a way to identify what computer I am running the script on.
 
 
Post #: 1
 
 RE: Computer Name - 6/20/2006 12:43:05 AM   
  ebgreen


Posts: 4970
Score: 31
Joined: 7/12/2005
Status: offline
Option Explicit

Dim oWSN:Set oWSN = CreateObject("WScript.Network")

WScript.Echo oWSN.ComputerName

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to jljr23)
 
 
Post #: 2
 
 RE: Computer Name - 6/20/2006 6:19:04 AM   
  jljr23

 

Posts: 3
Score: 0
Joined: 6/19/2006
Status: offline
Where in the script should I insert this section of code?

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: Computer Name - 6/20/2006 6:39:09 AM   
  ebgreen


Posts: 4970
Score: 31
Joined: 7/12/2005
Status: offline
That was just demo code. The .ComputerName method of the WScript.Network object simply returns that name of the computer that the script is running on. To use it in your script, you would assign that to some variable anywhere before wherever you need to use the computer name.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to jljr23)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Computer Name Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts