Install/Uninstall C Windows Service - c

I have written a windows service in C. I would like to install/uninstall it without using .NET framework (installutil) or a visual studio installer (because I'm writing this in C).
I am using NSIS to install my application which contains this service among many other things. Can NSIS install/uninstall windows services, if not, how can I programatically install/uninstall a windows service in C. I have seen examples of this for C# and VB but not for C.

The NSIS documentation lists the various possibilities. You simply need to pick the one most suitable to your needs.
It's much easier to get NSIS to do this than to script it yourself by calling the service control manager API.

Yes you can create service using NSIS. Take a look at these examples

There is no built in method in NSIS to install a windows service but you can simply us sc.exe with the "create" parameter to install it.
The details on the sc.exe command can be found here: http://support.microsoft.com/kb/251192
and you would simply call it from NSIS with a command like this
Exec '"sc.exe" create ServiceName otherparameters'

Related

List all installed Windows updates - Programmatically in C

As stated in the title, I have to implement a program in C, that retrieves all the installed Windows updates.
I've seen I can execute a command like wmic qfe get Hotfixid, and just take its output, but not sure it's the most elegant thing to do.
I wonder if there is another approach to perform it in C. Do you have an idea?
You can refer to Searching for Installed Windows Updates. The case supplied two c++ solutions. One is Windows Shell API FOLDERID_AppUpdates and the other is Windows Update Agent API IUpdateSession with CoCreateInstance.

How to use shp2pgsql

My question should be very simple to answer for anyone not being a self-taught newbie like me...
On this page is a cheatsheet concerning a function to be used in GIS/DB environnement : http://www.bostongis.com/pgsql2shp_shp2pgsql_quickguide.bqg
I would like to create a script allowing users to just have to click on it to launch the process, given the proper datas. But I don't understand how to use this. It obviously doesn't work in a Python console, nor directly in the windows console. How is it supposed to work ? What language is this ?
Thanks
shp2pgsql is indeed a command line tool. It comes with your PostgreSQL/PostGIS installation (usually) and, if not accessible via PATH-variable, can (usually) be run from within the /bin-folder in your PostgreSQL-Installation. You can also always 'make' the programm from source in any location yourself, if needed.
EDIT:
One way to set up a script (independent of whether you use it within qgis own python environment or not) would be to use Pythons subprocess (or os.system) module (check related question here) to write to shell and execute shp2pgsql.
A slightly more sophisitcated solution to (batch) insert (multiple) shapefiles via script could be to implement ogr2ogr via gdal/ogr module within python (check this blog). That, however, would require a working installation of the gdal core library, and the respective Python bindings (at least to use outside of QGIS Python environment, where it is pre-installed AFAIK), which can be tiresome at times. Once installed correctly, it offers a powerful (I dare say almighty) toolset for geodata management and manipulation via Python, though.
Apart from that, the blog link I provided also states the implementation of a batch insert script/tool (which operates ogr2ogr) in qgis 2.8 toolbox...maybe that can help you, either with your work directly or (via sourcecode) to point you in the direction of creating your own tool.

Checking installation integrity with installshield

For Linux packages, specifically RPMs with stored checksums, we always can check two things: the contents of package is ok and the installation from this package is ok. When someone modifies parts of the installation he shouldn't, we can see it by running rpm -Vp my-precious-package. In our busyness it is not only recommended, but obligatory to provide our packages with tools for this purpose and for Linux these are just simple bash scripts.
Now I have to do something similar for Windows. Basically what I want is to provide some batch file by running which one can get assured, the installation is the same as it meant to be in the package. I'm using InstallShield for packaging, and yet it has some great visual tools, I still haven't found a way to verify package checksums in the command line.
Is it even possible, or should I reinvent the wheel writing my own checking utils?
Take a look at MakeCat and SignTool from Microsoft, both in SDK
http://msdn.microsoft.com/en-us/library/windows/desktop/aa386967%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/aa387764%28v=vs.85%29.aspx
Windows Installer has a feature called resiliency that supports auto repair of products and there are ways to call it for self checks only. (This is assuming by InstallShield you mean Windows Installer based projects.)
Here's a couple links to read to get you started:
INFO: Description of Resiliency in Windows Installer
Resiliency
Application Resiliency: Unlock the Hidden Features of Windows Installer
MsiProvideComponent function (See dwInstallMode flags)
This also assumes all files are key files. Companion files are not managed by the installer. Also changes performed by custom actions outside of the installer aren't managed.

what is the win32 alternative to the Unix daemon() subroutine?

I have to call several (> 10) .exe command line programs in the background.
Creating a Windows Services doesn't sound very appealling in this context - c'mon, that's a bit overpowered for such a simple task.
Is there anything like a daemon(3) subroutine for Windows?
You might look into using the srvany.exe service wrapper found in the Windows Server 2003 Resource Kit Tools. I have used this method quite successfully under Windows XP, but I cannot comment on how it may work for newer versions of the OS.
There seems to be plenty of information available1 on how to use this tool.
1 - Google search for srvany+howto

Windows Scripting: What and How to do this? Batch Files or Something else?

What I am trying to do is have some sort of script run in windows (ideally .cmd file/batch file) when double clicked it should create a short-cut menu in the start menu and set a path in the windows registry (i think thats what it is called) so that next time, for example, all I have to is get the variable JAVA_HOME to get the path I need.
What I need help in this is just examples on how to do these, what tutorials I should look at or even what key terms to search in Google (seriously) as I am very new to windows programming and what's used for what etc.
Thanks all
If you want to target all versions of Windows, your best choice is writing a MS-DOS Batch file (.bat). Here's a good tutorial that I've used in the past.
If you are targeting modern versions of Windows (Windows XP SP2/2003/Vista/7) you should definitely take a look at Windows PowerShell, which is the new standard automation engine for the Windows platform.PowerShell is a separate download for Windows XP SP2, Windows Server 2003 and Windows Vista, while it is included in Windows Server 2008 and Windows 7.
About Windows PowerShell
PowerShell is built on top of the .NET Framework and consists of a runtime environment, a scripting language and an interactive console.Here are some of its key features that I find most valuable:
All processing is done using CLR objects, instead of text as in traditional shells
It is possible to interact directly with the classes in the .NET Framework
It is possible to run commands written in any .NET language and distributed as DLLs (called Cmdlets)
Great collection of built-in commands to accomplish most administrative tasks
The scripting language's syntax is C-style (curly braces...)
The runtime can be hosted inside any managed process as an ad-hoc automation engine
This isn't of course a complete list of all the features in PowerShell. If you are interested, I recommend you to look into it. Here is a good place to start.

Resources