when i try to run the command 'Help.F1Help' from 'Command Window' (Visual Studio -> view-> other windows-> command Window) i can able to see the help file opening.
but when i try in c# with the below code nothing working. Any help would be appreciated
Code:-
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
//startInfo.UseShellExecute = true;
startInfo.Verb = "runas";
startInfo.FileName = "cmd.exe";
//startInfo.Arguments = "/C Help.LaunchinHelpViewer";
startInfo.Arguments = "/C Help.F1Help";
process.StartInfo = startInfo;
process.Start();
Related
I want to delete files by sending IRP via a WDK driver. It works well for deleting all files no matter *.pdf or *.pptx, except some EXEs which require Administrator to run, such as EXE installer and setup.exe etc. I don't know why it hangs on IoCallDriver once I try to delete EXE installers. I have also tried to set a timeout for KeWaitForSingleObject but no luck, the driver keeps hanging on IoCallDriver.
Does Windows limit drivers to remove these Administrator authority EXEs? How to solve this? Thanks a lot.
NTSTATUS send_delete_file_irp(PFILE_OBJECT file_object) {
KEVENT event;
PDEVICE_OBJECT device_object = IoGetBaseFileSystemDeviceObject(file_object);
PIRP irp = IoAllocateIrp(device_object->StackSize, false);
// Set the complete routine that will free the IRP and signal the event
KeInitializeEvent(&event, SynchronizationEvent, false);
IoSetCompletionRoutine(
irp,
io_complete,
&event,
true,
true,
true);
FILE_DISPOSITION_INFORMATION file_disposition;
file_disposition.DeleteFile = true;
IO_STATUS_BLOCK io_status_block;
irp->AssociatedIrp.SystemBuffer = &file_disposition;
irp->UserEvent = &event;
irp->UserIosb = &io_status_block;
irp->Tail.Overlay.OriginalFileObject = file_object;
irp->Tail.Overlay.Thread = (PETHREAD)KeGetCurrentThread();
irp->RequestorMode = KernelMode;
IO_STACK_LOCATION* stack_location = IoGetNextIrpStackLocation(irp);
stack_location->MajorFunction = IRP_MJ_SET_INFORMATION;
stack_location->DeviceObject = device_object;
stack_location->FileObject = file_object;
stack_location->Parameters.SetFile.Length = sizeof(FILE_DISPOSITION_INFORMATION);
stack_location->Parameters.SetFile.FileInformationClass = FileDispositionInformation;
stack_location->Parameters.SetFile.FileObject = file_object;
IoCallDriver(device_object, irp);
KeWaitForSingleObject(&event, Executive, KernelMode, true, nullptr);
return STATUS_SUCCESS;
}
I am new to Coded UI. I have written a simple code to execute a .bat file from a CodedUITestMethod1() as below:
thisProcess.StartInfo.CreateNoWindow = true;
thisProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
thisProcess.StartInfo.FileName = #"C:\BVTBatch\PlayBack.bat";
thisProcess.StartInfo.UseShellExecute = false;
thisProcess.StartInfo.RedirectStandardOutput = true;
thisProcess.Start();
thisProcess.WaitForExit();
strException = thisProcess.StandardOutput.ReadToEnd();
Problem statement: When I debug the script, it gets executed but the batch file does not run. I tried executing iexplorer.exe, and observed same issue. The script gets executed with pass, but IE browser does not start.
However if I execute the same code from other console application or Unit Test project method, it gets executed successfully.
Can someone suggest what is the reason behind this? and how can we fix this in CodedUI?
Thanks in advance.
This would seem legit:
thisProcess.StartInfo.FileName = ("C:\BVTBatch\PlayBack.bat");
Process p = new Process();
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo = new ProcessStartInfo ("C:\BVTBatch\PlayBack.bat");
p.Start();
vstest.console.exe does not execute my tests.
var testProcess = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = #"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe",
Arguments = _testDllPath,
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
I receive the following output when executing the commandline:
Microsoft (R) Test Execution Command Line Tool Version 11.0.60315.1Copyright (c) Microsoft Corporation. All rights reserved.
NOTE: Tests do get executed when I run MSTest:
var testProcess = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = #"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\mstest.exe",
Arguments = string.Format(#"/testcontainer:""{0}"" /resultsfile:""{1}""", _testDllPath, _resultsDirectoryPath),
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
However, running mstest on the commandlline results in one of my tests failing even though I cannot reproduce the test failure in VS2012 TestExplorer.
I needed to surround my test dll path with quotes:
var testProcess = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = #"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe",
Arguments = _testDllPath.Replace(_testDllPath, '"' + _testDllPath + '"'),
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
I want to open a text file programmatically using C#. I have used :
System.Diagnostics.Process.Start(test.txt);
but this code is causing OS command injection problem when scanning for threats.
Is there any way that i can open a text file programmatically?? or way to bypass that OS command injection?
Thank you
You should call a program, say notepad:
Process.Start("notepad.exe", fileName);
the argument is the file name:
Process.Start("notepad.exe", "Test.txt");
See the problem with your code in the comments of this post:
Open a file with Notepad in C#
Try:
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new
System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
string _path = "c:/filepath";
startInfo.Arguments = string.Format("/C start {0}", _path);
process.StartInfo = startInfo;
process.Start();
I have written a console application in mono for linux.
i have to start it with
"sudo mono app.exe"
Is there some posibility to restart the app when something happens.
For examlpe I run this app on the raspberry Pi, and when the app
detects some voltage on a special IO pin the app should restart automatically.
Please help me.
You can launch a new application instance using methods in the Process class and later exit.
http://www.dotnetperls.com/process-start
On Windows you can use cmd.exe to execute the script. In this blog post the author asks cmd to wait for a while, and then delete the executable,
http://blog.pedroliska.com/2010/05/20/c-self-destruct-windows-app/
You can use the same trick to restart the executable if on Windows.
var startInfo = new ProcessStartInfo();
startInfo.FileName = "cmd.exe";
startInfo.RedirectStandardInput = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
var process = new Process();
process.StartInfo = startInfo;
process.Start();
// The delay is just making sure the exe to delete is done
// running.
var delayPings = 2;
var exeName = AppDomain.CurrentDomain.FriendlyName;
process.StandardInput.WriteLine("(ping -n " + delayPings + " 127.0.0.1) && (CALL " + exeName + ")");
Now for Linux, you just need to use bash (or another Shell) to replace cmd and also modify the command passed to it.