How do I start/stop IIS Express Server? - iis-express

I have installed MS Visual Web Developer 2010 which includes IIS Express.
Before this, I had installed XAMPP server for my php applications.
I would like to know how can I stop IIS in order to be able to start XAMPP? It appears that they use the same port. I guess those could be changed, but I do not want to interfere with other programs, and more than that I think this should be simpler.
Thanks!

Closing IIS Express
By default Visual Studio places the IISExpress icon in your system tray at the lower right hand side of your screen, by the clock. You can right click it and choose exit. If you don't see the icon, try clicking the small arrow to view the full list of icons in the system tray.
then right click and choose Exit:
Changing the Port
Another option is to change the port by modifying the project properties. You'll need to do this for each web project in your solution.
Visual Studio > Solution Explorer
Right click the web project and choose Properties
Go to the Web tab
In the 'Servers' section, change the port in the Project URL box
Repeat for each web project in the solution
If All Else Fails
If that doesn't work, you can try to bring up Task Manager and close the IIS Express System Tray (32 bit) process and IIS Express Worker Process (32 bit).
If it still doesn't work, as ni5ni6 pointed out, there is a 'Web Deployment Agent Service' running on the port 80. Use this article to track down which process uses it, and turn it off:
https://sites.google.com/site/anashkb/port-80-in-use

An excellent answer given by msigman. I just want to add that in windows 10 you can find IIS Express System Tray (32 bit) process under Visual Studio process:

Open Task Manager and Kill both of these processes. They will autostart back up.
Then try debugging your project again.

I came across the same issue. My aim is to test PHP scripts with Oracle on Windows 7 Home and without thinking installed IIS7 express and as an afterthought considered Apache as a simpler approach. I will explore IIS express's capabilities seperately.
The challenge was after installing IIS7 express the Apache installation was playing second fiddle to IIS express and bringing up the Microsoft Homepage.
I resolved the port 80 issue by :-
Stopping Microsoft WedMatrix :- net stop was /y
Restarted the Apache Server
Verifying Apache now was listening on the port :- netstat -anop
Clearing out the Browsers caches - Firefox and IE
Running localhost

Here is a static class implementing Start(), Stop(), and IsStarted() for IISExpress. It is parametrized by hard-coded static properties and passes invocation information via the command-line arguments to IISExpress. It uses the Nuget package, MissingLinq.Linq2Management, which surprisingly provides information missing from System.Diagnostics.Process, specifically, the command-line arguments that can then be used to help disambiguate possible multiple instances of IISExpress processes, since I don't preserve the process Ids. I presume there is a way to accomplish the same thing with just System.Diagnostics.Process, but life is short. Enjoy.
using System.Diagnostics;
using System.IO;
using System.Threading;
using MissingLinq.Linq2Management.Context;
using MissingLinq.Linq2Management.Model.CIMv2;
public static class IisExpress
{
#region Parameters
public static string SiteFolder = #"C:\temp\UE_Soln_7\Spc.Frm.Imp";
public static uint Port = 3001;
public static int ProcessStateChangeDelay = 10 * 1000;
public static string IisExpressExe = #"C:\Program Files (x86)\IIS Express\iisexpress.exe";
#endregion
public static void Start()
{
Process.Start(InvocationInfo);
Thread.Sleep(ProcessStateChangeDelay);
}
public static void Stop()
{
var p = GetWin32Process();
if (p == null) return;
var pp = Process.GetProcessById((int)p.ProcessId);
if (pp == null) return;
pp.Kill();
Thread.Sleep(ProcessStateChangeDelay);
}
public static bool IsStarted()
{
var p = GetWin32Process();
return p != null;
}
static readonly string ProcessName = Path.GetFileName(IisExpressExe);
static string Quote(string value) { return "\"" + value.Trim() + "\""; }
static string CmdLine =
string.Format(
#"/path:{0} /port:{1}",
Quote(SiteFolder),
Port
);
static readonly ProcessStartInfo InvocationInfo =
new ProcessStartInfo()
{
FileName = IisExpressExe,
Arguments = CmdLine,
WorkingDirectory = SiteFolder,
CreateNoWindow = false,
UseShellExecute = true,
WindowStyle = ProcessWindowStyle.Minimized
};
static Win32Process GetWin32Process()
{
//the linq over ManagementObjectContext implementation is simplistic so we do foreach instead
using (var mo = new ManagementObjectContext())
foreach (var p in mo.CIMv2.Win32Processes)
if (p.Name == ProcessName && p.CommandLine.Contains(CmdLine))
return p;
return null;
}
}

You can stop any IIS Express application or you can stop all application. Right click on IIS express icon , which is located at right bottom corner of task bar. Then Select Show All Application

to stop IIS manually:
go to start menu
type in IIS
you get a search result for the manager (Internet Information Services (IIS) manager, on the right side of it there are restart/stop/start buttons.
If you don't want IIS to start on startup because its really annoying..:
go to start menu.
click control panel.
click programs.
turn windows features on or off
wait until the list is loaded
search for Internet Information Services (IIS).
uncheck the box.
Wait until it's done with the changes.
restart computer, but then again the info box will tell you to do that anyways (you can leave this for later if you want to).
oh and IIS and xampp basically do the same thing just in a bit different way. ANd if you have Xampp for your projects then its not really all that nessecary to leave it on if you don't ever use it anyways.

Related

How can I launch an application through Microsoft Visual Studio?

I am still new to using Visual Studio, any windows programming really, and I am trying to make an application Launcher for Microsoft Office applications. I have already made the interface but dont know how to make the buttons actually launch the programs. Any help is appreciated.
You can add System.Diagnostics namespace to your project and use its Process.Start function to start an external application and for closing a process you can use Process.Close function, save your started process in a variable and close it when ever you want: like this:
static void Main()
{
// ... Open specified Word file.
OpenMicrosoftWord(#"C:\Users\Sam\Documents\Gears.docx");
}
public Process myProcess;
static void OpenMicrosoftWord(string file)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "WINWORD.EXE";
//If skip this line, you'll have an open MS Word with no specific file loaded
startInfo.Arguments = file;
myProcess = Process.Start(startInfo);
}
static void CloseMicrosoftWord()
{
myProcess.Close();
}
for more information check below links
Process.Start Examples
Using Diagnostics.Process to start an external application
Process.Close Method

Launch Visual Studio 2012 Shell (Integrated) and run SSIS package using Windows Scheduler

I am working on a project that creates a reporting database by loading data from an AS400 into SQL Server 2012 Express (just FYI - I do not have sql agent or sql profiler). I downloaded sql server data tools with the SSIS designer and created a couple of data loading packages within the same solution. I have researched running SSIS packages using the DTExec utility, and for the most part it worked fine, however, I was not able to log any of the runtime data to a log table (only the text file log worked), and for some reason the send emails tasks didn't send emails when run through DTExec. Both of these things worked fine when running the packages directly in VS Shell.
While trying to troubleshoot these issues, I realized that I do not actually have integration services installed on my machine - just the designer. I will not be able to get integration services (soon, at least) so I would like to figure out how to launch VS Shell, validate, build and execute my SSIS load packages - not using the DTExec utility, but actually launching in the VS Shell using Windows Scheduler.
I know that to launch the program itself, I would just schedule devenv.exe. But what arguments do I use to validate, build and execute the packages using this method. The only thing I can find about executing packages involves using the utility, and assumes that the user has SSIS installed, not just the designer.
Now, if worse comes to worse I can just execute the load packages and then create some sql queries to pull together the row counts and other stuff I will need to audit the data, but it seems like there should be a way to do what I want to do.
There's a reason you're not able to run an SSIS package outside of BIDS/SSDT/Visual Studio and it's called licensing.
With the 2012 release of SQL Server, you're free to develop SSIS packages to your heart's content. However, to get them to run outside of Visual Studio means you need to have installed SQL Server on the invoking machine. Even though it's "just integration services", that's a SQL Server installation and thus a license is required. A developer edition license of SQL Server is cheap: ~50 USD per user. However, since it sounds like you're making a "productionalized" version, you're going to need a Standard Edition or Enterprise Edition, depending on the features used in SSIS. SE or EE is not cheap and with the change to licensing with the 2012 release (per core vs per socket), it's gotten more precious.
You're looking for a technical solution and if you find one, you're likely going to be in violation of licensing.
You can use AutoIT to script GUI applications:
http://www.autoitscript.com/site/autoit/
I managed to figure out how to launch VS using the windows scheduler:
create a task
go to actions, edit
In the program/script box enter the path to devenv.exe (using double quotes) - "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe"
In Add arguments enter devenv /runexit /project [project name] "\fileserver\path[solution name].sln"
You can use other switches for arguments: http://msdn.microsoft.com/en-us/library/xee0c8y7.aspx
The only thing is that because it is running in visual studio (at least for me) is that it runs in debug mode, so you have to click stop to stop debugging. So in my case, I used the runexit switch, which is supposed to close VS when the package is complete. It only closed after I clicked stop. I tried using the /command switch to execute a stop debugging command (http://msdn.microsoft.com/en-us/library/c3a0kd3x.aspx) Debug.StopDebugging, but it didn't seem to work.
I used the run flag in task scheduler and I was able to get the the debugger to automatically stop by taking advantage of user32.dll via a script. Basically I send the close command message and a button click to the ok on the close dialog. Below is my cookie cutter task I put at the end of my projects... If you just want to stop without exit you could probably just send shift+f5 too.
private static string project = "MyProjectName";
[DllImportAttribute("User32.dll")]
private static extern int FindWindow(String ClassName, String WindowName);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(int hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
public static extern int FindWindowEx(int parentHandle, IntPtr childAfter, string className, string windowTitle);
const UInt32 WM_CLOSE = 0x0010;
private const int BN_CLICKED = 245;
/// <summary>
/// This method is called when this script task executes in the control flow.
/// Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
/// To open Help, press F1.
/// </summary>
public void Main()
{
int hwndChild = 0;
int hWnd = FindWindow(null, project + " (Running) - Microsoft Visual Studio (Administrator)");
if (hWnd == 0)
hWnd = FindWindow(null, project + " (Running) - Microsoft Visual Studio");
if (hWnd == 0)
hWnd = FindWindow(null, project + " - Microsoft Visual Studio");
if (hWnd > 0)
{
SendMessage(hWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
while (hwndChild == 0)
{
hWnd = FindWindow(null, "Microsoft Visual Studio");
hwndChild = FindWindowEx(hWnd, IntPtr.Zero, "Button", "&Yes");
if (hwndChild == 0)
hwndChild = FindWindowEx(hWnd, IntPtr.Zero, "Button", "Yes");
SendMessage(hwndChild, BN_CLICKED, IntPtr.Zero, IntPtr.Zero);
System.Threading.Thread.Sleep(500);
System.Windows.Forms.Application.DoEvents();
}
}
Dts.TaskResult = (int)ScriptResults.Success;
}

VS SDK: ToolWindowPane hides when debugging

I used the VS 2010 SDK to create and show a custom ToolWindowPane with a WPF control as content. I create a new instance and show it each time a Tool menu item is clicked (the ProvideToolWindow attribute has MultiInstances = true).
When the user attaches the debugger (e.g., hits F5 while in C# project) my ToolWindowPane suddenly hides. I'd like to make sure my tool window is always visible while open, no matter what context the user is in. Is there a way I can enforce that?
I've tried using the ProvideToolWindowVisibility attribute but that automatically shows a new instance of my tool window rather than keeping a remaining one open.
For VS 2010 SDK Microsoft added a new flag __VSCREATETOOLWIN2.CTW_fDocumentLikeTool
You can use this way:
public override void OnToolWindowCreated()
{
IVsWindowFrame windowFrame = Frame as IVsWindowFrame;
object varFlags;
windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_CreateToolWinFlags, out varFlags);
int flags = (int)varFlags | (int)__VSCREATETOOLWIN2.CTW_fDocumentLikeTool;
windowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_CreateToolWinFlags, flags);
}
This way Tool Window persist open at "Document Well" when you go Debugging
However I have to say this give us some problems when debugging projects, avoiding us to open code files while debugging, like if Visual Studio document management was 'block', there are not so much information for this new flag...
So we preferred to hook to EnvDTE.DebuggerEvents and show the ToolWindow if hide when a debugging session start...
(our ToolWindow has MultiInstances = false)
Implement QueryShowTool
public:
int QueryShowTool(Guid % rguidPersistenceSlot, System::UInt32 dwId, [Runtime::InteropServices::Out] int % pfShowTool);
Enables the VSPackage to control whether to show or hide the tool
window. The shell calls this method when the user switches views or
contexts, for example Design, Debugging, Full Screen.
See https://learn.microsoft.com/en-us/visualstudio/extensibility/opening-a-dynamic-tool-window?view=vs-2017

Visual Studio unable to open port to host WCF Service

I created a solution VS2010 C# with the WCF service, the library to get data, the service is working fine in a console application in the solution. No problem.
I have to use it on a VS2008 project (and probably later on a VS2005) for the older projects. Then I start VS2010 I get the "WCF Test Client". At this time in the VS2008, I tried to "Add a web reference" on the local machine... no result.
Then I tried to create a console application with Vs2010 to host it, I did this :
Uri baseAddress = new Uri("http://localhost:8080/hello");
using (ServiceHost host = new ServiceHost(typeof(SecurityAccessWCF.WCFSecurityService), baseAddress))
{
// Enable metadata publishing.
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
host.Description.Behaviors.Add(smb);
host.Open();
Console.WriteLine("The service is ready at {0}", baseAddress);
Console.WriteLine("Press <Enter> to stop the service.");
Console.ReadLine();
// Close the ServiceHost.
host.Close();
}
I get an error on the Open(), I get this error "AddressAccessDeniedException - HTTP could not register URL... Your process does not have access rights" (the link provided is not clear, I'm on Win7 x64 as local admin and in a domain)
Shift + Mouse Right Click on Visual Studio shortcut and select Run as administrator
This way you should be able to host it.
Alternately, you could build the project and run the resulting console application the same way under admin account.
Thats a standard error meaning your application cant register the domain. Normally this is a problem on vista/windows 7 with security. Log in as administrator and run netsh http add urlacl url=http://+:80/Localhost user=DOMAIN\user
Here is a msdn article with more information

How to attach a debugger dynamically to a specific process

I am building an internal development tool to manage different processes commonly used in our development environment. The tool shows the list of the monitored processes, indicating their running state and allows to start or stop each process.
I'd like to add the functionality of attaching a debugger to a monitored process from my tool instead of going in Debug -> Attach to process in Visual Studio and finding the process.
My goal is to have something like Debugger.Launch() that would show a list of the available Visual Studio. I can't use Debugger.Launch(), because it launches the debugger on the process that makes the call. I would need something like Debugger.Launch(processId).
How do I achieve this functionality?
A solution could be to implement a command in each monitored process to call Debugger.Launch() when the command is received from the monitoring tool, but I would prefer something that does not require to modify the code of the monitored processes.
Side question:
When using Debugger.Launch(), instances of Visual Studio that already have a debugger attached are not listed. Visual Studio is not limited to one attached debugger, you can attach on multiple process when using Debug → Attach to process.
How do I bypass this limitation when using Debugger.Launch() or an alternative?
A coworker ended up with a solution using DTE, and I posted the code on PasteBin.
The methods of interest are AttachVisualStudioToProcess and TryGetVsInstance
Source Code
public static void AttachVisualStudioToProcess(Process visualStudioProcess, Process applicationProcess)
{
_DTE visualStudioInstance;
if (TryGetVsInstance(visualStudioProcess.Id, out visualStudioInstance))
{
//Find the process you want the Visual Studio instance to attach to...
DTEProcess processToAttachTo = visualStudioInstance.Debugger.LocalProcesses.Cast<DTEProcess>().FirstOrDefault(process => process.ProcessID == applicationProcess.Id);
// Attach to the process.
if (processToAttachTo != null)
{
processToAttachTo.Attach();
ShowWindow((int)visualStudioProcess.MainWindowHandle, 3);
SetForegroundWindow(visualStudioProcess.MainWindowHandle);
}
else
{
throw new InvalidOperationException("Visual Studio process cannot find specified application '" + applicationProcess.Id + "'");
}
}
}
private static bool TryGetVsInstance(int processId, out _DTE instance)
{
IntPtr numFetched = IntPtr.Zero;
IRunningObjectTable runningObjectTable;
IEnumMoniker monikerEnumerator;
IMoniker[] monikers = new IMoniker[1];
GetRunningObjectTable(0, out runningObjectTable);
runningObjectTable.EnumRunning(out monikerEnumerator);
monikerEnumerator.Reset();
while (monikerEnumerator.Next(1, monikers, numFetched) == 0)
{
IBindCtx ctx;
CreateBindCtx(0, out ctx);
string runningObjectName;
monikers[0].GetDisplayName(ctx, null, out runningObjectName);
object runningObjectVal;
runningObjectTable.GetObject(monikers[0], out runningObjectVal);
if (runningObjectVal is _DTE && runningObjectName.StartsWith("!VisualStudio"))
{
int currentProcessId = int.Parse(runningObjectName.Split(':')[1]);
if (currentProcessId == processId)
{
instance = (_DTE)runningObjectVal;
return true;
}
}
}
instance = null;
return false;
}
WinDbg does the chain debugging for native code by default. If you want to launch another instance of Visual Studio, check Launch the Debugger Automatically on MSDN:
To automate the existing debugger, use Marshal.GetActiveObject to get the current EnvDTE.Debugger then let it attach to the process you just created.
Sometimes, you may need to debug the startup code for an application that is launched by another process. Examples include services and custom setup actions. In these scenarios, you can have the debugger launch and automatically attach when your application starts.
To setup an application to launch the debugger automatically
Start the Registry Editor (regedit).
In the Registry Editor, open the HKEY_LOCAL_MACHINE folder.
Navigate to HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\currentversion\image file execution options.
In the Image File Execution Options folder, locate the name of the application you want to debug, such as myapp.exe. If you cannot find the application you want to debug:
a. Right-click the Image File Execution Options folder, and on the shortcut menu, click New Key.
b. Right-click the new key, and on the shortcut menu, click Rename.
c. Edit the key name to the name of your application; myapp.exe, in this example.
Right-click the myapp.exe folder, and on the shortcut menu, click New String Value.
Right-click the new string value, and on the shortcut menu, click Rename.
Change the name to debugger.
Right-click the new string value, and on the shortcut menu, click Modify.
The Edit String dialog box appears.
In the Value data box, type vsjitdebugger.exe.
Click OK.
From the Registry menu, click Exit.
The directory containing vsjitdebugger.exe must be in your system path. To add it to the system path, follow these steps:
a. Open the Control Panel in Classic view, and double-click System.
b. Click Advanced System Settings.
c. In System Properties, click the Advanced tab.
d. On the Advanced tab, click Environment Variables.
e. In the Environment Variables dialog box, under System variables, select Path, then click the Edit button.
f. In the Edit System Variable dialog box, add the directory to the Variable value box. Use a semicolon to separate it from other entries in the list.
g. Click OK to close the Edit System Variable dialog box.
h. Click OK to close the Environment Variables dialog box.
i. Click OK to close the System Properties dialog box.
Now, use any method to start your application. Visual Studio will start and load the application.
Here is some information about how you can programmatically attach the debugger to multiple processes:
Attach to locally running processes
Attach to remotely running processes

Resources