Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Robocopy shows a command window in .bat

Posted on 2008-10-01
3
Medium Priority
?
1,756 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 1500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

597 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