i made a windows service & add project installer.in which only contain this code.
System.Diagnostics.Process.Start(#"C:\Windows\system32\notepad.exe"); inside the timer tick event & interval is 60 sec.i just wanted to try to run Windows service.
1st-serviceProcessInstaller1 i have been changed its account setting as local system.
2nd-serviceInstaller1 in this case i have been changed its start up type as Automatic.
then i create a setup add another project then right click add project output then add primary output then press ok.
then go to Right click on project->view->custom Action->right click on Install->Add custom Action->select Application folder & add primary output.the same thing done for all the remaining options like commit,rollback,uninstall.
after that i build the setup it build succesfully then i install the setup it installed properly into program file n create one .exe file n one Instalfile.
but problem is that when i search the service into "services.msc" the service is not there.
means service is not showing there.i tried but not getting the ans.plz help me to solve this problem.
Not the answer to your original question, but
Starting an application with a GUI from a service is a bad idea (tm) and won't work in the majority of cases
Check what kind of Timer you use. .Net provides 3 Timer classes, not all of them work in a service (because they depend on a window's message loop, iirc)
To test any service: Why don't you go for the installutil binary first (bypassing the setup project)? You find it in your framework directory, for example in "C:\Windows\Microsoft.NET\Framework\v2.0.50727".
I'd suggest trying to install the assembly manually to see if you get any kind of error message.
Just open a Visual Studio command prompt and run InstallUtil.exe [YourService].exe. At least you'll know if it installed properly.
Even better option is to use the command line tool sc.exe
Try "sc create /?" on command line and see its options.
You can then use "sc start " , "sc stop " & "sc query " to control service. You can use sc.exe to send custom command to the service. Check windows event log for errors related to service installation. It may be .Net version used to create it is not on target machine.
Related
I would like to set up min winforms app to use the IntelliTrace stand-alone collector.
Iv downloaded the application but I cant seem to find how I set it up to winforms.
It should be in this link I guess, but I dont quite understand: https://msdn.microsoft.com/en-us/library/hh398365(v=vs.110).aspx
Does anyone have any advice? Im trying to google to find examples without luck.
Best regards
Rob
I have a powershell script that I use to collect traces from console applications. This should be the same for winforms (I've tested it against WPF application and it works). The only step I'm not sure on is what "Collection Plan" you need - this might take a lot of experimentation.
Good Luck!
#1) Create a C:\IntelliTrace and place this script in there
$ROOT_DIR = $PSScriptRoot
#2) Extract the intellitrace cab file to C:\IntelliTrace\IntelliTraceCollection folder
#3) Where is the path to the winforms executable?
$Prog = "C:\path\to\my\winformsApplication.exe"
#4) Where do you want to save the trace?
$OutputLog = "$ROOT_DIR\MyTrace.iTrace"
#Note use of relative paths
$IntelliTraceStandAlone = "$ROOT_DIR\IntelliTraceCollection\IntelliTraceSC.exe"
#YOU WILL MOST LIKELY NEED A DIFFERENT COLLECTION PLAN
$collectionPlan = "$ROOT_DIR\IntelliTraceCollection\collection_plan.ASP.NET.default.xml"
#5) Run it..
#Note "dot space $IntelliTrace..."
. $IntelliTraceStandAlone launch /logfile:$OutputLog /collectionplan:$collectionPlan $Prog
Download Intellitrace standalone collector
Double click on the .exe file
Put the IntelliTraceCollectio.cab file in a folder.
For example D:\Intellitrace
Open command prompt as an administrator
Go to specified path of IntelliTraceCollectio.cab
and enter the command
expand /f:* IntelliTraceCollection.cab .
(Don't forget to put . at end)
Using command prompt,
enter
icacls "D:\IntelliTrace" /grant
(D:\Intellitrace is the path of your folder as specified above)
Create one more folder as D:\IntelliTraceLog (To store the collected intellitrace log file)
To collect data from an application, enter command
D:\Intellitrace\IntelliTraceSC.exe launch /cp:"D:\Intellitrace\collection_plan.ASP.NET.default.xml" /f: "C:IntelliTraceLog\MyApp.itrace" "D:\xyz\abc.exe"
(D:\xyz\abc.exe is the actual path of your file you want to run)
Now you will get an itrace file in D:\IntelliTraceLog. Open it in visual studio enterprise. Select any exception and click on Run Debugging.
You need to use IntelliTrace stand-alone collector to launch your WinForm application. You can find the reference from the link you posted https://msdn.microsoft.com/en-us/library/hh398365.aspx#BKMK_Collect_Data_from_Executables
PowerShell cmdlet is for web application or sharepoint application. For other managed application, the command you should use is
<FullPathToIntelliTraceCollectorExecutable> \IntelliTraceSC.exe launch /cp: <PathToCollectionPlan> /f: <FullPathToITraceFileDirectoryAndFileName> <PathToAppExecutableFileAndFileName>
I'm trying to setup our CI build environment and having an issue.
First, I'm using VS and TFS 2012 so I can't use the *.12.xaml templates since those are for VS/TFS 2013.
Second, right now I'm configured to use just the defaulttemplate.11.xaml. Originally, I was using WebDeploy for the deployment method and that was working great. Since then, our web/server team has re-configured our test environment to use IIS Shared Configuration as well as DFS Replication to keep everything in sync.
Because of that, I'm no longer able to use WebDeploy (I passed this post over to the TFS admins, but they said no).
Is there a place where I can add some msbuild arguments, or a post-build event where I can send a *.cmd file with some arguments so I can get my code copied/deployed?
I've read Hanselman's (and everyone else that copied him) posts/blogs that say "if you're using xcopy, you're doing it wrong, etc...", but I believe in my case I CAN'T use Web Deploy.
Update:
So I thought I found my answer. Since the web deploy doesn't work for me, I found a workflow activity called CopyDirectory that sounded exactly like what I need.
I went through the process of updating my default template to add this additional step to the build process, which by the way, does NOT work very well. After adding the step, saving, etc, the step doesn't ever show up in my build output. I gave up for awhile to go see if I could do this on our Jenkins build server, got some different errors over there so I came back to TFS to make the changes and commit. Since the CI was still setup in TFS (granted, failing), I noticed that a build got kicked off when I made my commit. I decided to watch for awhile and IT FINISHED SUCCESSFULLY! Woah, all right. So I checked through the build logs, and find out that it threw a WARNING saying "failed to copy. Ensure the source directory exists and that you have the appropriate permissions".
Well, since I just entered this value incorrectly, no big deal, just change to the correct BuildDetail.DropLocation, and we should be golden.
WRONG, after building again with my changes to the source and destination values, I come to find out that since I'm trying to deploy my files to a different domain, it still fails.
Oh, and in addition to that, YOU CAN'T PASS CREDENTIALS TO THE COPYDIRECTORY STEP! REALLY! Phew, I found some documentation though, it says "give the tfs build service/account permissions on the domain that you want to copy to. Well, that would be great, if my server team would allow that, but they don't.
Back to square one...(this is going to turn into a blog about me complaining about TFS...)
I believe you can do it using robocopy. You will want to update your build template to include a new InvokeProcess activity. Set the activity's FileName to "RoboCopy" (include the quotes) and it's Arguments to something like the following:
String.Format(" ""{0}"" ""{1}"" /E /R:10 /W:10 /NFL /NDL ", BinariesDirectory, BuildDetail.DropLocation)
Of course changing the robocopy flags to your specific needs.
I don't think you can pass credentials into robocopy either though, so you might still be SOL there.
One possible alternative though is that because your admins won't give the TFS Build User (i.e. tfsservice) permissions on the destination box, you could change the TFS Builds to run as a different User that does have permissions on that box. To do this I believe you just have to log onto your TFS Build machine, go to the Services, find the Visual Studio Team Foundation Build Service Host 2012 (or something similar), and change the Log On As user from tfsservice to whatever user has permissions on the box that you want to publish to. Of course you will also need to give that user permissions to do everything else that the build system needs to do (download source code, etc.).
I have an MSI installer that installs my Windows Service and in my custom actions I need to write some values into the Registry in the HKEY_LOCAL_MACHINE/SOFTWARE/MYSoftware key.
I am trying to do this and it's not working, but from my Windows Service it's working fine. Can anybody tell me where I am going wrong?
string registryLocaltion = AgentProperties.TMAGENT_REGISTRY_LOCATION
+ #"\" +AgentProperties.TMAgentVersion;
tmKeyMain = Registry.LocalMachine.OpenSubKey(registryLocaltion, true);
if (tmKeyMain == null)
{
log.Error("Unable to open registry key " + registryLocaltion);
}
tmKeyMain.SetValue("UseProxySettings", settings.UseProxySettings);
if (settings.UseProxySettings)
{
tmKeyMain.SetValue("ProxyHost", settings.ProxyHost);
tmKeyMain.SetValue("ProxyPort", settings.ProxyPort);
tmKeyMain.SetValue("ProxyUsername",
GenericHelper.ConvertToBase64Encoding(settings.ProxyUsername));
tmKeyMain.SetValue("ProxyPassword",
GenericHelper.ConvertToBase64Encoding(settings.ProxyPassword));
tmKeyMain.SetValue("ProxyExclusion", settings.ProxyExclusion);
tmKeyMain.SetValue("BypassProxy", settings.BypassProxy);
}
This code is working fine in my Windows Service, but if I do some thing very similar in my custom action in the MSI installer it doesn't work.
Can anybody tell me where I am going wrong?
You are up against a couple problems. The most obvious problem is that Visual Studio Deployment projects incorrectly schedule custom actions to impersonate the client context. This means in a UAC scenario you won't have permissions. The quick work around is to run the MSI from an already elevated command prompt context.
The second problem is that Visual Studio Deployment Projects abstract / hide the underlying MSI too much. For Custom Actions, it only gives you the options of "install, uninstall, rollback, commit" without exposing any additional settings. It hides the ServiceInstall and ServiceControl tables. This causes you to write a custom action that reinvents the wheel.
See, all your custom action should be doing is performing the business logic and setting properties. Then you should be using the Registry table to set the data based on the properties. This way you leverage as much of Windows Installer as possible and all of it's free transactional / rollback capabilities.
This problem repeats over and over and is why Microsoft killed of the setup project types in VS2012.
If it was my install, I'd be refactoring the design to use AppSearch/Reglocator to read in the data, have a minimalist custom action to do the processing and then use the Registry table to apply the data.
That will require you at a minimum to look at Windows Installer XML to create a merge module that has all of this logic and gets merged into your existing setup project. That takes awhile to learn though.
How do I configure a C# program to run when the operating system is first started?
If you want to run the program when the user logs on, then the "Startup" folder or Run registry key methods both work.
If you want the program to run when the computer is turned on (ie Windows starts), without waiting for the user to log on, you will need to install it as a service, and configure it to start automatically.
Just add the program to the Startup folder in the Start Menu.
add to registry
private void AddToRegistry()
{
RegistryKey regKey = Registry.CurrentUser.OpenSubKey(#"Software\Microsoft\Windows\CurrentVersion\Run", true);
regKey.SetValue(Application.ProductName, Application.ExecutablePath);
}
I believe you are going to have to convert this C# application into a Windows service and set its startup type to Automatic. That seems to be the approach most people use.
The easiest answer would be to add it to the Startup folder in your Start Menu. As far as I know simply dropping it in there should be enough (since it is just a little exe).
For a simple C# app, putting the app's .exe or a shortcut to it, in the start folder is the easiest approach.
To build it in a little bit more, you could add it to the registry, under "Software\Microsoft\Windows\CurrentVersion\" then the subkey that you require. For more info on the registry approach read this - http://support.microsoft.com/kb/179365
For a more complex approach which may/maynot be needed depending on your application you can create it as a service, and have it set to run automatically. For a simple app this isn't needed so I won't expand further on this point.
You can develop this program as a Windows service. Then you can configure it to re-start after a failure or subsequent failures which increases robustness. Just an idea...
I'm using Inno Setup for my installer and adding the following line will accomplish this:
Name: "{commonstartup}\YourFolder"; Filename: "{app}\YourApp.exe"; IconFilename: "{app}\YourApp.ico"
Also add this to your [setup] section
PrivilegesRequired=admin
Documentation http://www.jrsoftware.org/iskb.php?startup
bla.exe (application alias) points to a .net application called wpfapp1.exe.
When i add a key&value to eg. this key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\bla.exe
and then start application using Run -> bla.exe it starts
however when i start application using windows search i get an "windows cannot find wpfapp1.exe. make sure you typed the name correctly, and then try again."
I have successfully identified problem: this error only occurs to .net applications while native one start normally (eg. firefox.exe).
So is there any .net config that i've missed during development?
From MSDN:
The App Paths key is not used when
computing the DLL search path.
Maybe you're missing some dependent DLL...
I don't really understand your "points to" or if Windows search is specific to using the explorer search or using the start menu search.
I've had a similar problem with another application that the search could not find at all, neither in Explorer or Start menu (since it did not have an indexed folder to locate it) and solved it with a simple shortcut.
If you can create a shortcut of your application in your start menu or some other indexed folder, like a %PATH% folder, Windows search should be able to pick it up and then you can name your shortcut to whatever you want, for instance bla.exe.