Tuesday, September 10

How to get system/user name of machine in QTP/VBscript

Hello Friends!

Here in this post we will quickly see how to get the User Name of the machine you are executing your test. It's useful specially in results of your test. If you have have more then one users/machines involved in the test execution, it'll help you to differentiate which tests have been executed on which machine.. 

Function f_GetSystemUserName()
    Set oSystemInfo = CreateObject("ADSystemInfo")
    Set oUser=GetObject("LDAP://" & oSystemInfo.UserName)
    f_GetSystemUserName= oUser.DisplayName
    Set oSystemInfo = Nothing
    Set oUser = Nothing
End Function    'End of function f_GetSystemUserName()

'Calling above function
Msgbox f_GetSystemUserName()