Solved

Robocopy shows a command window in .bat

Posted on 2008-10-01
3
1,719 Views
Last Modified: 2010-04-21
There is a command window flickering when I run this code. When I only run Robocopy, no window is showing??? It seems like it is when I run as another user that the window appers. How do I get ridd of that, so the program is completely silent/hidden? (the .bat-file itself is hidden by using hstart from a vbs-file)

if exist "%path%" (runas /user:%user% "%path%\Robocopy.exe %path% "%ProgramFiles%\folder"  /MIR /E /W:0 /R:2 /XD *Script* > "%ProgramFiles%\DOM_Mallar\cp_mallar.txt"" | %path%\sanur %pwd%)

Thanks!
if exist "%path%" (runas /user:%user% "%path%\Robocopy.exe %path% "%ProgramFiles%\folder"  /MIR /E /W:0 /R:2 /XD *Script* > "%ProgramFiles%\DOM_Mallar\cp_mallar.txt"" | %path%\sanur %pwd%)

Open in new window

0
Comment
Question by:einarbrown
  • 2
3 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 22619482
Hi, I'd say the extra DOS box is appearing because of the RunAs command. You'd have to use a silent program like PSExec.exe to have no DOS box.

There may be a syntax error here, but it would be something like this.

Regards,

Rob.
if exist "%path%" (psexec -accepteula -u %user% -p %pwd% "%path%\Robocopy.exe %path% "%ProgramFiles%\folder" /MIR /E /W:0 /R:2 /XD *Script* > "%ProgramFiles%\DOM_Mallar\cp_mallar.txt"")

Open in new window

0
 
LVL 6

Author Comment

by:einarbrown
ID: 22624448
Thanks! You made me understand that it was the runas that made the window pop up. I tried the psexec but I didnt get it working. Maby I dont understand exactly how it works.

But now I have solwed it, or how ever made a work around:

First I have a vb-script file that starts a exe-file a have med myself in c#. I run the exe-file (a console app) with hstart to hide the console window.

In the c# code I run robocopy, and again I do it using the utility hstart.

Puh....


VB-file:
 
Shell.Run "path\hstart /NOCONSOLE path\MyConsoleApp.exe"
 
---------
C#:
 
if (Directory.Exists(@"path"))
            {
                System.Diagnostics.ProcessStartInfo myProcess = new System.Diagnostics.ProcessStartInfo(@"path\hstart.exe", "/NOCONSOLE \"path\\Robocopy.exe path1 path2  /MIR /E /W:0 /R:2 /XD *Script*  > path\\info.txt\"");
                System.Security.SecureString password = new System.Security.SecureString();
                string uspw = "Password";
                foreach (char c in uspw)
                {
                    password.AppendChar(c);
                }
                password.MakeReadOnly();
 
                myProcess.WorkingDirectory = @"path";
                myProcess.UserName = "UserName";
                myProcess.Password = password;
                myProcess.UseShellExecute = false;
                
                System.Diagnostics.Process.Start(myProcess);
            }
 
--------------

Open in new window

0
 
LVL 6

Author Closing Comment

by:einarbrown
ID: 31501890
Thanks allot!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question