Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Enumerating data formats currently available on the clipboard
GDI+: retrieving list of available image encoders and image decoders
Obtaining addresses for the adapters on the local computer (Win XP/2003/Vista)
Quering a waveform-audio input device
Reading data from INI files
Winsock: retrieving information about available transport protocols
Enumerating devices installed on the local machine
How to create a desktop shortcut (shell link)
How to obtain Content-Type value for a file type from the System Registry
How to retrieve adapter information for the local computer (including MAC address)
How to run FoxPro application under different user name (impersonating user)
How to view icons stored in executable files (Icon Viewer)
Retrieving IP statistics for the computer
Winsock: how to retrieve the protocol information corresponding to a protocol name
Winsock: resolving an address to a host name
PocketPC: custom RAPI class for executing routines on remote Windows CE device
Programmatically removing submenus from VFP main menu
Retrieving the name of the default printer for the current user on the local computer (Win NT/XP)
Validating URLs using moniker functions
Converting a hexadecimal string to an integer
Finding out if the current user is the Guest account
How to display advanced Task Dialog (Vista)
How to display the port-configuration dialog box for a port on the specified server
How to play a waveform sound (a WAV file in particular)
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: 101  
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 (50.16.36.153)
12.82 min.Function: 'AVIStreamLength'
Function group: 'Windows Multimedia'
12.87 min.Example: 'Extensible Storage Engine class library'
1.96 hrs.Example: 'How to display Windows On-Screen Keyboard'
2.71 hrs.Function: 'CeCreateDirectory'
Function group: 'Remote Application Programming (RAPI)'
 Example: 'Using the FindMediaType function'
2.72 hrs.Example: 'Simple printer queue monitor: deletes, pauses, resumes print jobs for local printer'
2.82 hrs.Example: 'Exporting DLL icon resources as .ICO files'
2.83 hrs.Function: 'GdipCreateFromHDC'
Function group: 'GDI+ Graphics'
3.14 hrs.Example: 'Accessing Windows Control Panel from VFP Application'
 Function: 'GdipSaveImageToFile'
Google
Advertise here!