Link to home
Start Free TrialLog in
Avatar of SilentBob
SilentBobFlag for Hong Kong

asked on

VB6 - random 2 min - 5 min delay + hide app from task manager

I need code to effect a random delay from 2 to 5 minutes, and I need the program to not show up on the task manager.  This is for a practical joke ;-)

Thanks.
Avatar of anv
anv

try this code...

add 2 timer Controls into ur application

set Timer2 Interval =5000 (i.e 5 Seconds) at design time

and paste this code...

Private Sub Form_Activate()
    Randomize (5)
    Dim i!
    i = Rnd() * 1000
    If ((i >= 2000) And (i <= 5000)) Then
        Timer1.Interval = i
    Else
        Timer1.Interval = 2000
    End If
End Sub

Private Sub Timer1_Timer()
    Me.Visible = False
    Timer2.Enabled = True
    Timer1.Enabled = False
End Sub

Private Sub Timer2_Timer()
    Timer1.Enabled = True
    Me.Visible = True
    Timer2.Enabled = False
End Sub
This "practical joke" code looks like it could be used for malicious purposes. For that reason I will not answer.

anv
That code will not work for the following reasons:
- Randomize (5) - will seed the timer, so that  - i = Rnd() * 1000 - will always return the same result into i.
- If ((i >= 2000) And (i <= 5000)) Then - will never be true i will always be less than 1000 because rnd() returns a number greater or equal to  0 and less than 1.

The timers will cause the form to flash on and off in 2 second intervals.
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SilentBob

ASKER

Hi all.  I worked out the timer part already thanks.  Just need to hide the app from trivial investigation.  Yes, I am aware this code can be used for malicious purposes, and could be a real headache for someone who doesn't know a lot about computers, but what I intend to code will not hurt anyone, and will definitely not go past a joke.  I understand trust is a rare comodity on a public group such as this where most people are strangers, so if you don't beleive me, that's cool.

Cheers,

split points between all..