Solved

Robocopy shows a command window in .bat

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

How our DevOps Teams Maximize Uptime

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

Question has a verified solution.

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

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
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…

856 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