Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to change display settings: screen resolution, screen refresh rate
Adding and deleting Scheduled Tasks using NetScheduleJob API functions
Capturing keyboard activity of another application with the Raw Input API (VFP9)
Converting Unicode data from the Clipboard to a character string using a given code page
Custom GDI+ class
Establishing connection using the SQLDriverConnect
Custom FTP Class for Visual FoxPro application
Detecting changes in connections to removable drives (VFP9)
Splash Screen for the VFP application
Winsock: sending email messages (SMTP, port 25)
How to create non-blocking Winsock server
How to print a bitmap file
GDI+: copying to the Clipboard (a) image of active FoxPro window/form, (b) image file
Peer-to-peer LAN messenger built with Mailslot API functions
Sending email messages with Simple MAPI
Custom HttpRequest class (WinINet)
How to create MD-5 and SHA-1 hash values from a string
Displaying animated images on FoxPro form with BitBlt and StretchBlt functions
Enumerating raw input devices attached to the system (keyboard, mouse, human interface device)
Displaying bitmap using the AlphaBlend function
Enumerating data formats currently available on the clipboard
How to put a vertical text scrolling on the form (a movie cast)
Mapping and disconnecting network drives
How to prevent users from accessing the Windows Desktop and from switching to other applications
Encapsulating access to the Windows Services in a class

User rating: 6/10 (1 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Versions:
click to open
Before you begin:
The winservices class, subclassed from the Collection class, enumerates Windows Services found in the default service control manager database on local computer.

Each item in the collection is an instance of the winservice class that wraps the members of ENUM_SERVICE_STATUS structure for a given service. The winservice object exposes methods StartService, StopService and PauseService.

Here is an example of how these classes can be used to start/stop the MSSQLSERVER service on local computer:

#DEFINE SERVICE_WIN32 0x30
#DEFINE SERVICE_RUNNING 4

LOCAL ws As winservices, srv As winservice
ws = CREATEOBJECT("winservices", Null, Null, SERVICE_WIN32)

srv = ws.GetService("MSSQLSERVER")
IF ISNULL(srv)
        ? "MSSQLSERVER service is not found on this computer"
ELSE
        ? "MSSQLSERVER service is " +;
                IIF(srv.currentstate=SERVICE_RUNNING,;
                "running", "stopped") + "."
ENDIF

srv.StartService()
*srv.PauseService()
*srv.StopService()

 
  Members area. Log in to view this example.
 
  User name:
  Password:
 
 
  Forgot your password?
 
  Sign up for
the Membership
 
 


User rating: 6/10 (1 votes)
Rate this code sample:
  • ~
8180 bytes  
Created: 2004-12-13 21:22:00  
Modified: 2011-12-10 09:20:22  
Visits in 7 days: 131  
Listed functions:
CloseServiceHandle
ControlService
EnumServicesStatus
GetLastError
LocalAlloc
LocalFree
LockServiceDatabase
OpenSCManager
OpenService
StartService
UnlockServiceDatabase
Printer friendly API declarations
My comment:
When starting a service you may encounter error code 1058 (The Specified Service is Disabled and Cannot Be Started).

* * *
WMI approach:



This is how to to start-restart the Messenger service using WMI objects:

oWmi = GetObject("winmgmts:\\" +;
        "." + "\root\cimv2")

oServices = oWmi.ExecQuery([SELECT * FROM ] +;
        [Win32_Service WHERE name="Messenger"])

FOR EACH oService IN oServices
        IF oService.StartMode = "Disabled"
                oService.ChangeStartMode("Manual")
        ENDIF
        IF NOT oService.Started()
                oService.StartService
        ENDIF
        RETURN
NEXT

Note that the Messenger service usually takes a few seconds to start. It does not happen immediately. Also the changing the start mode for this service from Disabled to Manual may pose security risk.

Win32_Service inherits the ChangeStartMode method from the Win32_BaseService class.

* * *
SC is a command line program used for communicating with the Service Control Manager and services.

USAGE:
sc [command] [service name] < option 1 > < option 2 > ...

EXAMPLE:
sc start MyService
sc query type= interact
Word Index links for this example:
Translate this page:
  Spanish    Portuguese    German    French    Italian  
FreeTranslation.com offers instant, free translations of text or web pages.
User Contributed Notes:
There are no notes on this subject.


Copyright © 2001-2013 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

Privacy policy
Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.1.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
Last Topics Visited (107.20.129.212)
2.32 hrs.Example: 'Retrieving country-specific dialing information from the Windows Telephony list of countries'
 Example: 'Retrieving information about the main VFP window'
2.71 hrs.Function: 'GetKeyState'
Function group: 'Keyboard Input'
 Example: 'Retrieving a universal form for the drive-based path for a network resource'
14.42 hrs.Example: 'MapiSendMail class for Visual FoxPro application'
14.43 hrs.Example: 'How to drag a Form not using its Titlebar or Caption'
1 day(s)Example: 'Custom GDI+ class'
 Example: 'Adding and deleting Scheduled Tasks using NetScheduleJob API functions'
Google
Advertise here!