Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


display computer name of client pc

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> display computer name of client pc
  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 >>
 display computer name of client pc - 7/9/2004 2:15:37 AM   
  bpsi489

 

Posts: 1
Score: 0
Joined: 7/9/2004
From: Philippines
Status: offline
Hi All,

Could anyone please help me how to add the computer name in this script to be displayed?

Thanks.


'~~Comment~~.
'This program displays the full name of a given username.

'~~Script~~.
Option Explicit

' Declare variables.
Dim Domainname, Username
Dim WshNetwork
Dim SearchPos
Dim User
Dim ErrNum

' Parse parameters provided by user.
' If no parameters are provided, prompt user for username.
' If parameter is '/?', display help.
' If more than one parameter is specified, display errormessage.

Select Case Wscript.Arguments.Count
Case 0
Set WshNetwork = Wscript.CreateObject("Wscript.Network")
Username = InputBox("This program displays the full name of a given username." & vbCrLf & vbCrLf & "Please enter an username in the field below." & vbCrLf & vbCrLf & "Syntax: [Domainname\]Username", "Fullname.vbs", WshNetwork.UserDomain & "\" & WshNetwork.UserName)
If Username = "" Then Wscript.Quit(0)
Case 1
Username = Wscript.Arguments(0)
If Username = "/?" Then
MsgBox "This program displays the full name of a given username." & vbCrLf & vbCrLf & "Usage: Fullname.vbs [[domainname\]username]" & vbCrLf & vbCrLf & "If no parameters are provided, Fullname.vbs will prompt for a username." & vbCrLf & "If no domainname is provided, Fullname.vbs will use the current domain.", vbOKOnly + vbInformation, "Fullname.vbs"
Wscript.Quit(0)
End If
Case Else
MsgBox "ERROR: Too much parameters." & vbCrLf & vbCrLf & "Use 'Fullname.vbs /?' for more help.", vbOKOnly + vbCritical, "Fullname.vbs"
Wscript.Quit(1)
End Select

' Get Domainname and Username.
' If domainname is not specified, get the current domainname.
' If domainname or username are blank, display errormessage.

SearchPos = InStr(Username, "\")
If SearchPos = 0 Then
Set WshNetwork = Wscript.CreateObject("Wscript.Network")
Domainname = WshNetwork.UserDomain
Else
Domainname = Left(Username, SearchPos - 1)
Username = Mid(Username, SearchPos + 1)
End If
If Domainname = "" Then
MsgBox "ERROR: Domainname is empty." & vbCrLf & vbCrLf & "Use 'Fullname.vbs /?' for more help.", vbOKOnly + vbCritical, "Fullname.vbs"
Wscript.Quit(2)
ElseIf Username = "" Then
MsgBox "ERROR: Username is empty." & vbCrLf & vbCrLf & "Use 'Fullname.vbs /?' for more help.", vbOKOnly + vbCritical, "Fullname.vbs"
Wscript.Quit(3)
End If

' Check Username for errors.
' If username still contains '\', display errormessage.
' If username contains '/', display errormessage.

SearchPos = InStr(Username, "\")
If SearchPos <> 0 Then
MsgBox "ERROR: Username contains too much '\' characters." & vbCrLf & vbCrLf & "Use 'Fullname.vbs /?' for more help.", vbOKOnly + vbCritical, "Fullname.vbs"
Wscript.Quit(4)
End If
SearchPos = InStr(Username, "/")
If SearchPos <> 0 Then
MsgBox "ERROR: Username contains '/' character." & vbCrLf & vbCrLf & "Use '\' between domainname and username." & vbCrLf & vbCrLf & "Use 'Fullname.vbs /?' for more help.", vbOKOnly + vbCritical, "Fullname.vbs"
Wscript.Quit(5)
End If

' Get Fullname.
' If binding to user fails, display errormessage.
On Error Resume Next 'we need to disable WSH error checking to verify if binding to user was succussfull or not.
Set User = GetObject("WinNT://" & Domainname & "/" & Username & ",User")

ErrNum = Err.Number
On Error GoTo 0 're-enable WSH error checking.
If ErrNum = 0 Then
MsgBox "Domainname : " & Domainname & vbCrLf & "Username : " & Username & vbCrLf & vbCrLf & "Fullname : " & User.Fullname, vbOKOnly + vbInformation, "Fullname.vbs"
Else
MsgBox "ERROR: Failed to bind to " & "WinNT://" & Domainname & "/" & Username & ",User" & vbCrLf & vbCrLf & "Check domainname and username." & vbCrLf & vbCrLf & "Use 'Fullname.vbs /?' for more help.", vbOKOnly + vbCritical, "Fullname.vbs"
Wscript.Quit(6)
End If

' End of script.
WScript.Quit(0)
 
 
Post #: 1
 
 Re: display computer name of client pc - 8/18/2004 6:33:41 AM   
  agkrueger

 

Posts: 9
Score: 0
Joined: 8/18/2004
From: USA
Status: offline
Where does this script run from? If from the machine you want the name of, here is a simple script I wrote for our helpdesk. We put it out on the netlogon share and ask users to run it when the helpdesk needs PC related information...i've since added more to it but this was rev1

---------------[begin]-------------------
'Computer Information Script
'Script will collect basic information and present it within a popup dialog for the user.
'Aaron G. Krueger, 03/01/2004

On Error Resume Next
strComputer = "."

Set objShell = Wscript.CreateObject("Wscript.Shell")
Set colSystemEnvVars = objShell.Environment("System")
Set colUserEnvVars = objShell.Environment("User")
Set objNetwork = Wscript.CreateObject("Wscript.Network")

samUser = objNetwork.UserName
computerName = objNetwork.ComputerName

objShell.Popup "This Computer Name is: " & computerName & vbCrLF & "The Current UserID is: " & samUser & vbCrLF & vbCrLF & "Click 'OK' to close this window (auto-closes in 60 seconds).",60,"Computer Information Collection",vbInformation+vbOKOnly+vbDefaultButton1
Wscript.Quit
---------------[end]-------------------

maybe this will help you see what you need to add.

(in reply to bpsi489)
 
 
Post #: 2
 
 
 
  

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 >> display computer name of client pc 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