Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Upload & Download

Status
Not open for further replies.

FireNacho

Programmer
May 5, 2003
2
0
0
NO
I am using Delphi 5, I have WinXp and my internet connection is via LAN.

I´m trying to make a program where you can see total downloaded and uploaded megabytes. 'Label1' shows downloaded mega and 'Label2' shows uploaded.

The program must save the values in a file when closed and load them up again upon starting the program.

Also..... How do a make a system shutdown button? Like the one in Windows ?
 
For system shutdown try:

ExitWindowsEx(EWX_SHUTDOWN,0);
 
for log files, I like to use a stringlist....quick and easy:
procedure Logfile //or pass in some paramaters for the values
var
slLogFile Tstringlist;
begin
slLogFile := Tstringlist.create;
//load it up first
slLogFile.loadfromfile('c:\logfile.txt');
if slLogfile.count = 2 then begin
//if its the stringlist is empty, you'll get index out of bounds
label1.caption := sllogfile.strings[0];
label2.caption := slLogfile.strings[1];
end
//Then when you're done
sllogfile.clear;
slLogfile.add(label1.caption);
sllogfile.add(label2.caption);
sllogfile.savetofile('c:\logfile.txt');
slLogfile.free;
end;

I hope this is what you're after...
 
This is some old Delphi 2.0 / Win98 code. Not sure if
it will work in WinXP, but it might be worth a try...
[tt]
uses registry;

function GetBytesRecvd:Longint;
var
Buf: array[0..3] of Byte;
begin
Result:=0;
with TRegistry.Create do try
RootKey := HKEY_DYN_DATA;
if OpenKey('\PerfStats\StatData', False) then begin
ReadBinaryData('Dial-Up Adapter\BytesRecvd',Buf, 4);
Result:=LongInt(Buf);
end
finally
Free;
end;
if ( Result < 0 ) then Result:=0;
end;
[/tt]

Of course, the &quot;Dial-Up Adapter&quot; string would probably
be something different for a LAN, but if you have a look
( with regedit ) under HKEY_DYN_DATA\PerfStats\StatData
maybe you can adapt the code above.
 
Hi,
you can use PerfMon to get the value Of Bytes Sent (and many others, like CPU usage etc.).

Take a look at
ftp://Delphi-jedi.org/api/perfmon.zip
there is all the stuff needed to take every value you can get wit the performance Monitor ([System32]\perfmon.exe)


Ciao,
Geppo Darkson.

 
HKEY_DYN_DATA doesn't exist in my registry (WinXP), so either I have a wierd setup or the dropped it. Am searching for an equivalent now.
 
If you have a random Symantec product (forget which one in particular), stuff is dumped in HKEY_LOCAL_MACHINE\SOFTWARE\Symantec\IAM\Stats\Cumlative but other than that, I can't find anything.
 
Ok, I have the following, why didn't it work?

function GetBytesRecvd:Longint;
var
Buf: array[0..3] of Byte;
begin
Result:=0;
with TRegistry.Create do try
RootKey := HKEY_LOCAL_MACHINE;
if OpenKey('\SOFTWARE\Symantec\IAM\Stats\Cumlative', False) then begin
ReadBinaryData('TcpBytesRecieved',Buf, 4);
Result:=LongInt(Buf);
end
finally
Free;
end;
if ( Result < 0 ) then Result:=0;
end;

procedure TForm1.tmrMainTimer(Sender: TObject);
begin
lblRcvd.Caption := IntToStr(GetBytesRecvd);
end;

I know the key name is right. When my mouse is elsewhere, it says 0, when my mouse hovers over the window it says the same number all the time and occasioanlly a different number flashes up for a fraction of a sec.
 
Ok, so the key isn't updated for some reason, but what's with the random numbers?
 
Are you sure Symantec saves the value as binary?

Maybe you could put a case statement in the function,
to test the data type before trying to read it...

[tt]
function GetBytesRecvd:Longint;
var
Buf: array[0..3] of Byte;
begin
Result:=0;
with TRegistry.Create do try
RootKey := HKEY_LOCAL_MACHINE;
if OpenKey('\SOFTWARE\Symantec\IAM\Stats\Cumlative', False) then begin
case GetDataType('TcpBytesRecieved') of
rdUnknown:
Result:=LongInt(ReadFloat('TcpBytesRecieved'));
rdString:
Result:=StrToInt(ReadString('TcpBytesRecieved'));
rdExpandString:
Result:=StrToInt(ReadString('TcpBytesRecieved'));
rdInteger:
Result:=ReadInteger('TcpBytesRecieved');
rdBinary: begin
ReadBinaryData('TcpBytesRecieved',Buf, 4);
Result:=LongInt(Buf);
end;
end;
end
finally
Free;
end;
if ( Result < 0 ) then Result:=0;
end;
[/tt]


> occasioanlly a different number flashes up for a fraction of a sec.

If you set your timer interval to 1000 (one second)
the number should stay visible for at least a second.
( This also makes it easier to do &quot;bytes per second&quot; calculations. )
 
Another thing, just because a Symantec product has created the key,
doesn't mean it will be auto-magically updated. I would guess that
the program that writes to the key would also need to be running.
 
Check your spelling of &quot;Cumlative&quot;
Shouldn't that be &quot;Cumulative&quot; ?
 
Thanks for all the answers, I haven't tried anyone after the third tip, but I'll try them all today i think.

But I have already encountered some problems.

For awarnica's tip:
ExitWindowsEx(EWX_SHUTDOWN,0);
I do not get this to function right (Maybe because I use XP), I tried some other commands like EWX_REBOOT,0 and other things but Log Off to the 'login screen' it does not shut off.

And for cmgaviao's tip:
When I start the program it can't load up c:\logfile.txt even if I create a logfile.txt filein c:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top