Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Can I wake up a computer from screen saver with a VB executable?

Posted on 2004-10-22
20
Medium Priority
?
783 Views
Last Modified: 2008-02-01
I have a VB executable that notifies me of new email with a large flashing image.  Is there anyway to have the VB wake up the computer once it goes into the screen saver (of course I mean when the executable is run)?  I want the screen saver to kick in as normal so that teh screen does not burn in, but I would like for the executable to return the screen to the desktop and the flashing image so that I will see it.

If not with VB then maybe something else?
0
Comment
Question by:murryc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
  • 3
  • +2
20 Comments
 
LVL 4

Expert Comment

by:AjithJose
ID: 12386230
You have to find the screensaver window and post a wm_close message to it.

Check out this URL:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q140723

Or Try the API

PostMessage (GetForegroundWindow(), WM_CLOSE, 0, 0)

from VB if you are not running NT

0
 
LVL 8

Expert Comment

by:List244
ID: 12386607
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Type POINTAPI
    X As Long
    Y As Long
End Type

Private Sub MousePos(ByRef X As Long, ByRef Y As Long)
Dim Mouse As POINTAPI
GetCursorPos Mouse
X = Mouse.X
Y = Mouse.Y
End Sub

Private Sub SetX(X As Long)
Dim Mouse As POINTAPI
GetCursorPos Mouse
Mouse.X = X
RealMousePos Mouse
mouse_event &H1 Or &H8000, Mouse.X, Mouse.Y, 0, 0
End Sub

Private Sub RealMousePos(ByRef Point As POINTAPI)
Point.X = Point.X * (65536 / GetSystemMetrics(0))
Point.Y = Point.Y * (65536 / GetSystemMetrics(1))
End Sub

I would use this, then when you get new mail do:

Dim X as long,Y as long
MousePos X,Y
SetX x+5

This will send mouse movement. The reason I
suggest this is, if the screensaver is not active,
it will not close a different program (the other
method will). Also, such little mouse movement
will not cause troubles if screensavers not active.
Otherwise you need to MAKE SURE that the
screensaver is active, so you are not closing
the wrong program.
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 12386611
How about simulating a keypress:

Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_S = &H53&

Private Sub Command1_Click()
    keybd_event VK_S, 0, 0, 0 ' Press S
    keybd_event VK_S, 0, KEYEVENTF_KEYUP, 0 ' Release it
End Sub


0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 8

Expert Comment

by:List244
ID: 12386641
If you use Vinny's method, I would suggest taking out
the Sleep, seeing how it is unused.
0
 

Author Comment

by:murryc
ID: 12386643
I have increased the points to 500 from 250 because I need a little more help with implementing these solutions.  I am okay with either mouse movement or keypress so I will award points to whoever can add code to the already working VB code below and test it working to kill the screensaver.  I have very little experience with VB so I am unable to get either to work.  The code below is someones else's work and it works perfectly but I need to add the screen saver solution to it. Thanks.

VERSION 5.00
Begin VB.Form frmMain
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Message Notification"
   ClientHeight    =   3120
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   7065
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   208
   ScaleMode       =   3  'Pixel
   ScaleWidth      =   471
   ShowInTaskbar   =   0   'False
   StartUpPosition =   2  'CenterScreen
   Begin VB.Timer Timer1
      Enabled         =   0   'False
      Interval        =   1000
      Left            =   120
      Top             =   2520
   End
   Begin VB.CommandButton btnClose
      Appearance      =   0  'Flat
      Caption         =   "Close"
      Default         =   -1  'True
      Height          =   375
      Left            =   5760
      TabIndex        =   1
      Top             =   2640
      Width           =   1095
   End
   Begin VB.Label lblMessage
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      BackColor       =   &H80000005&
      Caption         =   "URGENT New message for Backup Guard"
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   13.5
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H80000008&
      Height          =   375
      Left            =   240
      TabIndex        =   0
      Top             =   1200
      Width           =   6495
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim arrParams As Variant, _
    lngRootColor As Long, _
    lngFlashColor As Long

Private Sub Form_Load()
    Dim strArguments As String, _
        intParamCount As Integer, _
        varTemp As Variant
    lngRootColor = frmMain.BackColor
    lngFlashColor = vbRed
    strArguments = Command()
    arrParams = Split(strArguments, "/", , vbTextCompare)
    For intParamCount = 0 To UBound(arrParams)
        varTemp = Trim(Mid(arrParams(intParamCount), 3))
        Select Case LCase(Left(arrParams(intParamCount), 1))
            Case "a"    'Account parameter
                lblMessage.Caption = lblMessage.Caption & " " & varTemp
            Case "c"    'Root color parameter
                lngFlashColor = Val(varTemp)
            Case "h"    'Height of the dialog-box parameter
                If IsNumeric(varTemp) Then
                    frmMain.Height = (Int(varTemp) * Screen.TwipsPerPixelX)
                End If
            Case "w"    'Width of the dialog-box parameter
                If IsNumeric(varTemp) Then
                    frmMain.Width = (Int(varTemp) * Screen.TwipsPerPixelY)
                End If
            Case "s"    'Speed parameter
                If IsNumeric(varTemp) Then
                    Timer1.Interval = CLng(varTemp)
                End If
        End Select
    Next
    btnClose.Top = frmMain.ScaleHeight - (btnClose.Height + 25)
    btnClose.Left = frmMain.ScaleWidth - (btnClose.Width + 25)
    lblMessage.Top = (frmMain.ScaleHeight - lblMessage.Height) / 2
    lblMessage.Left = (frmMain.ScaleWidth - lblMessage.Width) / 2
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
    Static bolRoot As Boolean
    frmMain.BackColor = IIf(bolRoot, lngRootColor, lngFlashColor)
    bolRoot = Not bolRoot
    DoEvents
End Sub

0
 
LVL 8

Expert Comment

by:List244
ID: 12386724
Are you using Visual Basic or Wordpad???
Is the vb EXE that tells you you have mail
something you have code for , or a seperate
program?
0
 

Author Comment

by:murryc
ID: 12386729
I am using Visual Basic to compile the code I provided.  I use another program to fire the exe that the visual basic creates.  All of the process is working okay, I just need to be able to see the flashing message when the screen saver is running.  I just paste the completed code into notepad and name *.frm then open in VB.
0
 
LVL 8

Expert Comment

by:List244
ID: 12386745
Okay for the code I provided:

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Type POINTAPI
    X As Long
    Y As Long
End Type

Private Sub MousePos(ByRef X As Long, ByRef Y As Long)
Dim Mouse As POINTAPI
GetCursorPos Mouse
X = Mouse.X
Y = Mouse.Y
End Sub

Private Sub SetX(X As Long)
Dim Mouse As POINTAPI
GetCursorPos Mouse
Mouse.X = X
RealMousePos Mouse
mouse_event &H1 Or &H8000, Mouse.X, Mouse.Y, 0, 0
End Sub

Private Sub RealMousePos(ByRef Point As POINTAPI)
Point.X = Point.X * (65536 / GetSystemMetrics(0))
Point.Y = Point.Y * (65536 / GetSystemMetrics(1))
End Sub


Paste the above in the declarations under General.
Then paste the following code where you need the
screensaver disabled:

Dim X as long,Y as long
MousePos X,Y
SetX x+5

(In an exisiting sub of course)
0
 

Author Comment

by:murryc
ID: 12386964
please excuse my ignorance in Visual Basic.  I am unable to understand where to place your code.  I want to execute your mouse movement at the end of the process.  Can you please insert all of your code in the correct place within the code I have provided.  I will then create a frm file with that code and compile it.  Thank you again.
0
 
LVL 8

Assisted Solution

by:List244
List244 earned 1400 total points
ID: 12386999
VERSION 5.00
Begin VB.Form frmMain
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Message Notification"
   ClientHeight    =   3120
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   7065
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   208
   ScaleMode       =   3  'Pixel
   ScaleWidth      =   471
   ShowInTaskbar   =   0   'False
   StartUpPosition =   2  'CenterScreen
   Begin VB.Timer Timer1
      Enabled         =   0   'False
      Interval        =   1000
      Left            =   120
      Top             =   2520
   End
   Begin VB.CommandButton btnClose
      Appearance      =   0  'Flat
      Caption         =   "Close"
      Default         =   -1  'True
      Height          =   375
      Left            =   5760
      TabIndex        =   1
      Top             =   2640
      Width           =   1095
   End
   Begin VB.Label lblMessage
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      BackColor       =   &H80000005&
      Caption         =   "URGENT New message for Backup Guard"
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   13.5
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H80000008&
      Height          =   375
      Left            =   240
      TabIndex        =   0
      Top             =   1200
      Width           =   6495
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim arrParams As Variant, _
    lngRootColor As Long, _
    lngFlashColor As Long

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Type POINTAPI
    X As Long
    Y As Long
End Type

Private Sub MousePos(ByRef X As Long, ByRef Y As Long)
Dim Mouse As POINTAPI
GetCursorPos Mouse
X = Mouse.X
Y = Mouse.Y
End Sub

Private Sub SetX(X As Long)
Dim Mouse As POINTAPI
GetCursorPos Mouse
Mouse.X = X
RealMousePos Mouse
mouse_event &H1 Or &H8000, Mouse.X, Mouse.Y, 0, 0
End Sub

Private Sub RealMousePos(ByRef Point As POINTAPI)
Point.X = Point.X * (65536 / GetSystemMetrics(0))
Point.Y = Point.Y * (65536 / GetSystemMetrics(1))
End Sub
Private Sub Form_Load()
    Dim strArguments As String, _
        intParamCount As Integer, _
        varTemp As Variant
    lngRootColor = frmMain.BackColor
    lngFlashColor = vbRed
    strArguments = Command()
    arrParams = Split(strArguments, "/", , vbTextCompare)
    For intParamCount = 0 To UBound(arrParams)
        varTemp = Trim(Mid(arrParams(intParamCount), 3))
        Select Case LCase(Left(arrParams(intParamCount), 1))
            Case "a"    'Account parameter
                lblMessage.Caption = lblMessage.Caption & " " & varTemp
            Case "c"    'Root color parameter
                lngFlashColor = Val(varTemp)
            Case "h"    'Height of the dialog-box parameter
                If IsNumeric(varTemp) Then
                    frmMain.Height = (Int(varTemp) * Screen.TwipsPerPixelX)
                End If
            Case "w"    'Width of the dialog-box parameter
                If IsNumeric(varTemp) Then
                    frmMain.Width = (Int(varTemp) * Screen.TwipsPerPixelY)
                End If
            Case "s"    'Speed parameter
                If IsNumeric(varTemp) Then
                    Timer1.Interval = CLng(varTemp)
                End If
        End Select
    Next
    btnClose.Top = frmMain.ScaleHeight - (btnClose.Height + 25)
    btnClose.Left = frmMain.ScaleWidth - (btnClose.Width + 25)
    lblMessage.Top = (frmMain.ScaleHeight - lblMessage.Height) / 2
    lblMessage.Left = (frmMain.ScaleWidth - lblMessage.Width) / 2
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
    Static bolRoot As Boolean
    frmMain.BackColor = IIf(bolRoot, lngRootColor, lngFlashColor)
    bolRoot = Not bolRoot
    DoEvents
End Sub


Then wherever it should be turning off the screensaver
(Im confused on where you want that to happen) you
would put:

Dim X as long,Y as long
MousePos X,Y
SetX x+5

(Where you want it to disable the screensaver though,
I am confused, so it's up to you to place the LAST
bit of code) The rest was placed for you.
0
 

Author Comment

by:murryc
ID: 12387229
it works...I would also like to create a seperate exe with just your code that I can run by itself.  I thought I could do that simply and it works but it creates a small prompt that I have to close manually.  Can you assemble code for that too and include a way to make sure it closes any windows it opens.

Again, I just want seperate code of your solution that I can compile by itself without any of my stuff but I want it to move the mouse then exit completely.
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 12393139
Only need to use the below to move the mouse 10 "mickeys" to the right:

Call mouse_event(&H1, 10, 0, 0, 0)

:P
0
 

Author Comment

by:murryc
ID: 12394829
zzzzzzooc...

I have no experience with Visual Basic, can you make me a complete VB code that I can compile with VB into an exe that will move the mouse as you describe?  I create an FRM file in notepad with the source code then open with VB and create the exe.
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 12397952
Comment was directed towards List244. It was his suggestion so I'm not going to "muscle in" after his time spent helping. Just trying to make things simpler.
0
 
LVL 8

Expert Comment

by:List244
ID: 12401318
MurryC, I told you put the line wherever it should be disabling the screensaver.
From looking at the code, it appears to me there is no spot where it is to
disable the screensaver. On form load would make no sense, and your
timer.... Has no Ifs.. So, really I don't quite see what you are doing
here. I think you have a seperate program that tells you if you have
mail, and you are trying to write an add-on that makes it disable the
screensaver as well, and well... With your experience in VB... That
is going to be rough, even if one of us GAVE you a solution... Sorry.

However, maybe that program launches yours when you get new mail?
If so, put the mouse-move code on form load. Otherwise... Put it in
the timer, and watch your mouse go crazy as long as your program
is running. Sorry I couldn't help more.
0
 
LVL 8

Expert Comment

by:List244
ID: 12401345
Zzzzzooc If you happen to understand his problem
any better than I apparently do, go right ahead and
jump in, I've helped all I can.
0
 

Author Comment

by:murryc
ID: 12402454
List244.. the overall solution with my existing coding works great, inlcuding what you added for me.  It would be hard for me to explain what it all does for me and how I run it, but I do use a batch file that runs the executable with additional switch information.  All I want now is just to have a VB executable that does nothing but moves the mouse when executed.  I implemented your coding into my exiting code and placed the line where I wanted it and it wakes up the computer when the exe executes.  I would now like to just have your code by itself in an executable that if run does nothing but wakes the computer from the screen saver.  I tried creating the FRM file with just your code and it works but it also opens a small window prompt that has to be closed.  I am sure it can just run and close all on its own, I just do not know how to do it.

Is that a better explaination?
0
 
LVL 17

Accepted Solution

by:
zzzzzooc earned 600 total points
ID: 12405181
>>I am sure it can just run and close all on its own, I just do not know how to do it.

1.) Create a new project.

2.) Remove Form1 (right-click on it in the list and choose "Remove Form1").

3.) Add a new Module (Project -> Add Module)

4.) Copy and paste the below into the new Module (Module1):

Option Explicit

Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Sub Main()
    Call mouse_event(&H1, 10, 0, 0, 0)
End Sub

5.) Compile it. When it's run, it'll move the mouse cursor 10 mickeys to remove the screensaver and then exit immediately. However, you're in trouble if the screensaver has a password. ;)
0
 

Author Comment

by:murryc
ID: 12406174
thanks to both list244 and zzzzzooc for the solutions..they both work great...majority of points to List244 for providing main solution...others to zzzzzooc for following up with additional request
0
 

Author Comment

by:murryc
ID: 12406188
list224 was supposed to get the accepted answer and zzzzzooc was supposed to get assisted but I reversed them by accident..points where split correctly though..thanks again
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question