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
Related
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.
Basically I have some C/C++ code that I need to build and debug on a Linux machine. Unfortunately, my windows laptop doesn't have enough free hard space to install some Linux dist nor does it have enough free RAM to comfortably run VM.
Until now, I dealt with it rather comfortably using WSL, but the scale was rather small. It was easy to edit and debug 2-3 .c files through CLI and gdb, but it became really annoying on a large scale projects.
I want something simple as "edit code in windows IDE [X], compile it on remote Linux/WSL (the project uses Makefiles), and preferably debug it via gdb".
VS has something close to what I want, but it can't deal with existing Linux projects. It needs to create a new configuration which is alien to the project's Makefile.
I know this question is a bit old, but I think the solution is to make a symlink between your WSL folder and the Window's folder. This is how I handled it for a Ubuntu-20.04 WSL:
Access PowerShell in Administrator mode
Type cmd.exe in the PowerShell
Once cmd.exe is opened, type mklink /d C:\<path_to_your_Windows_folder> \\wsl$\Ubuntu-20.04\home\<your_user>\<path_to_your_WSL_folder>
EDIT
This was tested under Windows 10 Version 2004 with WSL2
I'm unsure about C and C++ but it sounds like this is exactly the same as how i work in node and javascript every day.
I checkout my code using git inside WSL to a location like /mnt/c/code/myproject. Then using sublime/VS code/webstorm i edit the files in windows in the location c:\code\myproject this works really well and have been doing this every day for over a year.
Things to be aware of are that you need to ensure that your editor of choice saves files with linux line endings and that all command line operations are done inside WSL.
Please see this article to see the differences between windows and linux files and how this works inside the WSL.
I want something simple as "edit code in windows IDE , compile it on remote linux/WSL
You will have something as simple as that.
Only with Windows 19.03 though:
See "Updated WSL in Windows 10 version 1903 lets you access Linux files from Windows"
Microsoft's Craig Loewen says:
In the past, creating and changing Linux files from Windows resulted in losing files or corrupting data. Making this possible has been a highly requested and long anticipated feature. We're proud to announce you can now easily access all the files in your Linux distros from Windows.
So how does this work? He goes on to explain:
To put it briefly: a 9P protocol file server facilitates file related requests, with Windows acting as the client.
We've modified the WSL init daemon to include a 9P server. This server contains protocols that support Linux metadata, including permissions.
There is a Windows service and driver that acts as the client and talks to the 9P server (which is running inside of a WSL instance).
Client and server communicate over AF_UNIX sockets, since WSL allows interop between a Windows application and a Linux application using AF_UNIX as described in this post.
Warning:
The old rules still apply, you should NOT access your Linux files inside of the AppData folder!
If you try to access your Linux files through your AppData folder, you are bypassing using the 9P server, which means that you will not have access to your Linux files, and you could possibly corrupt your Linux distro.
Is there a way to keep my Linux services running after I close the bash prompt? I had hoped that this would be a little more robust than it actually is. When I close bash on Windows 10 everything shuts down, which I should have expected of course.
This is not currently possible, but Microsoft is aware of it and may add that functionality in future.
I'm trying to port an application written in C from linux to windows.
At the moment I'm done fixing the 'hard' parts like missing posix features and the like.
The application compiles, links and works on Windows now (except for the fork() stuff which will be replaced with windows service code later).
The only problem I'm having now is that within the MSYS shell it all works (this maps unix paths for me).
Outside of the MSYS shell it won't work because ~ is not available.
I'm looking for the best way to set the windows user home within my #ifdef stuff.
I read about %USERPROFILE% somewhere but that doesn't seem to work.
Use SHGetKnownFolderPath (Vista+) or SHGetFolderPath depending on your Windows version.
I think you should use the SHGetFolderLocation API:
http://msdn.microsoft.com/en-us/library/bb762180%28VS.85%29.aspx
well not enought, you should even retrieve the ID of the user folder, but by starting at the doc location above you should have all what you neeed.
This should works on any windows version.
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.