0

My code:

Process kurulum1 = new Process();
kurulum1.StartInfo.FileName = @"C:\ProgramData\Microsoft\Windows\StartMenu\Programs\Visual Studio 2017\Visual Studio Tools\Developer Command Prompt for VS 2017.lnk";

 kurulum1.StartInfo.Arguments = "cd C:\\Users\\stajyer3\\Documents\\Visual Studio 2017\\Projects\\TestWindowsService\\TestWindowsService\\bin\\Debug InstallUtil.exe "TestWindowService.exe"  ";

kurulum1.Start();

kurulum1.WaitForExit();

Not Working

Error:

[ERROR:parse_cmd.bat] Invalid command line argument: 'cd'. Argument will be ignored. [ERROR:parse_cmd.bat] Invalid command line argument: 'C:\Users\stajyer3\Documents\Visual'. Argument will be ignored. [ERROR:parse_cmd.bat] Invalid command line argument: 'Studio'. Argument will be ignored. [ERROR:parse_cmd.bat] Invalid command line argument: '2017\Projects\TestWindowsService\TestWindowsService\bin\Debug'. Argument will be ignored.


** Visual Studio 2017 Developer Command Prompt v15.0.26430.14 ** Copyright (c) 2017 Microsoft Corporation ********************************************************************** [ERROR:VsDevCmd.bat] * VsDevCmd.bat encountered errors. Environment may be incomplete and/or incorrect. *

mjwills
  • 23,389
  • 6
  • 40
  • 63
MaviLe
  • 15
  • 2
  • could you please format your code? – WhatsThePoint Jul 13 '17 at 09:05
  • 1
    I've reformatted your post for you. Please consider doing so yourself in the future, to make it more readable. The preview is there for a reason. – J. Steen Jul 13 '17 at 09:05
  • @MaviLe tell us what you want the code to do, are you trying to run command prompt, start "Debug InstallUtil.exe" run "TestWindowService.exe" we can't fix your code for you unless we know what you want the code to do – MikeT Jul 13 '17 at 10:39
  • @MikeT I want to install the windows service named TestWindowService.exe in c # – MaviLe Jul 13 '17 at 11:07

3 Answers3

3

you have made many mistakes here , with out knowing your objective its very difficult to say which is the worst

  1. ProcessStartInfo.FileName should be the file you want to execute not a start menu shortcut

  2. ProcessStartInfo.Arguments is a command line argument not a command

  3. the command you are using seems to be an attempt to change the working directory this should be done with ProcessStartInfo.WorkingDirectory

  4. the strings you are using are broken because you are exiting the strings by using " but then you carry the string on, so i must assume you mean the " to be inside the string in which case you need to delimit them with \ this would then look like "he said \"delimit your strings\" "though if you are using the @ notation then the delimiter becomes "" not \"

  5. arguments are space separated strings so if your arguments contain spaces such as long form filenames then you need to surround them with quotes " so ProcessStartInfo.Arguments = "a b c:\\temp"; will pass the args "a", "b" and "c:\temp" to the executing program but ProcessStartInfo.Arguments = "a literal string arg"; would pass each word as as separate argument ProcessStartInfo.Arguments = "\"a literal string arg\""; and this will pass in a single arg with the entire string

MikeT
  • 5,398
  • 3
  • 27
  • 43
0

You need to enclose the path in quotes (and escape the quotes around the filename)

kurulum1.StartInfo.Arguments = "cd \"C:\\Users\\stajyer3\\Documents\\Visual Studio 2017\\Projects\\TestWindowsService\\TestWindowsService\\bin\\Debug InstallUtil.exe\" \"TestWindowService.exe\"  ";
David Lindon
  • 305
  • 2
  • 8
0

Give this a whirl:

var kurulum1 = new Process
{
    StartInfo =
    {
        FileName = @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil.exe",
        WorkingDirectory =
            "C:\\Users\\stajyer3\\Documents\\Visual Studio 2017\\Projects\\TestWindowsService\\TestWindowsService\\bin\\Debug",
        Arguments = "TestWindowService.exe"
    }
};
kurulum1.Start();
kurulum1.WaitForExit();

There is no need to involve the Developer Command Prompt - you can just invoke installutil directly.

mjwills
  • 23,389
  • 6
  • 40
  • 63
  • The transaction is not occurring and I can not see the error – MaviLe Jul 13 '17 at 11:14
  • How is your code running? Is it a command line app? A web-app? Something else? Can you copy and paste your class into https://dotnetfiddle.net/ and `Share` a link so I can check your code and make sure there isn't a typo? – mjwills Jul 13 '17 at 12:54
  • I'm new on stackoverflow. – MaviLe Jul 13 '17 at 13:01
  • I want to see if a windows service setup program called TestWindowsService is running in services at c # form application – MaviLe Jul 13 '17 at 13:03
  • I can not see installutil.exe running and shutting down – MaviLe Jul 13 '17 at 14:02
  • Why do you need to see that? Are you worried it isn't working? If so, uninstall it yourself (https://stackoverflow.com/a/22373062/34092) and then run my code. If it is there, my code must have installed it successfully. – mjwills Jul 13 '17 at 14:02
  • I can not see the windows service in the services I want to install @mjwills – MaviLe Jul 13 '17 at 14:13