Is a Console Application & Windows Form Application combination possible? - console-application

I use Visual Studio 2010 and am coding in C#. A couple of people I know have a difference of opinion on what format these programs should be in, console or windows form. These programs usually just install\delete\modify\create other files given some settings and files already provided to the program.
The reasoning for the console application is to have the ability use it in batch scripts for unmanned execution and repetition with different settings. The reason for the Windows Application is ease of use instead of typing command line options and arguments. Is it possible to combine both of these or is it even a good practice?

If what you want to do, given the right values, can be pulled out into a shared project then yes. You then have two more projects: the console app, and the windows app. Both of these take a reference to the shared project with the meat of the logic. The app projects are there to give an interface into the shored project.
Personally, if the app is just going to use values given to it I'd give it a config file and make it a console app that pulls from that config. You could then have it set up differently on different servers. You could even put different named configuration in that file and have the console app do nothing but ask with named config to use. If the app can be a console app and it is for use by programmers/admin/other power user type people, then it is likely it doesn't really need a windows UI over it.

Related

WebStorm with mulitple projects attached - open a tool window for a certain project

I've got a project with four different repositories.
Recently, instead of opening four different windows, I've decided to open up the most important repo and attach to it the other projects.
However, it seems all of WebStorm's tool windows (VCS et cetera) are still bound to the main project, and there doesn't seem to be a convenient way to manage all the projects from one WebStorm instance.
Is it possible to, for example, open the VCS tool window and easily switch it focus between projects?
no, it's not. Attaching projects to current one is more or less equal to adding content roots, it's a single project for the IDE. See https://www.jetbrains.com/help/webstorm/2019.2/opening-reopening-and-closing-projects.html#428b6b3d
Related feature requests:
https://youtrack.jetbrains.com/issue/WEB-39009
https://youtrack.jetbrains.com/issue/WEB-39015
https://youtrack.jetbrains.com/issue/IDEA-218888
https://youtrack.jetbrains.com/issue/IDEA-217413

How to create a login application with Visual Basic (using WebHttpRequest)

Hei there, I'm not experienced at all in C++ as I need to start learning year the next year at my university, though, I've been creating a browser based game and I'm looking for someone to transform it into pc app.
Though, I'm wondering how to make that application send a http request via POST to a file on my webserver with the username / pw.
After all the tutotials I've been reading, I concluded that none worth spending my time with, because they all based on own database, and I'm looking for one that connects to a maestro server and requests the data from there.
This may not be the answer you are looking for, but you may consider two alternatives to a more pure C++ application.
If you already have a working browser game, try to take that same code and put the html/javascript/whatever in a file and give the file a ".hta" extention. It basically opens inside a browser to run your files, but it acts more like an application from the user's viewpoint. (And, as much as I hate Windows, they're pretty fun to create if I may say so). However, your source code with this option is easily read because it can be renamed to a text file (or html file).
You could use Visual C++ (or VB.net, which you have tagged to the question, as well as "Visual" C#) to create an application which mostly consists of a browser view. It could be a "standalone" application (however would rely completely on the .Net framework - may or may not be what you want) that basically accomplishes the same as the option above, but adds that you can "hide" your files inside your application.
Using the two above alternatives, you could make an application relatively quickly that would load your files, which I assume you have already created. Note that neither of the above alternatives will work on anything other than Windows OS's.
If the two above alternatives are not what you want, or if you have questions about either one, I'd be glad to attempt to help.
I've been able to find a friend that would do it in Delphi because I wouldn't want users to download net framework just for this ap.
So the program that would fit most for any apps is Delphi Prism XE (even if it's an addon of Visual Studio)

Where should my win32 program keep its files?

Our win32 applications (written in C++) have been around for over 10 years, and haven't been updated to follow "good practices" in terms of where they keep files. The application defaults to installing in the "C:\AppName" folder, and keeps application-generated files, configuration files, downloaded files, and saved user documents in subfolders of that folder.
Presumably, it's "best practices" to default to installing under "c:\Program Files\AppName" nowadays. But if we do that, where should we keep the rest of our files? Starting from Vista, writing to the program files folder is problematic, and there seem to be a million other places that you can put different files, and I'm confused.
Is there a reference somewhere for what goes where?
Edit: To expand on questions people have asked so far:
I'm familiar with the SHGetFolderPath function, but there are lots and lots of options that you can get from it, and I can't find a resource that says "Here is exactly what each of these options is used for, and when you might want to use it".
Up until now, we've done the "All files, including saved user files, under one folder" thing, and it's worked fine - but not when people want to install the app under the Program Files folder. For some reason, the virtualization monkeying around that Vista does isn't working for our application; if we're going to be making changes anyway, we might as well make an effort to do things the "right" way, since we don't want to have to change it again in 12 months time.
Further question:
We include some "sample" documents with our app, which we update every now and again. Is it appropriate to install them into My Documents, if we'll be overwriting them every few months? Or is My Documents assumed to be totally safe for users to mess around in?
If we can't install them to My Documents, where should we put them so that users can see them easily?
Presumably, it's "best practices" to default to installing under "c:\Program Files\AppName"
Close, but not quite. Users can configure the name of the Program Files folder and may not even have a C: drive. Instead, install to the %ProgramFiles%\AppName environment variable folder.
Note you should assume you only have read access to this folder after the installation has finished. For program data files where you might need write access, use %AppData%\AppName.
Finally, are you sure yours is the only app with that name? If you're not 100% certain of that, you might want to include your company name in there as well.
The mechanisms you use to retrieve those variables will vary depending on your programming platform. It normally comes down to the SHGetFolderPath() Win32 method in the end, but different platforms like Java or .Net may provide simpler abstractions as well.
Some guidelines are in this Knowledge Base article: How to write a Windows XP Application that stores user and application data in the correct location by using Visual C++. Also, if you search MSDN for Windows Logo Program you will find documentation regarding what an app needs to do to be truly compliant.
SHGetKnownFolderPath can get you the directories you need. If backwards compatibility with XP and earlier is required, use the deprecated SHGetFolderPath
Having said that, if you app came with documentation that said "everything used by this app is in this directory" I would love it ;)
Use the Windows SHGetFolderPath() function to get the correct directories.
Edit: To reply to your other question, added in the edit: Where to put the sample files of your application does very much depend on whether your application is installed for a single user or for all users, and whether the person installing the application can be assumed to be the one who uses it.
If your program is to be used by multiple users on a system, copying stuff into "My Documents" is not going to work - the files would be accessible only for the user installing the application. Worse, if the only user of your application needed to install as Administrator, then [s]he will not have access to the files either. So unless you are fairly certain that there is only one user for your application, and they have sufficient permissions to install the application using their own account, don't use "My Documents".
IMO you should install sample files into the directory identified by CSIDL_COMMON_APPDATA. This will give you exactly one copy for all users, and since you want every user to see the original, unaltered sample files all users should consider them read-only. In fact, your setup program should probably make them read-only. Opening one of the samples will work for all users, but as soon as they try to save their modifications the application should detect that the file is read-only, and open the "Save As" dialog, pointing to "My Documents" or suitable directory inside. That will also keep all user modifications when the installer updates the sample files later on.
It is of course somewhat more difficult for the users to find the sample files. You could add a link to the samples folder to the start menu group of your application, so that access to the files is fast, and of course you should properly document everything.
For your application binaries, you can assume that you may write to the PROGRAM FILES directory (use the %ProgramFiles% environment variable to support installations other than the default English version - e.g. in german Installations this will be c:\Programme by default). Wikipedia lists the most common variables. Another option are the SHGetFolderPath or newer SHGetKnownFolderPath functions.
For User data, you should assume that the application is running with limited access rights and may only write to the user's home directory. Same applies for registry entries. This path should probably be configurable b the user, as the home directory may actually be a network server and a user might have a second disk attached for data storage. For information on the current (Vista) filesystem guidelines see this article.
Regarding plugins, this might be more complicated. The best practice seams to be offering the option to install for the current user only, and placing the plugin in the user directory, or install for all users and place the files into your program files directory (but remember to check for write permission and request elavated access if needed).
There are plenty of environment variables like: %USERPROFILE%, %HOMEPATH%, %APPDATA% all of these points to some user-specific directories, where you can put your user-specific files.
For system-wide storage you can use %ALLUSERSPROFILE%, that is the place where you should put your read/write datafiles that are not specific to any user.
Sorry I don't know the correct answer, but...
Do you have a business case for wanting to do that? Are your customers complaining that files aren't stored where they expect? Are your applications crippled in some way because you store files in non-standard locations? If not, I don't see a reason for spending time and budget to redo your file storage strategy just to meet "best" practice. If your programs just work, then IMHO you should leave them alone and spend money and time on things that matter.
There is a directory structure under c:\users for user oriented data.
There is documentation for porting apps from older windows OSs to Vista.
Check out http://www.innovateon.com and follow the links to Vista. There is documentation regarding certification that has the details on topics like this.
We have a similar app created ~10 years ago using MFC. The easiest thing to do was create a folder right off of C:\ (e.g. C:\OurApp). No install files, no special permissions, no registry changes, etc. Clients (and particularly their sys admins) LOVE it.
One other consideration - are you planning to all of a sudden change the installation folder for existing clients (assuming this is installed in many locations)? If something isn't broke, why fix it?

What is the best way to get all Windows startup processes using Windows API?

I know there are startup folders and certain registry keys I need to look into. But how to do that using Windows API? I'm interested to know for Windows XP and Vista. Thanks for your time.
There is no single API to get all the programs that run while the system is starting up. Consider all the things that Autoruns shows. Updates to that program occasionally allow it to show new classes of programs, and since those are updates to the program and not to the OS, it's obviously not some API that's changing to include more things. Rather, it's the program that's gradually expanding its notion of what an "auto-run program" is.
Work out what you wish to consider to be a "startup process," and then you can determine what APIs or other techniques you can combine to find out what all those processes are.
Among the places to look include the following:
The "run" registry key, like AJ mentioned.
The "startup" menu, as given by various constants used with ShGetFolderPath and some of its related functions.
Tasks scheduled to run on login.
Services.
Each bullet point includes at least one link to a page on MSDN that should get you started. If you need more, consider asking some more specific questions.
I am not sure such an API exists. Nevertheless you can write a function to do that.
The startup process names and location are stored in following location in registry:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
<Name> <Location of EXE>
You can write small function to open the above registry and read the startup process details.

how-to: programmatic install on windows?

Can anyone list the steps needed to programatically install an application on Windows. Aside from copying the files where they need to be, what are the additional steps needed so that your app will be a first-class citizen in Windows (i.e. show up in the programs list, uninstall list...etc.)
I tried to google this, but had no luck.
BTW: This is for an unmanaged c++ application (developed in Qt), so I'd rather not involve the .net framework if I don't have to.
I highly recommend NSIS. Open Source, very active development, and it's hard to match/beat its extensibility.
To add your program to the Add/Remove Programs (or Programs and Features) list, add the following reg keys:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\PROGRAM_NAME]
"DisplayName"="PROGRAM_NAME"
"Publisher"="COMPANY_NAME"
"UninstallString"="PATH_TO_UNINSTALL_PROGRAM"
"DisplayIcon"="PATH_TO_ICON_FILE"
"DisplayVersion"="VERSION"
"InstallLocation"="PATH_TO_INSTALLATION_LOCATION"
I think the theme to the answers you'll see here is that you should use an installation program and that you should not write the installer yourself. Use one of the many installer-makers, such as Inno Setup, InstallSheild, or anything else someone recommends.
If you try to write the installer yourself, you'll probably do it wrong. This isn't a slight against you personally. It's just that there are a lot of little details that an installer should consider, and a lot of things that can go wrong, and if you want to write the installer yourself, you're just going to have to get all those things right. That means lots of research and lots of testing on your part. Save yourself the trouble.
Besides copying files, installation tasks vary quite a bit depending on what your program needs. Maybe you need to put an icon on the Start menu; an installer tool should have a way to make that happen very easily, automatically filling in the install location that the customer chose earlier in the installation, and maybe even choosing the right local language for the shortcut's label.
You might need to create registry entries, such as for file associations or licensing. Your installer tool should already have an easy way to specify what keys and values to create or modify.
You might need to register a COM server. That's a common enough action that your installer tool probably has a way of specifying that as part of the post-file-copy operation.
If there are some actions that your chosen installer tool doesn't already provide for, the tool will probably offer a way to add custom actions, perhaps through a scripting language, or perhaps through linking external code from a DLL you would write that gets included with your installer. Custom actions might include downloading an update from a specific Web site, sending e-mail, or taking an inventory of what other products from your company are already installed.
A couple of final things that an installer tool should provide are ways to apply upgrades to an existing installation, and a way to uninstall the program, undoing all those installation tasks (deleting files, restoring backups, unregistering COM servers, etc.).
I've used Inno Setup to package my software for C++. It's very simple compared to heavy duty solutions such at InstallShield. Everything can be contained in a single setup.exe without creating all these crazy batch scripts and so on.
Check it out here: http://www.jrsoftware.org/isinfo.php
It sounds like you need to check out the Windows Installer system. If you need the nitty-gritty, see the official documentation. For news, read the installer team's blog. Finally, since you're a programmer, you probably want to build the installer as a programmer would. WiX 3.0 is my tool of choice - open source code, from Microsoft to boot. Start with this tutorial on WiX. It's good.
The GUI for innosetup (highly recommended) is Istool
You can also use the MSI installer built into Visual Studio, it's a steeper learning curve (ie is a pain) but is useful if you are installing software in a corporate environment.
To have your program show up in the Start program menu,
You would need to create folder
C:\Documents and Settings\All Users\Start Menu\Programs
and added a short cut to the program you want to launch.
(If you want your application be listed
directly in the Start menu, or in the programs submenu,
you would put your short cut in the respective directory)
To programically create a short cut you can use IShellLink
(See MSDN article).
Since you want to uninstall, that gets a lot more involved because you don't want to simply go deleting DLLs or other common files without checking dependencies.
I would recommend using a setup/installation generator, especially nowadays with Vista being so persnickety, it is getting rather complicated to roll your own installation
if you need anything more than a single executable and a start menu shortcut.
I have been using Paquet Builder setup generator for several years now.
(The registered version includes uninstall).
You've already got the main steps. One you left out is to install on the Start Menu and provide an option to create a desktop and/or quick launch icon.
I would encourage you to look into using a setup program, as suggested by Jeremy.