How to copy with default copier from cmd? - windows

I need to copy files from one folder to another from cmd and show the progress as in the user interface.
The copy and xcopy commands work but do not show progress and robocopy shows the progress but not the user interface.
Explorer.exe has some parameters, but none that works to copy.
Do you know any way to do what I need?
Thanks in advance...

There is no built-in command that does this, you have to use Windows Scripting Host or a 3rd-party application.
<?xml version="1.0" ?><job><script language="JScript"><![CDATA[
var SHA = new ActiveXObject("Shell.Application");
var FSO = WScript.CreateObject("Scripting.FileSystemObject");
if (WScript.Arguments.length != 2)
{
WScript.Echo("Usage: <SourceSpec> <DestinationPath>");
WScript.Quit(1);
}
var src = FSO.GetAbsolutePathName(WScript.Arguments(0)), dst = FSO.GetAbsolutePathName(WScript.Arguments(1));
var folder = SHA.NameSpace(dst);
var FOF_NOCONFIRMATION=0x0010;
var FOF_NOCONFIRMMKDIR=0x0200;
folder.CopyHere(src, FOF_NOCONFIRMMKDIR);
]]></script></job>
Save as shellcopy.wsf in %WinDir%.
Then in cmd.exe you can do shellcopy *.txt c:\backup etc.

Related

Is there a way to make an audio file that can only be played once?

I am looking for a way to make an audio file that can only be played once. It would be nice to do this with DRM however if there is a guide to make an EXE file that contains an audio file and when opened plays it then deletes itself that will work too. I don't know much about programming so if something like this can only be done with an EXE file then I would need a guide.
I know how I can do this with a BAT file but that would require at least two files (the BAT file and the audio file) and for my use, I need it to be a single file.
Is there a way I can go about doing this or some took to make such a file? I have been searching for a way to do this for about two hours and have come up with nothing.
Here's a console JScript.NET example to get you started. It'll only play base64-encoded wav data, though. If you want to play an mp3, that gets a little trickier.
import System; // for Convert
import System.Media; // for PlaySync()
import System.IO; // for MemoryStream
import System.Diagnostics; // for Process()
var base64EncodedWav:String = "paste your base64-encoded WAV file here",
audiobytes:byte[] = Convert.FromBase64String(base64EncodedWav),
stream:MemoryStream = new MemoryStream(audiobytes),
player:SoundPlayer = new SoundPlayer(stream);
// Play, blocking until finished
player.PlaySync();
// delete self
var self:String = System.Reflection.Assembly.GetExecutingAssembly().Location,
task:Process = new Process();
print("This message will self-destruct.");
task.StartInfo.FileName = "cmd.exe";
task.StartInfo.Arguments = "/c timeout /t 1 & del /q " + self;
task.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
task.StartInfo.CreateNoWindow = true;
task.Start();

print pdf silently in c#

I am trying to print pdf silently using adobe reader.
I have taken the example from the following location:
http://www.codeproject.com/Tips/598424/How-to-Silently-Print-PDFs-using-Adobe-Reader-and
I am able to work as desired with the above example code in my localhost.
But when I deploy my application on the server,I am unable to print the PDFs.
In my localhost on button click event,I am creating the PDFs and saving it to one location and printing the same.While printing adobe window opens and prints the PDFs and exits automatically.
The same doesn't work in my server.I am able to create and save PDFs,but adobe is not opening and printing my file.I am not even getting any exception/error.It simply doesn't show up adobe window.
Did anyone face the same issue.
Any help in this regard.
Thanks in advance.
EDIT:
If you are running on a Web Server using ASP.NET or in general IIS the new process executes on the Web server with restricted permissions. I point you out this answer that could explain the cause of your problem.
However the code you are using doesn't print any error message. You probably don't have access to the directory where the AcroRd32.exe is located.
Let's take this function from the article you posted:
public static Boolean PrintPDFs(string pdfFileName)
{
try
{
Process proc = new Process();
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.Verb = "print";
//Define location of adobe reader/command line
//switches to launch adobe in "print" mode
proc.StartInfo.FileName =
#"C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe";
proc.StartInfo.Arguments = String.Format(#"/p /h {0}", pdfFileName);
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
if (proc.HasExited == false)
{
proc.WaitForExit(10000);
}
proc.EnableRaisingEvents = true;
proc.Close();
KillAdobe("AcroRd32");
return true;
}
catch
{
return false;
}
}
PrintPDFs uses a process, which is called by the .NET framework using the Process class. In the StartInfo option you look carefully two options are set:
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
The first redirect the standard output stream to your application while the second hides the cmd window. The former is handy to use process without showing to the user a command window but the latter hide the console window. The main drawback is, if you're debugging, that you probably won't see error coming through.
One way to debug it would require to add the following to lines:
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();
Console.WriteLine(proc.StandardOutput.ReadToEnd());
Another property you can look at is ExitCode. If that is greather than zero means that your process exit with some error.
hope it helps.
A silent printing can be achieved with an Acroread command line parameters or with a PDF JavaScript event handler (of course, if your PDF producer tool has a possibility to define/inject PDF's OpenAction handler).
See http://pd4ml.com/cookbook/pdf_automated_printing.htm
With the JavaScript approach you are not bound to a printer driver, network name or IP address. On the other hand, JavaScript in Acroread can be disabled, for example, by a corporate security policy.
use this with Ghostscript that is GNU:
ProcessStartInfo info = new ProcessStartInfo();
var FileName = #"C:\ResultadoFormulario_CClastMovements.pdf";
var pathPrinter = #"\\Server\namePrinter";
info.CreateNoWindow = true;
var pathGsw = #"path gswin64c here\";
info.WindowStyle = ProcessWindowStyle.Hidden;
string strCmdText = $"{pathGsw}gswin64c.exe -sDEVICE=mswinpr2 -dBATCH -dNOPAUSE -dNOPROMPT -dNoCancel -dPDFFitPage -sOutputFile=\"%printer%{direccionImpresora}\" \"{FileName}\"";
Process.Start("CMD.exe", strCmdText);

Create shell script from Extendscript Toolkit

As one of the outputs from an Extendscript, I want to create a shell script which can then be executed by the user. Here is a very basic example:
function createShellScript()
{
var contents = "#!/bin/bash\ndate";
var outputFolder = Folder.selectDialog ("Choose where to save:");
var shFile = new File(outputFolder.absoluteURI + "/shell.sh");
shFile.open("W");
shFile.write(contents);
shFile.close();
}
createShellScript ();
If I take the resulting file (shell.sh), run chmod +x on it to make it exectuable, and then run it, nothing happens.
If, however, I adjust the script above to create the same content but a text file – so it outputs shell.txt open the file, copy the contents into a blank document in a code editor, and save as a .sh file, and then chmod and run it, it works fine.
Why does Extendscript not produce a proper .sh file when using this method?
Thanks for any help.
S
You need to set the line feed characters to unix style. For example, shFile.lineFeed = "Unix";.
function createShellScript()
{
var contents = "#!/bin/bash\ndate";
var outputFolder = Folder.selectDialog ("Choose where to save:");
var shFile = new File(outputFolder.absoluteURI + "/shell.sh");
shFile.open("W");
shFile.lineFeed = "Unix";
shFile.write(contents);
shFile.close();
}
createShellScript ();

Photoshop javascript save error 8800

In my javascript, in Windows 7, Photoshop CS2 & Photoshop CS5, it throws an error:
Error 8800: General Photoshop error occurred. This functionality may not be available in this version of Photoshop.
- Could not save a copy as "C:...\wcb-010B-11Y.jpg" because the file could not be found.
Line: 458
-> docRef.saveAs( saveFile, jpgSaveOptions, true, Extension.LOWERCASE );
here is a summary of the code to save the image:
var selectedSaveDir = "~/Desktop/";
var sFileNamePreFix = "wcb-";
var docRef = app.activeDocument;
var docName = app.activeDocument.name;
var docNewName = docName.substr( 0, docName.length - 4 ); // strip file extension
var sNewDocName = sFileNamePreFix + docNewName + ".jpg"
var sNewFileName = selectedSaveDir + sNewDocName;
//alert( "sNewFileName = " + sNewFileName ); // test to verify correct location
var saveFile = new File(sNewFileName);
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.quality = 12;
docRef.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);
In Windows XP, this script works very well in CS2 with no problems.... just in Windows 7 is where this issue occurs using CS2 or CS5.
The problem seems to be similar to : Photoshop Javascript scripting saving and closing document
But I don't know his OS.
I've added the "alert(" and confirmed the save folder & name is correct and can be saved to, but same issue.
Could it be a UAC issue in Windows 7 ? and how do you Fix it ? I've turned off all UAC settings (I think I did it correctly), but it still occurs.
Any Help ?
You missed out " var docRef = app.activeDocument;" (which i've added); but apart from that, in CS2 the script saves out a jpeg to the desktop (wcb-text test.jpg). It's obvious, but have you made sure the image is flattened or doesn't contain any information that cannot be stored in a jpeg - like paths for example.
Try forcing a flatten before saving
//flatten the image
docRef.flatten();
Another thing to try is to save out the file to another directory. I know that long file names (especially with spaces in) can cause problems - I think there's a limit to 300 characters in the file path.
I just found that, in new versions of PS this particular path variable gives the error 8800:
var selectedSaveDir = "~/Desktop/";
Use full path instead and use apostrophes instead of quotes:
var selectedSaveDir = 'C:/Users/yourname/Desktop/';

Read files in Windows Phone 7

I'm trying to open a file in Windows Phone 7, but it says it doesn't exist. Here's the code I'm trying:
IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication();
bool test = file.FileExists("\\ClientBin\\clubs.xml");
And in my project I added a folder called ClientBin, and the clubs.xml is in there. The clubs.xml file properties are:
Build action: Content
Copy to Output Directory: Copy always
I'm not sure what I'm doing wrong. You can see what I have in this screenshot.
Thanks!
When you ship a file with your application, it doesn't get stored in IsolatedStorage. You need use the conventional way of opening a file that ships with the XAP -
XDocument xdoc = XDocument.Load("ClientBin/customers.xml");
var customers = from query in xdoc.Descendants("Customer")
select new Customer
{
Name = (string)query.Element("Name"),
Employees = (int)query.Element("Employees"),
Phone = (string)query.Element("Phone")
};
// Data bind to listbox
listBox1.ItemsSource = customers;
HTH, indyfromoz

Resources