Visual Basic: Determining computer name, domain, workgroup, etc.
-
I'm developing an app that reports a machine's status each day to a remote server. In the process, I need it to determine: 1) Current user logged in 2) Computer name 3) Workgroup (if applicable) 4) Domain (if applicable) 5) Computer comment (as shown in Network neighborhood) It needs to run under Win9x and NT/2000/XP. Code needs to work in Visual Basic 6 Some of this information is available in the registry, but the trick is that it resides in different places in different versions of Windows. Some of it may be available from API calls, which would be much better, and hopefully more consistent. Below is the code I currently have, which does a fair job of getting some of it. It should at least serve as a start. The most problematic part seems to be determining Workgroup and Domain. Surely there's an API call to do that, right? Public Sub GetID() WorkgroupName = ReadKey("HKLM\System\CurrentControlSet\Services\VxD\VNETSUP\Workgroup") CompComment = ReadKey("HKLM\System\CurrentControlSet\Services\VxD\VNETSUP\Comment") DomainName = ReadKey("HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultDomainName") Dim lpBuff As String * 25 Dim ret As Long Dim lpBuff2 As String * 25 Dim ret2 As Long ret = getUserName(lpBuff, 25) UserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1) ret2 = GetComputerName(lpBuff2, 25) CompName = Left(lpBuff2, InStr(lpBuff2, Chr(0)) - 1) End Sub Public Function ReadKey(Value As String) As String Dim o As Object Dim s As String On Error Resume Next Set o = CreateObject("wscript.shell") s = o.RegRead(Value) ReadKey = s End Function I need VB 6 code ready to paste into my Subroutine, complete with any subs or functions required and any public declares needed to call Windows API functions. Ideally it should look something like this: MsgBox "Username = " & SecretUserNameFunction() MsgBox "Compname = " & SecretComputerNameFunction() MsgBox "Comment = " & SecretCompCommentFunction() MsgBox "Workgroup = " & SecretWorkgroupFunction() MsgBox "Domain = " & SecretDomainFunction() with your actual code replacing the unknown functions. That way I can paste it into a program and quickly run it on a number of machines to see if it's universally accurate. You can use API, read registry entries, or use VB functions. It may take some conditional code based on OS version. If you think you have it, but want me to test, send me what you have so far. It needs to be accurate on Win9x machines (in Workgroups or Domains), Win NT/2000/XP (in Workgroups or Domains) and NT/2000 servers. The ones that don't apply for a given OS (NT/2000/XP don't have Computer comments. A domain member won't be part of a workgroup, and vice versa) should just be blank. Feel free to ask for for clarification.
-
Answer:
Hi, Here are a few webpages that have this code ready for you. As you have guessed there are API calls which do this and they are well documented. I understand that finding this information can be a real chore, but I've located it enough times in my programming carrer that I knew where to look. First we will start with Microsoft's Knowledge Base and then a few other websites to give various ways of doing this. http://support.microsoft.com/default.aspx?scid=KB;en-us;q210088 Don't be thrown by the Access 2000, visual basic is visual basic and these calls will work with any of the systems. Other Links that may interest you VBnet Welcome (very good site for code snipets and examples) http://www.mvps.org/vbnet/welcome.htm API Index Page ( You want to go under G first and then explore the rest) http://www.mvps.org/vbnet/index.html?http://www.mvps.org/vbnet/api/_api/index.html VB2thMax http://www.vb2themax.com/KBBank.asp?Cat=1400&DocType=HOWTO Get UserName http://www.mvps.org/vbnet/index.html?code/core/index.html Workstation Name changer http://mytoolsandstuff.tripod.com/wsname.html Web pages containing VB6 free code http://www.access911.com/VB6freecode.htm
jbbarnes-ga at Google Answers Visit the source
Related Q & A:
- What are the object-oriented features of Visual Basic.NET?Best solution by msdn.microsoft.com
- Can you program Graphics with Visual Basic?Best solution by Yahoo! Answers
- What are the main parts of visual basic 2005?Best solution by msdn.microsoft.com
- Codes for a simple visual basic program.Best solution by vbtutor.net
- How do you use the Contains Function in Visual Basic?Best solution by go4expert.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.