C# command prompt commands not found - c#

I am trying to call tpmvscmgr.exe located in C:\Windows\System32
from my c# application.
I found this code:
string strCmdText;
strCmdText = #"/C Robocopy C:\Users\Johannes\test1 C:\Users\Johannes\test2";
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
here Run Command Prompt Commands
and it works good.
However when I try to change it to
strCmdText = "/C Tpmvscmgr.exe create /name tpmvsc /pin default /adminkey random /generate ";
This does not work.
In fact when I debug and look around in the command prompt opened by the code I can not find the tpmvscmgr.exe in windows/system32.
Im guessing it is opened as a different user or with other priviledges or something but can this be fixed?
I really would need to run a tpmvscmgr.exe command from code.

OK I figured something out.
In my visual studio c# project I had "Any CPU" marked for the project. Apparently this means the console opens as win32.
When I changed the c# project to x86 I could run tpmvscmgr.exe
Pretty tricky stuff.
C# cmd prompt cannot see telnet.exe

Related

Windows service not getting uninstalled

I want to uninstall Windows Service from command prompt but that is not working getting below error
'installutil' is not recognized as an internal or external command,
operable program or batch file.
This way I have tried command
D:\backup\WindowsService\WindowsService1\WindowsService1\obj\Debug>installutil -u TestService.exe
D:\backup\WindowsService\WindowsService1\WindowsService1\obj\Debug>installutil -u "TestService.exe"
How can I uninstall service?
After your comment, your issue seems related to %PATH%.
There is no such thing as "installutil" on your Windows. I believe "installutil" has created by you right?
Let's assume that binary resides at C:\Myproject\installutil.exe
There are two ways to execute it.
First:
C:\users\username> cd C:\Myproject
C:\Myproject> .\installutil.exe -u "bla bla bla bla".
Second:
Go to your start menu and search for "environment". Open "Edit the system variables" under "System properties". At the "Advanced" tab, you'll see "Environment Variables". You'll see a variable named "Path". Edit it's value and add your own .exe path at the end.
When you execute "echo %PATH" at command prompt, you should see your binary's folder. Otherwise, command prompt will not be able to find it.
EDIT:
So yeah, there is one such thing called installutil.exe and it can be used by the Developer Command Prompt for Visual Studio.
Command to uninstall service: installutil -u "AirwatchService.exe"
Are you sure you're using the right command prompt? Do you have the absolute path of this binary?
Please check this: https://learn.microsoft.com/en-us/dotnet/framework/tools/installutil-exe-installer-tool

VisualStudio 2017 runs .exe when building on external console

I'm trying to learn some C# and am currently using the internal console for outputs, but when it comes to keyboard inputs, I've read that it can not be done in the internal console on VS 2017 for Mac.
So I try to do it on external console, but all I get is this :
bash -c 'clear; cd "/Users/gb/Projects/reTest/reTest/bin/Debug";
"/Library/Frameworks/Mono.framework/Versions/5.8.1/bin/mono32"
--debug --debugger-agent=transport=dt_socket,address=127.0.0.1:56795 "/Users/gb/Projects/reTest/reTest/bin/Debug/reTest.exe" ; echo $? >
/var/folders/s_/sljf42_d01bdxlb5s_rwgsj80000gn/T/tmp563f24ea.tmp;
echo; read -p "Press any key to continue..." -n1; exit'; exit
I guess the console tries to execute a .exe application which is not possible in this case !
It's a console project by the way... I haven't found any solution for that so far.
Thks.
After further researches I found out that my bash was kind of corrupted somehow so I modified the .bash_profile file which had some extra inconvenient text..

Start new console application in new thread

I am trying to start a .exe program from the build runner, but I don't want it to run in the teamcity console, I want a brand new console that runs independently from the current build. So far I have tried a few things without any success.
Tried with a powershell script:
$ErrorMessage = "POWERSHELL ERROR"
try {
Write-Output "About to start backend"
Start-Process Program.exe
Write-Output "Started backend"
} Catch {
Write-Output $ErrorMessage
exit(1)
}
Tried starting a new console with this command:
Start Program.exe
I'm starting to wonder if it's even possible.
Start-Process powershell -ArgumentList #("-NoExit", "-Command Start-Process cmd")
I got the answer from the teamcity forum, thought I might share it here though. My problem was caused to an issue with the build agent caused by windows.
Check out the full explanation here.
To solve the problem, you need to run the agent by running the command "agent.bat run" in the agent's bin folder under your installation directory.

Starting a vm "Windows XP Mode" programmatically through a C# program Windows 7

Ok, so I'm having an issue starting the the Windows XP mode VM through a c# program. The command I'm using is vmwindow -file "absolute path to vmcx file" , but the problem is that the command does not work with the cmd prompt that my program kicks off. So, it's very weird. I can go to command prompt on my computer and run this command on my computer and it works, but if i have the same command on my c# program, the command prompt that pops up tells me the "vmwindow" is not a recognized command. I even looked at the paths of each of the command prompts and they're different, but they still both contain "C:\Windows\system32\" which is where vmwindow.exe exists. So, I navigate on the command prompt window that my program populated and the file "vmwindow.exe" is not there, but if I open a command prompt window from my computer and navigate to that folder, it exists there. I can't think of anything else as I already made sure they're both running in administrator mode, and also i tried starting a bat file which contained that command instead of running the command directly. Hope anyone knows anything about this. Here is the code I'm using:
private void button1_Click(object sender, EventArgs e)
{
Process process = new System.Diagnostics.Process();
ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
startInfo.FileName = "cmd.exe";
startInfo.WorkingDirectory = #"<my path>";
startInfo.Arguments = "/k vmwindow.exe -file \"<path to vcmx file>\\Windows XP Mode.vmcx\"";
process.StartInfo = startInfo;
process.Start();
}
What you can do is using Powershell. It has a native integration for Hyper V control and is easy to call from c#
You can see all HV-cmdlets here
a simple command to start your machine would be
Start-VM "Windows 8.1 Pro" -Computername HV-Host1
// etcetc
Stop-VM "Windows 8.1 Pro" -Save
So this should be something like this in C#
using (PowerShell PowerShellInstance = PowerShell.Create())
{
PowerShellInstance.AddScript("Start-VM "Windows 8.1 Pro" -Computername HV-Host1");
}
Probably it's because of the bitness setting you compile your program with. ("Platform target" and "Prefer 32-bit" settings under the build tab of the project).
32 and 64 bit processes see different files under System32.
See https://stackoverflow.com/a/950011

Trouble running .cmd file with c#

For some reason, I can't seem to launch and run a .cmd file with c#. An example of a line of the cmd file is:
"C:\Windows\system32\ffmpeg64.exe" -v verbose -y -i "S:\TEMP\A.ts" -c:v copy -c:a copy -ss 00:00:00.000 -t 2 "S:\TEMP\A_SHORT.ts"
I've tried several different ways to launch this file from within C#, such as (where curDirectory is for example "S:\TEMP")
Process p = Process.Start(curDirectory + "\\ffmpeg.cmd");
I've also tried
string path = curDirectory + "\\ffmpeg.cmd";
Process p = Process.Start("cmd.exe", #"/c " + path); //I've also tried /k
But what happens is the cmd prompt will show up and say "C:\Windows\System32\ffmpeg64.exe" is not recognized ..." even though the file is there. What am I doing wrong?
If your system is running the Windows 6.1 kernel or later, System32 is actually comprised of other directories based on the application you're running (depending on whether it is a 32-bit or 64-bit application).
I assume that ffmpeg64.exe is a 64-bit application, and when you execute the .cmd file manually, it should default to a 64-bit command prompt - Also ensure that your application is targeting "x64" or "Any CPU". Alternatively, you could place a 32-bit version of ffmpeg in the WoW64 directory.
Also, I know you've stated in comments that you don't want to read the .cmd file and modify it, but you could compose your ProcessStartInfo with Environment.SystemDirectory instead of the hard-coded path.
As a last option, you could place the ffmpeg exe somewhere static (as you stated in the comments, in c:\ works), or just in your application's working directory.

Categories

Resources