Sunday, May 23, 2010

Scripting C# Command Line with Robocopy

This masterpiece I wrote when writing a program I call Simple Ass Copy. SAC for short. It takes parameters from source, destination, wait, retry, and passes them to a procedure called RunParam.





36 public void RunParam ( String XRun ,
37 String XPar )
38 {
39 // MessageBox . Show ( XRun . TrimStart ( ' . ' )) ;
40 try
41 {
42 SecureString password =
43 new SecureString () ;
44 foreach ( char c in Password 1 . ToCharArray ())
45 password . AppendChar ( c ) ;
46
47
48 ProcessStartInfo procInfo = new ProcessStartInfo () ;
49
50 procInfo . UseShellExecute = false ;
51 procInfo . UserName = UserName 1 ;
52
53 procInfo . FileName = XRun ; // The file in that DIR .
54 procInfo . Password = password ; // The file in that DIR .
55
56 procInfo . WorkingDirectory = @ "" ; // The working DIR .
57 procInfo . Arguments = XPar ;
58
59 Process . Start ( procInfo ) ; // Start that process .
60
61 ntyEP . ShowBalloonTip (
62 5000 ,
63 AppTitle ,
64 XRun + " " + XPar + " has been run successfully !" ,
65 ToolTipIcon . Warning ) ;
66 }
67 catch ( Exception ex )
68 {
69 ntyEP . ShowBalloonTip (
70 5000 ,
71 AppTitle ,
72 ex . Message ,
73 ToolTipIcon . Warning ) ;
74
75 if ( btnCancel . Enabled == false )
76 {
77 stsSAC . Text = " Something went wrong !" ;
78 }
79
80 }
81 }
...

169 RunParam (" robocopy . exe " , " " + txtSource . Text +
170 " " +
171 txtDest . Text + @ " / w :" +
172 nmrWait . Value . ToString () +
173 " / r :" + nmrRetry . Value . ToString () +
174 " / e / Zb " +
175 "") ;




No comments:

Post a Comment