Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

How can I return the current machine name and the current user name via dll calling in SilkTest?

How can I return the current machine name and the current user name via dll calling in SilkTest?

Problem:

How can I return the current machine name and the current user name via dll calling in SilkTest?

Resolution:

QUESTION
----------------------------------

How can I return the current machine name and the current user name via dll calling in SilkTest?

ANSWER
----------------------------------

This can be done by using the GetComputerName function within KERNEL32.dll and GetUserName function from the advapi32.dll. You will need to declare the dlls in the correct manner; information can be found within the SilkTest Help on how to do this.

[-] dll "KERNEL32.DLL"
    [ ] LONG GetComputerName (out STRING lpBuffer, inout LONG nSize) alias "GetComputerNameA" 
[ ] 
[-] dll "advapi32.dll"
    [ ] LONG GetUserName(out STRING lpBuffer, inout LONG nSize) alias "GetUserNameA" 

[-] testcase compname () appstate none
    [ ] STRING lpBuffer 
    [ ] LONG nSize = 250
    [ ] STRING lpBuffer2 
    [ ] LONG nSize2 = 250
    [ ] 
    [ ] GetUserName(lpBuffer, nSize)
    [ ] Print("User: ",lpBuffer)
    [ ] 
    [ ] GetComputerName(lpBuffer2, nSize2)
    [ ] Print("Computer: ",lpBuffer2)


Note: if you are running this test in SilkTest 2006 or SilkTest International, you will need to use the widened versions of the dlls as discussed in the resolution below.

Other related topics are:


Old KB# 21033

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-02-15 19:16
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.