When I run my code I get the command line window popping up and it looks like it executes, but I never have an image created. I'm using the rasterize.js that came with PhantomJS
I have a number of websites I need to get a screen shot of and have stored them in a List<>.
I can't seem to narrow down just what is preventing me from having an image created. Any help would be greatly appreciated, and if there's any information that is missing or if anything needs to be clarified please let me know.
Here's my code:
foreach (var item in itemList)
{
string outPath = OUTPUTPATH + "\\" + item.foldername;
System.IO.Directory.CreateDirectory(outPath);
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "phantomjs.exe";
startInfo.WorkingDirectory = #"C:\phantomjs-1.9.7-windows\";
startInfo.WindowStyle = ProcessWindowStyle.Normal;
startInfo.CreateNoWindow = true;
startInfo.Arguments = "/C .\\examples\\rasterize.js " + item.url + " " + outPath + "\\" + item.filename+".jpg;
using (Process process = Process.Start(startInfo))
{
process.WaitForExit();
}
}
Related
I know there are other posts on the matter but none have presented me with a working solution.
I'm trying to take ownership of files under C:\Windows\Media so I can replace them with my own. Currently I've been trying to do that by running either takeown or icacls in CMD, but neither seem to work. The takeown method actually returns success from CMD but I still get access denied when trying to delete the file. With the icacls method I get "the handle is invalid" and still get access denied.
The program is running as administator fyi.
And also in the icacls method changing Environment.Username to "Administrators" doesn't change anything.
Any help is appreciated!
Here is the code for the takeown method:
string[] soundFiles;
soundFiles = Directory.GetFiles(#"C:/Windows/Media", "*.wav");
//string cmdargs = #"/c takeown /F C:\Windows\Media";
string shortcmdargs = #"/c takeown /F ";
//Process.Start("CMD.exe", cmdargs);
string output = "null";
foreach(string file in soundFiles)
{
try
{
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = shortcmdargs + #"C:\Windows\Media\" + Path.GetFileName(file);
p.Start();
output = p.StandardOutput.ReadToEnd();
System.IO.File.Delete(file);
System.IO.File.Copy("neco.wav", file);
}
catch(Exception exce)
{
MessageBox.Show("Output: " + output + "\neException: " + exce);
}
}
And here is what I get when running it:
Here is the code for the icacls method:
string[] soundFiles;
soundFiles = Directory.GetFiles(#"C:/Windows/Media", "*.wav");
string cmdargs = #"/c takeown /F C:\Windows\Media";
string shortcmdargs = #"/c takeown /F ";
Process.Start("CMD.exe", cmdargs);
string output = "null";
foreach(string file in soundFiles)
{
try
{
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = #"/c icacls " + #"C:\Windows\Media\" + Path.GetFileName(file) + " /grant " + Environment.UserName + ":(OI)(CI)F /T";
p.Start();
output = p.StandardOutput.ReadToEnd();
System.IO.File.Delete(file);
System.IO.File.Copy("neco.wav", file);
}
catch(Exception exce)
{
MessageBox.Show("Output: " + output + "\neException: " + exce);
}
}
And here is what I get with it:
I am making a C# program that will make input file an .iso file.
For example if we write C:\Users\User\Desktpo\a.txt in the textbox that I created and give a destination path for example C:\ it has to create an iso file name a in C:\.
So I downloaded PowerISO and learn about piso.exe then I made some other research about using Process.Start(); in C# so I write these lines of code:
string str = " create -o " + TextBox1.Text + ".iso -add " + TextBox2.Text + "//" ;
Process process = new Process();
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.FileName = "\"C:\PowerISO\piso.exe\"";
process.StartInfo.Arguments = str;
process.Start();
But this doesn't work.
Why?
EDIT: I am making an winform using Visual Studio 2017.
Please Note that
C:\PowerISO\piso.exe\
is not a valid C# path, the "\" before the P and the p is an escape indicater.
Either Add verbatim operator "#" before or escape it properly
edit:
In addition, you are adding extra double quotes to the FileName property.
You can check if the path is correct by asserting the file path with File.Exists method
Console.WriteLine(File.Exists(#"C:\PowerISO\piso.exe") ? "File exists." : "File does not exist.");
e.g
string str = " create -o " + TextBox1.Text + ".iso -add " + TextBox2.Text + "//" ;
Process process = new Process();
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.FileName = #"C:\PowerISO\piso.exe";
process.StartInfo.Arguments = str;
process.Start();
edit:
Verbatim operator will work, but escaping is better in my opinion.
string str = " create -o " + TextBox1.Text + ".iso -add " + TextBox2.Text + "//" ;
Process process = new Process();
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.FileName = "C:\\PowerISO\\piso.exe";
process.StartInfo.Arguments = str;
process.Start();
Here I have code that opens Adobe and causes it to print a PDF file using Process.Start(). I am trying to print multiple files (two different pdfs) using the same command. How would I go about this? This is what I have so far:
Process profilePrintProcess = new Process();
profilePrintProcess.EnableRaisingEvents = true;
profilePrintProcess.StartInfo = new ProcessStartInfo()
{
CreateNoWindow = true,
Verb = "PrintTo",
FileName = "[" + profFileName + " " + contractFileName + "]",
WindowStyle = ProcessWindowStyle.Hidden,
};
profilePrintProcess.Start();
I've been using this link as a guide per another SO question that referenced a similar issue.
to print a single file trough Acrobat Reader try this and let me know if worked:
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "AcroRd32.exe";
startInfo.Arguments = "/p " + YourPDFFilePath;
process.StartInfo = startInfo;
process.Start();
to printig multipile pdf files first combine them and next print combined document trough PDFSharp
var outputPDFDocument = PdfDocument.Combine("Output.pdf", "doc1.pdf", "doc2.pdf", "doc3.pdf");
outputPDFDocument.Save("C:\\temp.pdf");
PdfFilePrinter.AdobeReaderPath = #"C:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe";
PdfFilePrinter.DefaultPrinterName = "Take printer";
PdfFilePrinter printer = new PdfFilePrinter(#"C:\\temp.pdf");
printer.Print();
So I have the following code:
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
startInfo.FileName = "CMD.exe";
string[] serverNameParts = ServerName.Split('.');
string CN1 = t1.Text, CN2 = "Users";
string pwd = t2.Text;
startInfo.Arguments = "/c dsadd user " + "CN=" + CN1 + ",CN=" + CN2 +",";
for (int i = 0; i < serverNameParts.Length; i++)
{
startInfo.Arguments = startInfo.Arguments + "DC=" + serverNameParts[i] + ",";
}
startInfo.Arguments = startInfo.Arguments + " & ping www.google.com /t";
process.StartInfo = startInfo;
process.Start();
I used ping so I could see why it won't create an account.
What I get is this error:
Error code = 0x80005000
type dsadd /? for help.
I can't figure out what could be the problem here, I checked the final string and it looks totally fine and I even typed it into the promt and everything worked perfectly, but it won't when I use it in my app. Is there any way to solve this? I suppose it has something to do with the permissions, but I can't come up with an idea to give my program the rights to run an administrator cmd.
I'm making Visual Studio package where i start devenv.exe and try to build other solution.I need to get building output in realtime, so user can see buiding progress(output), but i don't know how to do it and if it's even possible.
I tried such way :
string rebuildLog = string.Empty;
string logFileName = System.IO.Path.GetTempFileName();
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
psi.FileName = #"devenv.exe";
psi.Arguments = "\"" + config.DmsPath + "\"" + #" /rebuild" + " Release|x64 " +" /out " + logFileName;
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo = psi;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.Start();
while (!process.StandardOutput.EndOfStream)
{
string line = process.StandardOutput.ReadLine();
MessageBox.Show(line); // just to see if it works. It should go to log form
}
rebuildLog = GetRebuildLog(logFileName);
And rebuildLog has output.
Can anybody help ?
I found answer.
devenv.exe doesn't write simple console output, so i had to change
psi.FileName = #"devenv.exe"; to psi.FileName = #"devenv.com"; and it worked.