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 |
Request for Answer Clarification by
jbbarnes-ga
on
27 Nov 2002 11:54 PST
Thanks.
What I really need, though, is the code ready to go in VB format.
Ready to paste in, as I put it. Even taking the code from the first
example and trying to use it caused problems. The compiler didn't like
"type" and it didn't like the form of the API declares. I put this
question on Google Answers because I'm unfamiliar enough with VB6
that, even though I can get the logic correct, the little syntax
issues are what bog down the whole process.
Also, it looks like that code does not retrieve domain or workgroup
information for Win9x machines. What I have already successfully
determines computername and username under 9x.
|
Clarification of Answer by
webadept-ga
on
27 Nov 2002 12:01 PST
Okay.. I'll put something together for you that will workon the the
95's. I read your comment below and I have an idea of what you are
trying to do. I wrote a program a few years back that made an
inventory of all the clients on the network.. this sounds like what
you are trying as well.
webadept-ga
|
Request for Answer Clarification by
jbbarnes-ga
on
27 Nov 2002 12:59 PST
As further clarification:
I've got a couple of hundred machines running at sites all over town.
The purpose of the program is to compile information such as disk
usage, CPU temp, backup status, uptime, etc.. Everything you would
want to know about the health of the machine. Once a day it will ftp
the report to my ftp site for analysis. Each machine will need to send
it with a unique filename to identify itself, such as
YearMonthDay_DomainOrWorkgroupName_MachineName.txt.
The other items, such as Username and Computer Comment will be part of
the report. Thus I will get a daily snapshot of all machines,
including who's logged in, which tasks are running, installed memory,
etc.. To this end, I found flajason-ga's code useful because it
returns installed memory, CPU speed, and MB manufacturer. This would
give me the ability to do even more with the system, such as locate
machines most in need of upgrades (based on installed memory, CPU
speed, MB, or OS). My Christmas list would also include screen
resolution and color depth, NIC and video manufacturers, current IP
address, most recent scandisk and defrag dates, running tasks, etc..
So the more I can learn about a machine, the better. But, as I said,
I'm rather new to VB, so that's why I've requested help to get past
the syntax hangups.
Thanks.
|
Clarification of Answer by
webadept-ga
on
27 Nov 2002 13:59 PST
Understood, that's the same program I made a few years back. We had a
problem with on-site computers at client sites missing RAM (sounds
silly but that's what was happening) the program sent in changes to
the system and wrote in Times that the change happened. I think I'm on
the right track here. The bid is a little low for writing out all this
code. Unfortunately the program I wrote used Delphi rather than VB,
but the same API calls are available, otherwise I would just post
those libs to you and call it a day.:-) But as I said, it's all
available. These are really basic calls, for instance a Perl progarm
could do the same thing, all the API's are available for that language
as well.
Your wish list I suspected, and that's why I found this link for you.
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
That is the area which will show you how to do all the things you are
talking about.
I'll make some functions and test them, making sure they work. I'll
dig out my old VB books and see where the differences are with the
Win95 and the Win98. Win2k I'm not worried about.
Is there a reason you are using FTP instead of sockets? Is is simply
because you aren't familiar with sockets? The advantage is that the
server can call for an update from the clients as well as receive them
on a scheduled basis. But if you have firewalls to deal with this may
be a bit much to tackle at this stage.
I'll post something to you in the next few days. Thanksgiving is fast
approaching so I can't promise anything today or tomorrow.
Thanks,
webadept-ga
|
Clarification of Answer by
webadept-ga
on
27 Nov 2002 14:07 PST
Here.. try these functions on the Win95 machines.. and let me know if
they work right..
Option Explicit
Private S1 As String
Private Declare Function WNetGetUser Lib "mpr.dll" Alias
"WNetGetUserA" (ByVal lpName As String, ByVal lpUserName As String,
lpnLength As Long) As Long
Private Declare Function GetUserName Lib "advapi32.dll" Alias
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function GetComputerName Lib "kernel32" Alias
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Function FindUserName() As String
' Function that returns the name of the currently logged on user
' Example - MyString = FindUserName
S1 = Space(512)
GetUserName S1, Len(S1)
FindUserName = Trim$(S1)
End Function
Public Function FindNetUserName() As String
' Function that returns the netword name of the currently logged on
user
' Example - MyString = FindNetUserName
S1 = Space(512)
WNetGetUser vbNullString, S1, Len(S1)
FindNetUserName = Trim$(S1)
End Function
Public Function FindComputerName() As String
' Function that returns the network name of the run time machine
' Example - MyString = FindComputerName
S1 = Space(512)
GetComputerName S1, Len(S1)
FindComputerName = Trim$(S1)
End Function
webadept-ga
|
Clarification of Answer by
webadept-ga
on
27 Nov 2002 14:24 PST
Oh, one other thing, the programs that don't work on the win95, are
you compiling them on win95 or on your win 2k? This may be part of the
problem you are having with the code not working. If the functions
I've posted above don't work on win95 try compiling them on win95 to
see if they work then.
webadept-ga
|
Request for Answer Clarification by
jbbarnes-ga
on
27 Nov 2002 22:50 PST
>The bid is a little low for writing out all this
>code.
All I was really after for the bid price was the five variables, two
or three of which may already be working fine. It's specifically the
Domain and Workgroup that I can't seem to come up with consitently.
(I'll run some tests on each type of configuration to see in exactly
which cases they don't work.) Based on the size of the task compared
to the whole project I'm working on, it seemed a fair price to have a
few variables filled in for me. Especially if someone had the code
they could grab from another project.
That being said, if you (or anyone else) can also include "wish list"
items, I can also tip or adjust the price. (Can I increase the bid on
the fly?) Or make it part of a second request. If I got an answer back
including more items like:
MemorySize = GetMemoryAPI()
CPUSpeed = GetMHZAPI()
IPAddress = GetIPAddress()
HorizontalDisplayResolution = BlahBlahBlah()
DisplayAdapter = BlahBlahBlah()
and so on, I would certainly make compensation for the additional
effort. The "G" API calls you gave me the address for are what I will
look into next. Like you, though, I have family duties during
Thanksgiving. I'll still probably take some time to work on the
program when I get in from work tonight. I'll try the additional code
you sent. And yes, I am compiling under Win2000. So far the Username
and Computername seem to work on every platform, and the Computer
Comment seems to work under 9x. I'll verify that, though.
As for sockets, the main reason (as you suspected) is my unfamiliarity
with them. The other concern I had (again as you foresaw) was the
router issue. The vast majority of machines sit behind NAT routers,
few of which support port forwarding. Most that do, only allow me a
total of 10 forwarded ports, most of which are already used by
PCAnywhere and vnc configurations. So for simplicity's sake (and
because I've found some VB ftp examples) I've got it set up to ftp the
report to my machine, where they'll be compiled into reports.
Anyway, happy Thanksgiving, and we can pick up when schedules allow.
|
Clarification of Answer by
webadept-ga
on
28 Nov 2002 01:07 PST
That being said, if you (or anyone else) can also include "wish list"
items, I can also tip or adjust the price. (Can I increase the bid on
the fly?) Or make it part of a second request. If I got an answer back
including more items like:
Don't worry about the bid issue. Let's just get you up and running.
Verify that the code I posted is working on the Win95 clients and let
me know. If those work, then I know what else to send you and which
functions to make. If those don't then I need to figure out why before
I can continue. I don't have a win95 client to test these on. I
checked around to see if anyone I knew still had one, with no luck.
So, I'm at the mercy of my memory and some saved files that did work 3
years ago. Anyway, let me know and we'll get this working for you.
Thanks,
webadept-ga
|
Request for Answer Clarification by
jbbarnes-ga
on
28 Nov 2002 16:30 PST
Hi,
Just so you know, the code you submitted worked on all platforms.
However, I already had username and computername working with the code
I included in my request. The netusername is new, so I'll see if it
turns up any interesting results. It's the domain name and workgroup
name that don't work and is of primary importance. I'll try that first
link you suggested, which I believe offered code that at least worked
for NT/2000/XP.
So you don't waste time on code I've already got, here is a current
list of the data I need and the status of the code for each:
IP Address: done
Gateway Address: done
DHCP Server Address: done
DHCP enabled: done
NIC Description: done
NIC Errors: example found
User name: done
Comp name: done
Domain name: NEEDED
Workgroup: NEEDED
Comment: done
OS Version: example found
uptime: done
names of running tasks: NEEDED
HD size: done
HD free space: done
HD model/description: NEEDED
HD file system: example found
Last chkdsk: NEEDED
Last defrag: NEEDED
CPU speed: example found
CPU temp: use vcool shared memory?
Case temp: use vcool shared memory?
CPU fan speed: use vcool shared memory?
Case fan speed: use vcool shared memory?
Installed memory: example found
IRQ Assignments: NEEDED
MB description: NEEDED
BIOS revision: NEEDED
Video card description: NEEDED
Display resolution: done
Display color depth: done
Display refresh rate: done
NAV virus definitions date: in progress
Last backup status: done
IE version: example found
IE cipher strength: example found
System error log: NEEDED
The link you gave me for vbNet was great. I got a lot of the above
from examples I found there. I love their format and the ease with
which you can incorporate their example code. Everything I located
there has a status of "done" or "example found."
For temperature and fan speed data, unless you know a better way, I
can use a program called vcool. It works for AMD chips on most
motherboards and puts the data into a shared memory area. I have no
idea how to retrieve it, but if you know how to read from shared
memory, I'll create a separate Google question.
The NEEDED are the ones I don't have a clue about yet. Many of them I
know to be possible, because the first comment on this question had
some great code to do it. But it relies on WMI, which doesn't seem to
work on any Win9x machines I've tried.
The idea for the task list is perhaps a string of comma or tab
separated task names, indicating the currently running tasks. The goal
is to keep track of when users load hogware like Webshots and Gator,
or various unnecessary tasks like QuickBooks Delivery Agent and
findfast. If there's not a nifty API answer, perhaps I can just check
the registry, startup groups, and win.ini to see which programs get
loaded on startup. That might be a better solution anyway, now that I
think about it.
The last scandisk and defrag are among the most useful. Win9x machines
display this information in the HD properties, but I've been unable to
find anything in the registry or any log file that gets updated after
these utilities are run. NT/2000/XP don't display this information at
all.
If I've overlooked other useful ones, let me know.
By the way, I enjoyed your answers on "Does a god exist outside of the
abstract realm of thoughts and ideas?" I see you also had one about
the book of Revelation, but that answer got pulled by Google.
Anyway, happy Thanksgiving.
|
Clarification of Answer by
webadept-ga
on
02 Dec 2002 21:48 PST
Try this for the domain name
Public Function Domain() As String
Dim wshNet As Object
Set wshNet = CreateObject("WScript.Network")
On Error GoTo errBadNetwork
Domain = wshNet.UserDomain
Set wshNet = Nothing
Exit Property
errBadNetwork:
Domain = "Unavailable"
End Function
As for workgroup it doesn't appear to be available for Win95 :
http://support.microsoft.com/default.aspx?scid=KB;en-us;210088&
NetWkstaGetInfo(), a Windows Application Programming Interface (API),
takes advantage of the Windows NT and Windows 2000 security model and
returns the computer, workgroup, and domain. Windows 95 and Windows
98, however, can get the current user name with the network
independent function call WNetGetUser and can get the current computer
name with the function GetComputerName(). The following code samples
demonstrate the use of all three.
I seem to remember this from way back, but wasn't sure. I've looked
around for a different way of getting this, such as using ipconfig
/all or netstat but these don't show it either. The only other way I
know of is to grab it from the registery, which is tricky at best and
foolish at worst, at your current level, so I think we are going to
have to let that one slide.
These two
Last chkdsk: NEEDED Last defrag: NEEDED
Checkdsk has a log file, you can ftp that over. Defrag ... ??? I'm not
sure what to do there.
Computer comment (as shown in Network neighborhood), again, not easly
accessable in Win95, and certaily not stable. Again, sorry.
Find out how long windows has been running
Declare Function GetTickCount& Lib "kernel32" ()
Private Sub cmdWinRun_Click()
MsgBox GetTickCount
End Sub
Get a drives drive and volume info
Declare Function GetVolumeInformation Lib _
"kernel32" Alias "GetVolumeInformationA" _
(ByVal lpRootPathName As String, _
ByVal lpVolumeNameBuffer As String, _
ByVal nVolumeNameSize As Long, _
lpVolumeSerialNumber As Long, _
lpMaximumComponentLength As Long, _
lpFileSystemFlags As Long, _
ByVal lpFileSystemNameBuffer As String, _
ByVal nFileSystemNameSize As Long) As Long
Declare Function GetDriveType Lib "kernel32" _
Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Private Sub cmdGetVol_Click()
Dim VolName As String, FSys As String, erg As Long
Dim VolNumber As Long, MCM As Long, FSF As Long
Dim Drive As String, DriveType As Long
VolName = Space(127)
FSys = Space(127)
Drive = "C:\" 'Enter the driverletter you want
DriveType& = GetDriveType(Drive$)
erg& = GetVolumeInformation(Drive$, VolName$, 127&, _
VolNumber&, MCM&, FSF&, FSys$, 127&)
Print "VolumeName:" & vbTab & VolName$
Print "VolumeNumber:" & vbTab & VolNumber&
Print "MCM:" & vbTab & vbTab & MCM&
Print "FSF:" & vbTab & vbTab & FSF&
Print "FileSystem:" & vbTab & FSys$
Print "DriveType:" & vbTab & DriveType&;
End Sub
What we are running into here is several limitations which are caused
by VB and the Win95 OS. Win95 isn't really a multi-tasking OS, so
getting process ID's is a little different than with the Win2k or
WinMx systems. What you can get is a list of open windows, not really
processes. With your description I don't see this as being very useful
to you.
I've been searching around here for several hours now and I'm coming
rapidly to the conclusion that what we are up against here is a case
of using the wrong tool for the job. Visual Basic is just not the
language to use for System Programming, at least not on the Win95
clients. With the Win2k's and NT's it's a bit better, but even there
it's not allowing several tools which I know are in other languages
such as C++ or Delphi.
Other links I've found
http://www.student.kuleuven.ac.be/~m0116986/agnet/tutors/api1p.htm#The
Window Procedure
http://www.fortunecity.com/skyscraper/unix/409/avbfaq/articles/c2a10.html
|
Clarification of Answer by
webadept-ga
on
02 Dec 2002 21:50 PST
The last scandisk and defrag are among the most useful. Win9x machines
display this information in the HD properties, but I've been unable to
find anything in the registry or any log file that gets updated after
these utilities are run. NT/2000/XP don't display this information at
all.
Description of Windows 95 Files Located in the Root Folder
Microsoft Windows 95
Autoexec.bat - Windows 95 configuration file
This file contains commands that should be run by Windows 95 before
the 32-bit portion of the operating system is started.
This file is necessary only if you need to load a real-mode driver.
Autoexec.dos - Previous MS-DOS Autoexec.bat file
This file contains the original Autoexec.bat file from the previous
operating system. It is used if you boot the previous operating
system.
Bootlog.prv - Previous Windows 95 startup log file
This file records the progress of the previous Windows 95 startup
process. When you request a logged boot (or if Windows 95 performs one
automatically), the previous Bootlog.txt file is renamed to
Bootlog.prv before the new Bootlog.txt file is created.
This file is not necessary for the proper operation of Windows 95 and
can be deleted.
Bootlog.txt - Windows 95 startup log file
This file records the progress of the Windows 95 startup (boot)
process. It is created if you request a logged boot, and is also
created automatically by Windows 95 if Windows 95 detected that the
previous boot was unsuccessful.
This file is not necessary for the proper operation of Windows 95 and
can be deleted.
Command.com - Windows 95 command line processor
This program is the Windows 95 command line processor.
This file is necessary for the proper operation of Windows 95 and
should not be deleted.
Command.dos - Previous MS-DOS Command.com file
This file contains the original Command.com file from the previous
operating system. It is used if you request to boot the previous
operating system.
Config.dos - Previous MS-DOS Config.sys file
This file contains the original Config.sys file from the previous
operating system. It is used if you boot the previous operating
system.
Config.sys - Windows 95 configuration file
This file contains parameters that describe the real-mode (16-bit)
drivers that should be loaded into memory as part of the Windows 95
startup process.
This file is necessary only if you need to load a real-mode driver.
Detlog.old - Previous Windows 95 detection log file
This file records the progress of the previous Windows 95 hardware
detection process. When you request that new hardware be detected, the
previous Detlog.txt file is renamed to Detlog.old before the new
Detlog.txt file is created.
This file is not necessary for the proper operation of Windows 95 and
can be deleted.
Detlog.txt - Windows 95 detection log file
This file records the progress of the Windows 95 hardware detection
process. It is created during hardware detection and is consulted by
the hardware detection recovery process if the previous attempt to
detect hardware caused problems.
This file is not necessary for the proper operation of Windows 95 and
can be deleted.
Io.dos - Previous MS-DOS Io.sys file
This file contains the original Io.sys file from the previous
operating system. It is used if you boot the previous operating
system.
Io.sys - Windows 95 MS-DOS
This file contains Windows 95 MS-DOS.
This file is necessary for the proper operation of Windows 95 and
should not be deleted.
Logo.sys - Windows 95 logo
This file contains the Windows 95 logo that is displayed as part of
the startup process.
Msdos.dos - Previous MS-DOS Msdos.sys file
This file contains the original Msdos.sys file from the previous
operating system. It is used if you boot the previous operating
system.
Msdos.sys - Windows 95 configuration file
This file contains parameters necessary for the early phases of the
Windows 95 startup process. For more information, please see the
following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q118579 TITLE : Contents of the Windows Msdos.sys File
This file is necessary for the proper operation of Windows 95 and
should not be deleted.
Oemlog.txt - Windows 95 Original Equipment Manufacturer (OEM) log file
This file records the progress of the Windows 95 OEM preinstallation
process.
This file is not necessary for the proper operation of Windows 95 and
can be deleted.
Scandisk.log - ScanDisk log file
This file is created by the ScanDisk program to record the result of
the most recent disk scan.
This file is not necessary for the proper operation of Windows 95 and
can be deleted.
Setuplog.txt - Windows 95 Setup log file
This file is created by Windows 95 Setup to record the progress of the
installation procedure. It is consulted by Windows 95 Setup as part of
installation recovery.
This file is not necessary for the proper operation of Windows 95 and
can be deleted.
Suhdlog.dat - Windows 95 Setup hard disk log file
This file contains a copy of all Master Boot Records and Partition
Boot Records on the system both before and after the upgrade to
Windows 95. This file is used by Windows 95 Uninstall to restore the
hard disk master boot sector as part of the uninstall process.
To remove this file, click "Old Windows 3.x and MS-DOS system files"
in the Add/Remove Programs tool and then click Add/Remove.
System.1st - Windows 95 first registry
This file contains a copy of the original registry created by Windows
95 setup.
Although this file is not necessary for the proper operation of
Windows 95 and can be deleted, it is recommended that the file be
retained because it can be used to restore the registry should it
become damaged.
W95undo.dat - Windows 95 uninstall data file
This file contains a compressed backup of Windows 3.x files that were
replaced as part of the Windows 95 installation process. It is created
by Windows 95 Setup and is used as part of the Windows 95 uninstall
process.
To remove this file, click "Old Windows 3.x and MS-DOS system files"
in the Add/Remove Programs tool and then click Add/Remove.
W95undo.ini - Windows 95 uninstall script file
This file contains a listing of files backed up in the W95undo.dat
file. It is created by Windows 95 Setup and is used as part of the
Windows 95 uninstall process.
|