|
@@ -0,0 +1,268 @@
|
|
1
|
+# Load the Windows Forms assembly
|
|
2
|
+Add-Type -AssemblyName System.Windows.Forms
|
|
3
|
+
|
|
4
|
+# Load the Media Player assembly
|
|
5
|
+Add-Type -AssemblyName PresentationCore
|
|
6
|
+
|
|
7
|
+# Create a new form
|
|
8
|
+$form = New-Object System.Windows.Forms.Form
|
|
9
|
+$form.Text = "Robocopy GUI"
|
|
10
|
+$form.Size = New-Object System.Drawing.Size(600,500)
|
|
11
|
+$form.StartPosition = "CenterScreen"
|
|
12
|
+
|
|
13
|
+# Create a label for "Source Directory"
|
|
14
|
+$sourceLabel = New-Object System.Windows.Forms.Label
|
|
15
|
+$sourceLabel.Location = New-Object System.Drawing.Point(10,10)
|
|
16
|
+$sourceLabel.Size = New-Object System.Drawing.Size(150,40)
|
|
17
|
+$sourceLabel.Text = "Source Directory"
|
|
18
|
+$form.Controls.Add($sourceLabel)
|
|
19
|
+
|
|
20
|
+# Create a text field for "Source Directory"
|
|
21
|
+$sourceBox = New-Object System.Windows.Forms.TextBox
|
|
22
|
+$sourceBox.Location = New-Object System.Drawing.Point(170,10)
|
|
23
|
+$sourceBox.Size = New-Object System.Drawing.Size(300,40)
|
|
24
|
+$form.Controls.Add($sourceBox)
|
|
25
|
+
|
|
26
|
+# Create a dropdown menu for selecting a drive
|
|
27
|
+$driveMenu = New-Object System.Windows.Forms.ComboBox
|
|
28
|
+$driveMenu.Location = New-Object System.Drawing.Point(480,10)
|
|
29
|
+$driveMenu.Size = New-Object System.Drawing.Size(100,40)
|
|
30
|
+$driveMenu.DropDownStyle = "DropDownList"
|
|
31
|
+$form.Controls.Add($driveMenu)
|
|
32
|
+
|
|
33
|
+# Get the list of drives and their names
|
|
34
|
+$drives = Get-WmiObject -Class Win32_LogicalDisk | Select-Object -Property DeviceID, VolumeName
|
|
35
|
+# Add the drives to the dropdown menu
|
|
36
|
+foreach ($drive in $drives) {
|
|
37
|
+ $driveMenu.Items.Add("$($drive.DeviceID) $($drive.VolumeName)")
|
|
38
|
+}
|
|
39
|
+
|
|
40
|
+# Create a button for "Copy from root"
|
|
41
|
+$rootButton = New-Object System.Windows.Forms.Button
|
|
42
|
+$rootButton.Location = New-Object System.Drawing.Point(10,60)
|
|
43
|
+$rootButton.Size = New-Object System.Drawing.Size(200,40)
|
|
44
|
+$rootButton.Text = "Copy from root"
|
|
45
|
+$form.Controls.Add($rootButton)
|
|
46
|
+
|
|
47
|
+# Create a button for "Copy from users directory"
|
|
48
|
+$usersButton = New-Object System.Windows.Forms.Button
|
|
49
|
+$usersButton.Location = New-Object System.Drawing.Point(220,60)
|
|
50
|
+$usersButton.Size = New-Object System.Drawing.Size(200,40)
|
|
51
|
+$usersButton.Text = "Copy from users directory"
|
|
52
|
+$form.Controls.Add($usersButton)
|
|
53
|
+
|
|
54
|
+# Create a label for "Destination Directory"
|
|
55
|
+$destinationLabel = New-Object System.Windows.Forms.Label
|
|
56
|
+$destinationLabel.Location = New-Object System.Drawing.Point(10,110)
|
|
57
|
+$destinationLabel.Size = New-Object System.Drawing.Size(150,40)
|
|
58
|
+$destinationLabel.Text = "Destination Directory"
|
|
59
|
+$form.Controls.Add($destinationLabel)
|
|
60
|
+
|
|
61
|
+# Create a text field for "Destination Directory"
|
|
62
|
+$destinationBox = New-Object System.Windows.Forms.TextBox
|
|
63
|
+$destinationBox.Location = New-Object System.Drawing.Point(170,110)
|
|
64
|
+$destinationBox.Size = New-Object System.Drawing.Size(300,40)
|
|
65
|
+$form.Controls.Add($destinationBox)
|
|
66
|
+
|
|
67
|
+# Create a button for "Copy to OldDrv"
|
|
68
|
+$oldDrvButton = New-Object System.Windows.Forms.Button
|
|
69
|
+$oldDrvButton.Location = New-Object System.Drawing.Point(480,110)
|
|
70
|
+$oldDrvButton.Size = New-Object System.Drawing.Size(100,40)
|
|
71
|
+$oldDrvButton.Text = "Copy to OldDrv"
|
|
72
|
+$form.Controls.Add($oldDrvButton)
|
|
73
|
+
|
|
74
|
+# Create a checkbox for "Use custom directory exclusions:"
|
|
75
|
+$xdCheckbox = New-Object System.Windows.Forms.CheckBox
|
|
76
|
+$xdCheckbox.Location = New-Object System.Drawing.Point(10,160)
|
|
77
|
+$xdCheckbox.Size = New-Object System.Drawing.Size(250,30)
|
|
78
|
+$xdCheckbox.Text = "Use custom directory exclusions:"
|
|
79
|
+$form.Controls.Add($xdCheckbox)
|
|
80
|
+
|
|
81
|
+# Create a text field for the /XD parameter
|
|
82
|
+$xdBox = New-Object System.Windows.Forms.TextBox
|
|
83
|
+$xdBox.Location = New-Object System.Drawing.Point(270,160)
|
|
84
|
+$xdBox.Size = New-Object System.Drawing.Size(300,30)
|
|
85
|
+$form.Controls.Add($xdBox)
|
|
86
|
+
|
|
87
|
+# Create a checkbox for "Use custom file exclusions:"
|
|
88
|
+$xfCheckbox = New-Object System.Windows.Forms.CheckBox
|
|
89
|
+$xfCheckbox.Location = New-Object System.Drawing.Point(10,200)
|
|
90
|
+$xfCheckbox.Size = New-Object System.Drawing.Size(250,30)
|
|
91
|
+$xfCheckbox.Text = "Use custom file exclusions:"
|
|
92
|
+$form.Controls.Add($xfCheckbox)
|
|
93
|
+
|
|
94
|
+# Create a text field for the /XF parameter
|
|
95
|
+$xfBox = New-Object System.Windows.Forms.TextBox
|
|
96
|
+$xfBox.Location = New-Object System.Drawing.Point(270,200)
|
|
97
|
+$xfBox.Size = New-Object System.Drawing.Size(300,30)
|
|
98
|
+$form.Controls.Add($xfBox)
|
|
99
|
+
|
|
100
|
+# Create a checkbox for "Disable standard exclusions:"
|
|
101
|
+$noStandardCheckbox = New-Object System.Windows.Forms.CheckBox
|
|
102
|
+$noStandardCheckbox.Location = New-Object System.Drawing.Point(10,240)
|
|
103
|
+$noStandardCheckbox.Size = New-Object System.Drawing.Size(250,30)
|
|
104
|
+$noStandardCheckbox.Text = "Disable standard exclusions"
|
|
105
|
+$form.Controls.Add($noStandardCheckbox)
|
|
106
|
+
|
|
107
|
+# Create a checkbox for "Log to file:"
|
|
108
|
+$logCheckbox = New-Object System.Windows.Forms.CheckBox
|
|
109
|
+$logCheckbox.Location = New-Object System.Drawing.Point(10,280)
|
|
110
|
+$logCheckbox.Size = New-Object System.Drawing.Size(250,30)
|
|
111
|
+$logCheckbox.Text = "Log to file:"
|
|
112
|
+$form.Controls.Add($logCheckbox)
|
|
113
|
+
|
|
114
|
+# Create a text field for the /LOG parameter
|
|
115
|
+$logBox = New-Object System.Windows.Forms.TextBox
|
|
116
|
+$logBox.Location = New-Object System.Drawing.Point(270,280)
|
|
117
|
+$logBox.Size = New-Object System.Drawing.Size(300,30)
|
|
118
|
+$form.Controls.Add($logBox)
|
|
119
|
+
|
|
120
|
+# Create a checkbox for "Log to C:\MCW\rbc.log"
|
|
121
|
+$mcwCheckbox = New-Object System.Windows.Forms.CheckBox
|
|
122
|
+$mcwCheckbox.Location = New-Object System.Drawing.Point(10,320)
|
|
123
|
+$mcwCheckbox.Size = New-Object System.Drawing.Size(250,30)
|
|
124
|
+$mcwCheckbox.Text = "Log to C:\MCW\rbc.log"
|
|
125
|
+$form.Controls.Add($mcwCheckbox)
|
|
126
|
+
|
|
127
|
+# Create a button for "Run"
|
|
128
|
+$runButton = New-Object System.Windows.Forms.Button
|
|
129
|
+$runButton.Location = New-Object System.Drawing.Point(10,360)
|
|
130
|
+$runButton.Size = New-Object System.Drawing.Size(200,40)
|
|
131
|
+$runButton.Text = "Run"
|
|
132
|
+$form.Controls.Add($runButton)
|
|
133
|
+
|
|
134
|
+# Define a function for running robocopy
|
|
135
|
+function Run-Robocopy {
|
|
136
|
+ # Get the values from the text fields
|
|
137
|
+ $source = $sourceBox.Text
|
|
138
|
+ $destination = $destinationBox.Text
|
|
139
|
+ $xd = $xdBox.Text
|
|
140
|
+ $xf = $xfBox.Text
|
|
141
|
+ $log = $logBox.Text
|
|
142
|
+
|
|
143
|
+ # Check if the source and destination are valid
|
|
144
|
+ if ((Test-Path $source)) {
|
|
145
|
+ # Build the robocopy command
|
|
146
|
+ $command = powershell.exe "robocopy $source $destination /E /COPY:DAT /DCOPY:DAT /XO /XJ /FP /ZB /ETA /w:1 /r:2"
|
|
147
|
+ # Check if the custom directory exclusions are enabled
|
|
148
|
+ if ($xdCheckbox.Checked) {
|
|
149
|
+ # Add the /XD parameter
|
|
150
|
+ $command += " /XD $xd"
|
|
151
|
+ }
|
|
152
|
+ # Check if the custom file exclusions are enabled
|
|
153
|
+ if ($xfCheckbox.Checked) {
|
|
154
|
+ # Add the /XF parameter
|
|
155
|
+ $command += " /XF $xf"
|
|
156
|
+ }
|
|
157
|
+ # Check if the standard exclusions are disabled
|
|
158
|
+ if ($noStandardCheckbox.Checked) {
|
|
159
|
+ # Do nothing
|
|
160
|
+ }
|
|
161
|
+ else {
|
|
162
|
+ # Add the standard directory and file exclusions
|
|
163
|
+ $command += " /XD *Cache* *NVIDIACorp* *Spotify* *CacheStorage* *wpnidm* *FileHistory* *PrimeVideo* *Netflix_* *MobileSync* *CrashReporter* *Temporary Internet Files* *GRBData*"
|
|
164
|
+ $command += " /XF *.dll *.bin *.loggz *.odlgz"
|
|
165
|
+ }
|
|
166
|
+ # Check if the log to file is enabled
|
|
167
|
+ if ($logCheckbox.Checked) {
|
|
168
|
+ # Add the /LOG parameter
|
|
169
|
+ $command += " /LOG:$log"
|
|
170
|
+ }
|
|
171
|
+ # Check if the log to C:\MCW\rbc.log is enabled
|
|
172
|
+ if ($mcwCheckbox.Checked) {
|
|
173
|
+ # Get the current timestamp
|
|
174
|
+ $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
|
|
175
|
+ # Add the /LOG+ parameter
|
|
176
|
+ $command += " /LOG+:C:\MCW\rbc.log"
|
|
177
|
+ # Check if the C:\MCW directory exists
|
|
178
|
+ if (Test-Path "C:\MCW") {
|
|
179
|
+ # Do nothing
|
|
180
|
+ }
|
|
181
|
+ else {
|
|
182
|
+ # Create the C:\MCW directory
|
|
183
|
+ New-Item -Path "C:\MCW" -ItemType Directory
|
|
184
|
+ }
|
|
185
|
+ # Check if the log file exists
|
|
186
|
+ if (Test-Path "C:\MCW\rbc.log") { # Do nothing
|
|
187
|
+ }
|
|
188
|
+ else {
|
|
189
|
+ # Create the log file
|
|
190
|
+ New-Item -Path "C:\MCW\rbc.log" -ItemType File
|
|
191
|
+ }
|
|
192
|
+ # Add the timestamp to the log file
|
|
193
|
+ Set-ItemProperty -Path "C:\MCW\rbc.log" -Value "$timestamp"
|
|
194
|
+ }
|
|
195
|
+ # Create a new powershell window to run the robocopy command
|
|
196
|
+ $newWindow = "powershell -NoExit -Command `"$command; pause`""
|
|
197
|
+ # Execute the new window command
|
|
198
|
+ Invoke-Expression $newWindow
|
|
199
|
+ # Play Ring06.wav from the system Media folder
|
|
200
|
+ $player = New-Object System.Windows.Media.MediaPlayer
|
|
201
|
+ $player.Open("C:\Windows\Media\Ring06.wav")
|
|
202
|
+ $player.Play()
|
|
203
|
+ }
|
|
204
|
+ else {
|
|
205
|
+ # Show an error message
|
|
206
|
+ [System.Windows.Forms.MessageBox]::Show("Invalid source or destination directory.", "Error", "OK", "Error")
|
|
207
|
+ }
|
|
208
|
+}
|
|
209
|
+
|
|
210
|
+# Define a function for copying from users directory
|
|
211
|
+function Copy-From-Users {
|
|
212
|
+ # Get the selected drive from the dropdown menu
|
|
213
|
+ $drive = $driveMenu.SelectedItem
|
|
214
|
+ # Check if the drive is valid
|
|
215
|
+ if ($drive) {
|
|
216
|
+ # Get the drive letter
|
|
217
|
+ $driveLetter = $drive.Substring(0,2)
|
|
218
|
+ # Set the source directory to the users directory of the drive
|
|
219
|
+ $sourceBox.Text = "$driveLetter\Users"
|
|
220
|
+ }
|
|
221
|
+ else {
|
|
222
|
+ # Show an error message
|
|
223
|
+ [System.Windows.Forms.MessageBox]::Show("Please select a drive.", "Error", "OK", "Error")
|
|
224
|
+ }
|
|
225
|
+}
|
|
226
|
+
|
|
227
|
+# Define a function for copying to OldDrv
|
|
228
|
+function Copy-To-OldDrv {
|
|
229
|
+ # Set the destination directory to C:\OldDrv
|
|
230
|
+ $destinationBox.Text = "C:\OldDrv"
|
|
231
|
+ # Check if the source directory contains the string "Users"
|
|
232
|
+ if ($sourceBox.Text -match "Users") {
|
|
233
|
+ # Append "\Users" to the destination directory
|
|
234
|
+ $destinationBox.Text += "\Users"
|
|
235
|
+ }
|
|
236
|
+}
|
|
237
|
+
|
|
238
|
+# Define a function for copying from root
|
|
239
|
+function Copy-From-Root {
|
|
240
|
+ # Get the selected drive from the dropdown menu
|
|
241
|
+ $drive = $driveMenu.SelectedItem
|
|
242
|
+ # Check if the drive is valid
|
|
243
|
+ if ($drive) {
|
|
244
|
+ # Get the drive letter
|
|
245
|
+ $driveLetter = $drive.Substring(0,2)
|
|
246
|
+ # Set the source directory to the root of the drive
|
|
247
|
+ $sourceBox.Text = "$driveLetter\"
|
|
248
|
+ }
|
|
249
|
+ else {
|
|
250
|
+ # Show an error message
|
|
251
|
+ [System.Windows.Forms.MessageBox]::Show("Please select a drive.", "Error", "OK", "Error")
|
|
252
|
+ }
|
|
253
|
+}
|
|
254
|
+
|
|
255
|
+# Add a click event handler for the run button
|
|
256
|
+$runButton.Add_Click({ Run-Robocopy })
|
|
257
|
+
|
|
258
|
+# Add a click event handler for the copy from users directory button
|
|
259
|
+$usersButton.Add_Click({ Copy-From-Users })
|
|
260
|
+
|
|
261
|
+# Add a click event handler for the copy to OldDrv button
|
|
262
|
+$oldDrvButton.Add_Click({ Copy-To-OldDrv })
|
|
263
|
+
|
|
264
|
+# Add a click event handler for the copy from root button
|
|
265
|
+$rootButton.Add_Click({ Copy-From-Root })
|
|
266
|
+
|
|
267
|
+# Show the form
|
|
268
|
+$form.ShowDialog()
|