Solved

Robocopy shows a command window in .bat

Posted on 2008-10-01
3
1,696 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now