Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Disk in drive A:
Displaying the drive type value
GDI+: enumerating fonts installed on the system
GetFocus returns a HWND value
Reading header information from AVI file
Retrieving information about the main VFP window
Retrieving list of all active RAS connections
Verifying a file using the Authenticode policy provider
Form Magnifier
Using the DrawText function
Enumerating print processors and supporting data types installed on the specified server
High-powered ALLTRIM
Obtaining Shell32.dll version
Quering Audio Mixer Device
Using FtpCommand
Using the SystemParametersInfo function
DiskFreeSpace class
Enumerating ports that are available for printing on a specified server
How to view system icons for the classes installed on the local machine
Pocket PC: base class
Reading the state of mouse buttons within DO WHILE loop
Retrieving information about MS-DOS device names using QueryDosDevice (WinNT only)
The DetectAutoProxyUrl function identifies the auto-config script location
Using GetNearestColor
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: 102  
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.
Google
Advertise here!