save my gpg file to a different directory - c#

I am working on a GPG encryption and want to save the file to a specific directory... can some one tell me how to do this..
i am using this code
ProcessStartInfo startInfo = new ProcessStartInfo()
{
WorkingDirectory = #"C:\",
CreateNoWindow = false,
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardInput = true,
RedirectStandardOutput = true
};
startInfo.FileName = "gpg.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = "-e -r myname config.xml";
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
}
when i do this it saves it to the APPdata folder is there a way i can change it to some default folder?
do i have to set some environmental variables to do this?
Please help me.. Let me know if I am not clear or i am missing something really stupid!
Thanks in advance

ProcessStartInfo startInfo = new ProcessStartInfo()
{
WorkingDirectory = #"C:\",
CreateNoWindow = false,
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardInput = true,
RedirectStandardOutput = true
};
startInfo.FileName = "gpg.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = #"-e -r myname c:\MYPATH\config.xml -o c:\MYPATH\config.xml.gpg";
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
}

Related

How to pass password StandardInput to pg_dump?

I'm creating Process to run pg_dump.exe in C#
var processStartInfo = new ProcessStartInfo
{
Arguments = #"-U postgres -W -f D:\postgres\test123_dump.sql postgres",
CreateNoWindow = true,
FileName = #"C:\PostgreSQL\bin\pg_dump.exe",
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden,
RedirectStandardInput = true
};
Process process = new Process() { StartInfo = processStartInfo, EnableRaisingEvents = true };
process.Start();
using( StreamWriter sw = process.StandardInput)
{
sw.WriteLine("123"); // test password
};
It will run pg_dump.exe, it will show prompt to pass the password, but StreamWriter seems to not work for some reason.
You could use this string to put your authentication info directly in argument list
var processStartInfo = new ProcessStartInfo
{
Arguments = #"--dbname=postgresql://user_name:pass_word#Localhost:5432/bd_name_to_save -F c -b -f output_bd_name",
CreateNoWindow = true,
FileName = #"C:\PostgreSQL\bin\pg_dump.exe",
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden,
RedirectStandardInput = true
};
Process process = new Process() { StartInfo = processStartInfo, EnableRaisingEvents = true };
process.Start();

C# How to run exe in PowerShell

I want to run mc.exe using by PowerShell as I write below.
How can I do that? I tried to add in Filename but it doesn't work.
var mcExe = #"C:\Users\developer\Desktop\Example\mc.exe ";
var proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = mcExe;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.Verb = "runas";
proc.StartInfo.Arguments = String.Format("{0}{1}{2}", "./mc alias set myCloud http://localhost:9000", "admin", "123456");
proc.Start();
Did you try set proc.StartInfo.UseShellExecute = true; ?
Because this property responsible for using powershell
Starting Powershell directly might work for you, e.g. :
using System.Diagnostics;
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = #"powershell.exe",
Arguments = #"& 'C:\Users\developer\Desktop\Example\mc.exe' #('./mc alias set myCloud http://localhost:9000', 'admin', '123456')",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true,
Verb = "runas",
};
Process process = new Process();
process.StartInfo = startInfo;
process.Start();
string output = process.StandardOutput.ReadToEnd();
string errors = process.StandardError.ReadToEnd();

Process Get the outpout of a CMD command

Im trying to get the outpout of my CMD command and i get the wrong outpout:
here's my cmd command : cm whoami
here's the outpout i should get (CMD outpout) :
C:\Users\Joevin>cm whoami
JoevinFerret
here's my code :
Process process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = "cm whoami",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
process.Start();
string outpout = process.StandardOutput.ReadLine();
here's the outpout that i get :
outpout = "Microsoft Windows [Version 10.0.19041.804]"
Thanks to Mathias.R and Christian.K i have been able to find a solution.
Here's my code:
Process process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = "/c cm whoami",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
process.Start();
string outpout = process.StandardOutput.ReadToEnd();
process.WaitForExit();

ProcessStartInfo Verb runas not working

What is wrong with the following code?
ProcessStartInfo startInfo = default(ProcessStartInfo);
startInfo = new ProcessStartInfo(SetupProgramPath)
{
UseShellExecute = true,
Verb = "runas",
WindowStyle = ProcessWindowStyle.Normal,
CreateNoWindow = false
};
Process.Start(startInfo);
It is expected to prompt for credentials but nothing shows up. The system has the UAC enabled and not supposed to be changed.
I appreciate your help in this one. Thank you in advance.
I have worked this out with the following code
ProcessStartInfo startInfo = default(ProcessStartInfo);
startInfo = new ProcessStartInfo(SetupProgramPath)
{
UseShellExecute = true,
Verb = "runas",
WindowStyle = ProcessWindowStyle.Normal,
FileName = "msiexec",
Arguments = "/i \"" + SetupProgramPath + "\"",
CreateNoWindow = false
};
Process.Start(startInfo);
If you want to ask the user to enter credentials of a different user, then use "runasuser":
ProcessStartInfo startInfo = new ProcessStartInfo(SetupProgramPath)
{
UseShellExecute = true,
Verb = "runasuser",
WindowStyle = ProcessWindowStyle.Normal,
CreateNoWindow = false
};
Process.Start(startInfo);

use mongodb_name does not work in C# Process

I regular use command
use some_mongodb
to create new database from command prompt on windows
it seems that this command does not work when you want to execute this in C# process
I have the following code trying to create mongo database from C#
ProcessStartInfo startInfo = new ProcessStartInfo
{
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true,
WorkingDirectory = _mongoBinDir,
FileName = "mongo.exe",
Arguments = "use " + databaseTxt.Text
};
_mongoInsertProcess = new Process
{
StartInfo = startInfo
};
_mongoInsertProcess.Start();
string stderrStr = _mongoInsertProcess.StandardError.ReadToEnd();
string stdoutStr = _mongoInsertProcess.StandardOutput.ReadToEnd();
stdoutStr variable get value
"MongoDB shell version: 3.2.1 connecting to: use
2016-04-07T15:28:52.875+0200 E - [main] file [some_db] doesn't
exist failed to load: some_db"
Please advise on this.
use some_db isn't a valid argument. Just pass the name of the database i.e:
ProcessStartInfo startInfo = new ProcessStartInfo
{
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true,
WorkingDirectory = _mongoBinDir,
FileName = "mongo.exe",
Arguments = databaseTxt.Text
};

Categories

Resources