Link to home
Start Free TrialLog in
Avatar of einarbrown
einarbrownFlag for Sweden

asked on

Robocopy shows a command window in .bat

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

ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of einarbrown

ASKER

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

Thanks allot!