TabTip.exe The requested operation requires elevation. .NET Core - asp.net-core

TabTip.exe The requested operation require
I am trying to get TabTip to pop up when a function is called. I am trying to do this with this code in .NET Core but I get the following error:
{System.ComponentModel.Win32Exception: The requested operation requires elevation
at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
at myfunc() in myClass.cs:line 64}
Here is the Code
Process p = new Process();
ProcessStartInfo processStartInfo = new ProcessStartInfo(#"C:\Program Files\Common Files\microsoft shared\ink\TabTip.exe");
p.StartInfo = processStartInfo;
p.Start();
I am running Visual Studio in Administrator mode.

This is the code that I used to complete what I was trying to accomplish. I needed to copy TabTip.exe from its original location to my project's directory.
var processlist = Process.GetProcesses();
foreach (var process in processlist.Where(process => process.ProcessName == "TabTip"))
{
process.Kill();
break;
}
Process cmd = new Process();
cmd.StartInfo.FileName = "powershell";
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.UseShellExecute = false;
cmd.Start();
cmd.StandardInput.WriteLine(".\\TabTip.exe");
cmd.StandardInput.Flush();
cmd.StandardInput.Dispose();
cmd.WaitForExit();
Debug.WriteLine(cmd.StandardOutput.ReadToEnd());

Related

Cannot execute linux commands from a Dotnet Core ASP.NET solution

Whenever I try to execute shell commands, I get an error saying
/bin/hostname: /bin/hostname: cannot execute binary file
fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[0]
An unhandled exception has occurred: Index was outside the bounds of the array.
I currently have
public MachineData FindHostname()
{
Thread.Sleep(3000);
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "/bin/bash";
psi.Arguments = "/bin/hostname && /bin/uname";
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
Process proc = new Process
{
StartInfo = psi
};
proc.Start();
...
}
Does anyone know of a workaround?

How to get return value of shell command in Mono C#

I want to know how to interact with shell from Mono and I can't seem to find very much information about this. For example, I want to return the output of "ls" and stick it into a variable - Is this even possible?
Here's what I have so far:
var proc = new Process();
proc.StartInfo.FileName = "ls";
proc.Start ();
proc.Close ()
It is possible to get the shell output. Please try the following -
Process p = new Process();
p.StartInfo = new ProcessStartInfo("/bin/ls", "-l")
{
RedirectStandardOutput = true,
UseShellExecute = false
};
p.Start();
p.WaitForExit();
//The output of the shell command will be in the outPut variable after the
//following line is executed
var outPut = p.StandardOutput.ReadToEnd();

Web Deploy API and Web Management Service (WMSVC)

I'm trying to translate the following WORKING command line into web deploy api (Microsoft.Web.Deployment) code:
"C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy.exe" -verb:sync -source:contentPath="\\myserver\code_to_deploy" -dest:contentPath="Default Web Site",wmsvc="mysandbox",userName="MyWebDeployUser",password="MyPassword" -allowUntrusted
My looks like this:
string srcPath = "\\myserver\code_to_deploy";
string destPath = "Default Web Site";
DeploymentBaseOptions sourceOptions = new DeploymentBaseOptions();
sourceOptions.TraceLevel = TraceLevel.Verbose;
sourceOptions.Trace += new EventHandler<DeploymentTraceEventArgs>(Src_Trace);
DeploymentBaseOptions destOptions = new DeploymentBaseOptions();
destOptions.UserName = "MyWebDeployUser";
destOptions.Password = "MyPassword";
destOptions.AddDefaultProviderSetting("contentPath", "wmsvc", "mysandbox");
destOptions.AuthenticationType = "basic";
destOptions.TraceLevel = TraceLevel.Verbose;
destOptions.Trace += new EventHandler<DeploymentTraceEventArgs>(Dest_Trace);
ServicePointManager.ServerCertificateValidationCallback = (s, c, chain, err) =>
{
return true;
};
DeploymentSyncOptions syncOptions = new DeploymentSyncOptions();
syncOptions.DeleteDestination = true;
using (DeploymentObject depObj = DeploymentManager.CreateObject(DeploymentWellKnownProvider.ContentPath, srcPath, sourceOptions))
{
var summary = depObj.SyncTo(DeploymentWellKnownProvider.IisApp, destPath, destOptions, syncOptions);
}
When the code makes the call to 'AddDefaultProviderSetting' it fails saying that wmsvc is not supported by the provider. If I remove the line I receive a 401 from the server. Any examples of doing this or other help is much appreciated.
I don't know whether you have found a solution but here is a code snippet that allows to use wmsvc for those who need it:
DeploymentBaseOptions destinationOptions = new DeploymentBaseOptions()
{
UserName = "<user_name>",
Password = "<password>",
IncludeAcls = false,
AuthenticationType = "Basic",
UseDelegation = true,
ComputerName = "https://<server>:8172/msdeploy.axd?Site=<website>"
};
// Use -allowUntrusted option
ServicePointManager.ServerCertificateValidationCallback +=
new RemoteCertificateValidationCallback(
(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) => { return true; });
string package = <zip_package_fullPath>;
string parameters = <project_SetParameters_xml_fullPath>;
using (var deploymentObject = DeploymentManager.CreateObject(DeploymentWellKnownProvider.Package, package))
{
deploymentObject.SyncParameters.Load(parameters);
DeploymentSyncOptions syncOptions = new DeploymentSyncOptions();
DeploymentChangeSummary results = deploymentObject.SyncTo(destinationOptions, syncOptions);
}
It's quite hard to find documentation on these topics. Btw, I've not succeeded in using AddDefaultProviderSetting, even by creating a .exe.configSettings file and I'm not sure it's the right method to achieve what you want to.
To create a virtual application instead of a website, only .SetParameters.xml has to be changed from
<setParameter name="IIS Web Application Name" value="<WebSite>" />
to
<setParameter name="IIS Web Application Name" value="<WebSite>/<VirtualApp>" />
Hope this helps.

WMIC - how to use Lenovo SetBiosSetting method

I have a prob calling SetBiosSetting method using WMIC (and also C#)
wmic /namespace:\root\wmi path Lenovo_SetBiosSetting call SetBiosSetting "SecurityChip,Active"
wmic /namespace:\root\wmi path Lenovo_SetBiosSetting call SetBiosSetting SecurityChip,Active
wmic /namespace:\root\wmi path Lenovo_SetBiosSetting call SetBiosSetting ("SecurityChip,Active")
that gives "Invalid Number of Parameters." error, but why ?
Lenovo BIOS Deployment Guide: http://download.lenovo.com/ibmdl/pub/pc/pccbbs/thinkcentre_pdf/hrdeploy_en.pdf
Any Idea ?
I cant use VBS or PowerShell ...
Thanks,Martin
Try this in C#:
ManagementScope scope = new ManagementScope(#"\\.\root\wmi");
//
// Make change(s)
//
SelectQuery queryRead = new SelectQuery("SELECT * from Lenovo_SetBiosSetting");
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, queryRead))
{
using (ManagementObjectCollection queryCollection = searcher.Get())
{
foreach (ManagementObject queryItem in queryCollection)
{
ManagementBaseObject inParams = queryItem.GetMethodParameters("SetBiosSetting");
inParams["parameter"] = "WakeOnLAN,Disable";
ManagementBaseObject outParams = queryItem.InvokeMethod("SetBiosSetting", inParams, null);
string result = outParams["return"] as string; // "Success"
}
}
}
//
// Commit to BIOS
//
queryRead = new SelectQuery("SELECT * from Lenovo_SaveBiosSettings");
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, queryRead))
{
using (ManagementObjectCollection queryCollection = searcher.Get())
{
foreach (ManagementObject queryItem in queryCollection)
{
ManagementBaseObject inParams = queryItem.GetMethodParameters("SaveBiosSettings");
inParams["parameter"] = "";
ManagementBaseObject outParams = queryItem.InvokeMethod("SaveBiosSettings", inParams, null);
string result = outParams["return"] as string; // "Success"
}
}
}
The PowerShell for this is:
(gwmi -class Lenovo_SetBiosSetting -namespace root\wmi).SetBiosSetting("WakeOnLAN,Disable")
I arrived at this post trying to find a way to use WMIC to get all the objects in the Lenovo_BiosSetting class. Your syntax got me on the right track. I had to change your WMIC query to this:
wmic /namespace:\\root\wmi path Lenovo_BiosSetting get
(Note the double back slash)

Process.Start and "The system cannot find the path specified"

I am trying to run a console application from a mapped drive (T:\ is a mapped drive for a shared network folder) and get the error:
The system cannot find the path specified.
Why do I get this error? The administrator credentials are correct.
var password = new SecureString();
password.AppendChar(Convert.ToChar("P"));
password.AppendChar(Convert.ToChar("a"));
password.AppendChar(Convert.ToChar("a"));
password.AppendChar(Convert.ToChar("s"));
Process.Start(#"t:\ca\test.exe"), "", "Administrator", password, "domain");
Check if the mapped drive T: is also correctly mapped for the Administrator account.
Also, I'm not sure, but the Administrator must probably be logged in for the mapped drive to be available.
You could also try the following, starting cmd.exe, mapping your UNC path and then calling the application:
var password = new SecureString();
password.AppendChar(Convert.ToChar("P"));
password.AppendChar(Convert.ToChar("a"));
password.AppendChar(Convert.ToChar("a"));
password.AppendChar(Convert.ToChar("s"));
var startInfo = new ProcessStartInfo();
startInfo.FileName = "cmd.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardOutput = true;
startInfo.UserName = "Administrator";
startInfo.Password = password;
startInfo.Domain = "domain";
var process = Process.Start(startInfo);
process.BeginOutputReadLine();
process.StandardInput.WriteLine(#"pushd \\your_unc_path\ca");
process.StandardInput.WriteLine("test.exe");
process.StandardInput.WriteLine("exit");
process.WaitForExit();