Monday, 20 June 2011

VBScript to get Hostname and Whoami

you may wonder what're whoami, systeminfo, and other simple dos commands, the o/p for which you have to at least click 5-10 clicks using web interface.. unix, dos and shell savvies would love such commands including me which is what being fetched by the web apps codes to populate currently logged-in user, machine name, current logged in email account, so on and so forth.

'---- your code starts here ... KTR
Dim objNet
On Error Resume Next

'In case we fail to create object then display our custom error
Set objNet = CreateObject("WScript.NetWork")
If  Err.Number <> 0 Then                'If error occured then display notice
 MsgBox "Don't be Shy." & vbCRLF &_
               "Do not press ""No"" If your browser warns you."
 Document.Location = "UserInfo.html"  
                                        'Place the Name of the document.
                                 'It will display again
End if

Dim strInfo
strInfo = "User Name is     " & objNet.UserName & vbCRLF & _
          "Computer Name is " & objNet.ComputerName & vbCRLF & _
          "Domain Name is   " & objNet.UserDomain
MsgBox strInfo

Set objNet = Nothing                    'Destroy the Object to free the Memory

'---- your code ends here --- copy and paste with .vbs extenstion if needs testing

0 comments: