-
Notifications
You must be signed in to change notification settings - Fork 37
/
vds.psm1
5995 lines (5339 loc) · 172 KB
/
vds.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Add-Type -AssemblyName System.Windows.Forms,presentationframework, presentationcore, Microsoft.VisualBasic
Add-Type @"
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;
public class vds {
public static void SetCompat()
{
// SetProcessDPIAware();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
}
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern bool SetProcessDPIAware();
[DllImport("user32.dll")]
public static extern bool InvertRect(IntPtr hDC, [In] ref RECT lprc);
[DllImport("user32.dll")]
public static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);
[DllImport("user32.dll")]
public static extern IntPtr WindowFromPoint(System.Drawing.Point p);
// Now working in pwsh 7 thanks to advice from seeminglyscience#2404 on Discord
[DllImport("user32.dll")]
public static extern IntPtr GetParent(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);
[DllImport("user32.dll")]
public static extern bool ShowWindow(int hWnd, WindowState nCmdShow);
public enum WindowState
{
SW_HIDE = 0,
SW_SHOW_NORMAL = 1,
SW_SHOW_MINIMIZED = 2,
SW_MAXIMIZE = 3,
SW_SHOW_MAXIMIZED = 3,
SW_SHOW_NO_ACTIVE = 4,
SW_SHOW = 5,
SW_MINIMIZE = 6,
SW_SHOW_MIN_NO_ACTIVE = 7,
SW_SHOW_NA = 8,
SW_RESTORE = 9,
SW_SHOW_DEFAULT = 10,
SW_FORCE_MINIMIZE = 11
}
[DllImport("User32.dll")]
public static extern bool MoveWindow(int hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
[DllImport("User32.dll")]
public static extern bool GetWindowRect(int hWnd, out RECT lpRect);
[DllImport("user32.dll", EntryPoint="FindWindow")]
internal static extern int FWBC(string lpClassName, int ZeroOnly);
public static int FindWindowByClass(string lpClassName) {
return FWBC(lpClassName, 0);}
[DllImport("user32.dll", EntryPoint="FindWindow")]
internal static extern int FWBT(int ZeroOnly, string lpTitle);
public static int FindWindowByTitle(string lpTitle) {
return FWBT(0, lpTitle);}
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
public static extern IntPtr GetWindow(int hWnd, uint uCmd);
[DllImport("user32.dll")]
public static extern int GetWindowTextLength(int hWnd);
[DllImport("user32.dll")]
public static extern IntPtr GetWindowText(IntPtr hWnd, System.Text.StringBuilder text, int count);
[DllImport("user32.dll")]
public static extern IntPtr GetClassName(IntPtr hWnd, System.Text.StringBuilder text, int count);
[DllImport("user32.dll")]
public static extern bool SetWindowPos(int hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
[DllImport ("user32.dll")]
public static extern bool SetParent(int ChWnd, int hWnd);
[DllImport("user32.dll")]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("User32.dll")]
public static extern bool SetWindowText(IntPtr hWnd, string lpString);
//CC-BY-SA
//Adapted from script by StephenP
//https://stackoverflow.com/users/3594883/stephenp
[DllImport("User32.dll")]
extern static uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);
public struct INPUT
{
public int type; // 0 = INPUT_MOUSE,
// 1 = INPUT_KEYBOARD
// 2 = INPUT_HARDWARE
public MOUSEINPUT mi;
}
public struct MOUSEINPUT
{
public int dx ;
public int dy ;
public int mouseData ;
public int dwFlags;
public int time;
public IntPtr dwExtraInfo;
}
const int MOUSEEVENTF_MOVED = 0x0001 ;
const int MOUSEEVENTF_LEFTDOWN = 0x0002 ;
const int MOUSEEVENTF_LEFTUP = 0x0004 ;
const int MOUSEEVENTF_RIGHTDOWN = 0x0008 ;
const int MOUSEEVENTF_RIGHTUP = 0x0010 ;
const int MOUSEEVENTF_MIDDLEDOWN = 0x0020 ;
const int MOUSEEVENTF_MIDDLEUP = 0x0040 ;
const int MOUSEEVENTF_WHEEL = 0x0080 ;
const int MOUSEEVENTF_XDOWN = 0x0100 ;
const int MOUSEEVENTF_XUP = 0x0200 ;
const int MOUSEEVENTF_ABSOLUTE = 0x8000 ;
const int screen_length = 0x10000 ;
public static void LeftClickAtPoint(int x, int y, int width, int height)
{
//Move the mouse
INPUT[] input = new INPUT[3];
input[0].mi.dx = x*(65535/width);
input[0].mi.dy = y*(65535/height);
input[0].mi.dwFlags = MOUSEEVENTF_MOVED | MOUSEEVENTF_ABSOLUTE;
//Left mouse button down
input[1].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
//Left mouse button up
input[2].mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(3, input, Marshal.SizeOf(input[0]));
}
public static void RightClickAtPoint(int x, int y, int width, int height)
{
//Move the mouse
INPUT[] input = new INPUT[3];
input[0].mi.dx = x*(65535/width);
input[0].mi.dy = y*(65535/height);
input[0].mi.dwFlags = MOUSEEVENTF_MOVED | MOUSEEVENTF_ABSOLUTE;
//Left mouse button down
input[1].mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
//Left mouse button up
input[2].mi.dwFlags = MOUSEEVENTF_RIGHTUP;
SendInput(3, input, Marshal.SizeOf(input[0]));
}
//End CC-SA
[DllImport("user32.dll")] public static extern int SetForegroundWindow(IntPtr hwnd);
}
public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
"@ -ReferencedAssemblies System.Windows.Forms,System.Drawing,System.Drawing.Primitives,System.Net.Primitives,System.ComponentModel.Primitives,Microsoft.Win32.Primitives
<#
Function: FlashWindow
Author: Boe Prox
https://social.technet.microsoft.com/profile/boe%20prox/
Adapted to VDS: 20190212
License: Microsoft Limited Public License
#>
if ((get-host).version.major -eq 7) {
if ((get-host).version.minor -eq 0) {
Add-Type @"
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.ComponentModel;
public class vdsForm:Form {
[DllImport("user32.dll")]
public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
[DllImport("user32.dll")]
public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
protected override void WndProc(ref Message m) {
base.WndProc(ref m);
if (m.Msg == 0x0312) {
int id = m.WParam.ToInt32();
foreach (Control item in this.Controls) {
if (item.Name == "hotkey") {
item.Text = id.ToString();
}
}
}
}
}
"@ -ReferencedAssemblies System.Windows.Forms,System.Drawing,System.Drawing.Primitives,System.Net.Primitives,System.ComponentModel.Primitives,Microsoft.Win32.Primitives
}
else{
Add-Type @"
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.ComponentModel;
public class vdsForm:Form {
[DllImport("user32.dll")]
public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
[DllImport("user32.dll")]
public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
protected override void WndProc(ref Message m) {
base.WndProc(ref m);
if (m.Msg == 0x0312) {
int id = m.WParam.ToInt32();
foreach (Control item in this.Controls) {
if (item.Name == "hotkey") {
item.Text = id.ToString();
}
}
}
}
}
"@ -ReferencedAssemblies System.Windows.Forms,System.Drawing,System.Drawing.Primitives,System.Net.Primitives,System.ComponentModel.Primitives,Microsoft.Win32.Primitives,System.Windows.Forms.Primitives
}
}
else {
Add-Type @"
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.ComponentModel;
public class vdsForm:Form {
[DllImport("user32.dll")]
public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
[DllImport("user32.dll")]
public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
protected override void WndProc(ref Message m) {
base.WndProc(ref m);
if (m.Msg == 0x0312) {
int id = m.WParam.ToInt32();
foreach (Control item in this.Controls) {
if (item.Name == "hotkey") {
item.Text = id.ToString();
}
}
}
}
}
"@ -ReferencedAssemblies System.Windows.Forms,System.Drawing
}
Add-Type -TypeDefinition @"
//"
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
public class Window
{
[StructLayout(LayoutKind.Sequential)]
public struct FLASHWINFO
{
public UInt32 cbSize;
public IntPtr hwnd;
public UInt32 dwFlags;
public UInt32 uCount;
public UInt32 dwTimeout;
}
//Stop flashing. The system restores the window to its original state.
const UInt32 FLASHW_STOP = 0;
//Flash the window caption.
const UInt32 FLASHW_CAPTION = 1;
//Flash the taskbar button.
const UInt32 FLASHW_TRAY = 2;
//Flash both the window caption and taskbar button.
//This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags.
const UInt32 FLASHW_ALL = 3;
//Flash continuously, until the FLASHW_STOP flag is set.
const UInt32 FLASHW_TIMER = 4;
//Flash continuously until the window comes to the foreground.
const UInt32 FLASHW_TIMERNOFG = 12;
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool FlashWindowEx(ref FLASHWINFO pwfi);
public static bool FlashWindow(IntPtr handle, UInt32 timeout, UInt32 count)
{
IntPtr hWnd = handle;
FLASHWINFO fInfo = new FLASHWINFO();
fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
fInfo.hwnd = hWnd;
fInfo.dwFlags = FLASHW_ALL | FLASHW_TIMERNOFG;
fInfo.uCount = count;
fInfo.dwTimeout = timeout;
return FlashWindowEx(ref fInfo);
}
}
"@
$global:ctscale = 1
$global:xmen = $false
$global:excelinit = $false
$global:fieldsep = "|"
$global:database = new-object System.Data.Odbc.OdbcConnection
set-alias run invoke-expression
function VisualStyle() {
[vds]::SetCompat() | out-null
}
function DPIAware($a) {
$vscreen = [System.Windows.Forms.SystemInformation]::VirtualScreen.height
[vds]::SetProcessDPIAware() | out-null
$screen = [System.Windows.Forms.SystemInformation]::VirtualScreen.height
$global:ctscale = ($screen/$vscreen)
}
function abs($a) {
<#
.SYNOPSIS
Returns the abslute value of a number.
.DESCRIPTION
VDS
$number = -5
if ($(abs $number) -gt 4)
{console "It's greater than 4"}
.LINK
https://dialogshell.com/vds/help/index.php/abs
#>
return [math]::abs($a)
}
function alt($a) {
return "%$a"
<#
.SYNOPSIS
Sends the ALT key plus string. Only useful with 'window send'.
.DESCRIPTION
VDS
window send $(winexists notepad) $(alt "F")
.LINK
https://dialogshell.com/vds/help/index.php/alt
#>
}
function asc($a) {
<#
.SYNOPSIS
Returns the ascii code number related to character $a.
.DESCRIPTION
VDS
$(asc 'm')
.LINK
https://dialogshell.com/vds/help/index.php/asc
#>
return [byte][char]$a
}
function ask($a,$b) {
$ask = [System.Windows.Forms.MessageBox]::Show($a,$b,'YesNo','Info')
return $ask
<#
.SYNOPSIS
Opens a dialog window to ask the user a question.
.DESCRIPTION
VDS
if ($(ask "Is this the question?" "This is the title") -eq "Yes")
{info "This is the question"}
else
{info "This is not the question"}
.LINK
https://dialogshell.com/vds/help/index.php/ask
#>
}
function beep {
[console]::beep(500,300)
<#
.SYNOPSIS
Beeps
.DESCRIPTION
VDS
beep
.LINK
https://dialogshell.com/vds/help/index.php?title=Beep
#>
}
function both($a, $b) {
if (($a) -and ($b)) {
return $true
}
else {
return $false
}
<#
.SYNOPSIS
Checks if both values are $true
.DESCRIPTION
VDS
if ($(both 1 2)){console "Both 1 and 2 exists"}
.LINK
https://dialogshell.com/vds/help/index.php/both
#>
}
function chr ($a) {
$a = $a | Out-String
return [char][byte]$a
<#
.SYNOPSIS
Returns the ascii code to character
.DESCRIPTION
VDS
$(chr 34)
.LINK
https://dialogshell.com/vds/help/index.php/chr
#>
}
function clipboard ($a,$b) {
switch ($a) {
append {
Set-Clipboard -Append $b
}
clear {
echo $null | clip
}
set {
Set-Clipboard -Value $b
}
}
<#
.SYNOPSIS
Performs clipboard operations
Paramters: append, clear or set
.DESCRIPTION
VDS
clipboard set $clip
.LINK
https://dialogshell.com/vds/help/index.php?title=Clipboard
#>
}
function clipbrd {
return Get-Clipboard -Format Text
<#
.SYNOPSIS
Returns the text in the clipboard
.DESCRIPTION
VDS
window send $(winexists notepad) $(clipbrd)
.LINK
https://dialogshell.com/vds/help/index.php/clipbrd
#>
}
function color ($a,$b,$c,$d) {
switch ($a.toLower()) {
name {return [System.Drawing.Color]::FromName($b)}
rgb {return [System.Drawing.Color]::FromArgb($b,$c,$d)}
}
<#
.SYNOPSIS
Returns color by name or rgb
.DESCRIPTION
VDS
Color
.LINK
https://dialogshell.com/vds/help/index.php/color
#>
}
function colordlg {
$colorDialog = new-object System.Windows.Forms.ColorDialog
$colorDialog.ShowDialog() | Out-Null
if (($global:colordlg -eq $null) -or ($global:colordlg -eq "object")) {
return $colorDialog
}
else {
return $colorDialog.color.name
}
<#
.SYNOPSIS
Produces a color selection dialog.
If 'option colordlg normal' has been set, this will return the friendly color name, otherwise it returns the entire colorDialog object.
If 'option colordlg normal' is set, it may be unset using 'option colordlg object'.
.DESCRIPTION
VDS
$color = $(colordlg); console $color.color.R; console $color.color.G; console $color.color.B
.LINK
https://dialogshell.com/vds/help/index.php/colordlg
#>
}
function console ($a,$b){
switch ($a) {
read {
return read-host -prompt $b
}
write {
write-host $b
}
default {
write-host $a
}
}
<#
.SYNOPSIS
Performs console write or read operations
.DESCRIPTION
VDS
$read = $(console read)
.LINK
https://dialogshell.com/vds/help/index.php?title=Console
#>
}
function count ($a) {
return $a.items.count
<#
.SYNOPSIS
Returns the count of items in an object, usually a listbox.
.DESCRIPTION
VDS
$c = $(count $listbox1)
.LINK
https://dialogshell.com/vds/help/index.php/count
#>
}
function cr {
return chr(13)
<#
.SYNOPSIS
A carriage return, this is usually followed by a line feed.
.DESCRIPTION
VDS
info "Return a new line $(cr) here."
.LINK
https://dialogshell.com/vds/help/index.php/cr
#>
}
function csv ($a,$b,$c,$d,$e,$f)
{
switch ($a)
{
read{
if ($e){
while ($i -lt $e) {
$build += ($i+1),($i+2)
$i = $i+2
}
}
else {
while ($i -lt 256) {
$build += ($i+1),($i+2)
$i = $i+2
}
}
$csv = Import-Csv $b -header $build.ForEach({ $_ })
$i = 0
$csv | %{
$i = $i+1
if ($i -eq $d){
return $_.$c
}
}
}
write {
if ($f){
while ($i -lt $f) {
$build += ($i+1),($i+2)
$i = $i+2
}
}
else {
while ($i -lt 256) {
$build += ($i+1),($i+2)
$i = $i+2
}
}
$csv = Import-Csv $b -header $build.ForEach({ $_ })
$i = 0
$csv | %{
$i = $i+1
if ($i -eq $d){
$_.$c = $e
return $csv
}
}
}
count {
if ($c){
while ($i -lt $c) {
$build += ($i+1),($i+2)
$i = $i+2
}
}
else {
while ($i -lt 256) {
$build += ($i+1),($i+2)
$i = $i+2
}
}
$csv = Import-Csv $b -header $build.ForEach({ $_ })
return $csv.count
}
save {
$b | export-csv $c -NoTypeInformation
$Content = Get-content $c | select-object -skip 1
$Content | out-file $c -Encoding utf8
}
}
<#
.SYNOPSIS
Manipulate CSV files
.DESCRIPTION
VDS
#There are 300 columns. Read cell A1
$csv = $(csv read c:\temp\temp.csv 1 1 300)
#There are less than 255 columns. Read cell B2
$csv = $(csv read c:\temp\temp.csv 2 2)
#There are 300 columns. Write to cell A1, return the whole CSV back.
$csv = $(csv write c:\temp\temp.csv 1 1 NotMyCow 300)
#There are less than 255 columns. Write cell B2, return the whole CSV back.
$csv = $(csv write c:\temp\temp.csv 2 2 Beans)
#Get the row count of a CSV
$csv = $(csv count c:\temp\temp.csv)
#Save CSV file
csv save $csv c:\temp\temp.csv
.LINK
https://dialogshell.com/vds/help/index.php?title=csv
#>
}
function ctrl($a) {
return "^$a"
<#
.SYNOPSIS
Sends the CTRL key plus string. Only useful with 'window send'.
.DESCRIPTION
VDS
window send $(winexists notepad) $(ctrl "s")
.LINK
https://dialogshell.com/vds/help/index.php/ctrl
#>
}
function curdir {
return $(trim (Get-Location | Select-Object -expandproperty Path | Out-String))
<#
.SYNOPSIS
Returns the current directory as string
.DESCRIPTION
VDS
$c = $(curdir)
directory change c:\windows
rem do some stuff
directory change $c
.LINK
https://dialogshell.com/vds/help/index.php/curdir
#>
}
function database($a,$b) {
switch ($a) {
Open {
$database.connectionstring = "DSN="+$b
$database.Open()
}
Close {
$database.Close()
}
Execute {
$command = New-object System.Data.Odbc.OdbcCommand($b,$database)
$getdata = new-object System.Data.Dataset
(new-object System.Data.odbc.Odbcdataadapter($command)).Fill($getdata)
return $getdata.tables
}
}
<#
.SYNOPSIS
Performs ODBC database operations, open requires the connection name, close closes the connection, execute is a sql command that returns data tables.
.DESCRIPTION
VDS
$q = $(database execute 'select * from table where name like $string')
.LINK
https://dialogshell.com/vds/help/index.php?title=Database
#>
}
function date($a)
{
return [System.Convert]::ToDateTime($a)
<#
.SYNOPSIS
Converts string to date (for math operations)
.DESCRIPTION
VDS
write-host $(date '7/17/2020 8:52:33 pm').AddDays(-1)
.LINK
https://dialogshell.com/vds/help/index.php?title=date
#>
}
function datetime {
return Get-Date
<#
.SYNOPSIS
Returns the current date and time.
.DESCRIPTION
VDS
$(datetime)
.LINK
https://dialogshell.com/vds/help/index.php/datetime
#>
}
function decrypt ($a, $b){
if ($b){
[byte[]]$b = $b.split(" ")
$secure = $a | ConvertTo-SecureString -Key $b
$user = "inconsequential"
$credObject = New-Object System.Management.Automation.PSCredential -ArgumentList $user, $secure
return ($credObject.GetNetworkCredential().Password)
}
else{
$secure = $a | ConvertTo-SecureString
$user = "inconsequential"
$credObject = New-Object System.Management.Automation.PSCredential -ArgumentList $user, $secure
return ($credObject.GetNetworkCredential().Password)
}
<#
.SYNOPSIS
Decrypt an encrypted secret.
.DESCRIPTION
VDS
$encrypt = 'Hello'
$b = $(encrypt $encrypt 'Aes')
$vals = $b.Split($(fieldsep))
info $(decrypt $vals[0] $vals[1])
.LINK
https://dialogshell.com/vds/help/index.php/decrypt
#>
}
function dialog($a,$b,$c,$d,$e,$f,$g,$h) {
function AddControl2 ($mControl){
$mReturnControl = $null
$ctrol = $mControl.Type | Out-String
$ctrol = $ctrol.trim()
switch($ctrol) {
"StatusStrip" {
$mReturnControl = New-Object System.Windows.Forms.$ctrol
$mReturnControl.Name = $mControl.Name
Return $mReturnControl
}
"ToolStrip"{
$oolbuttons = New-Object System.Windows.Forms.ToolStrip
$oolbuttons.imagescalingsize = new-object System.Drawing.Size([int]($ctscale * 16),[int]($ctscale * 16))
$oolbuttons.Name = $mControl.Name
$oolbuttons.Text = $mControl.Name
foreach ($mProperty in $mControl.Properties){
foreach ($split in $mProperty.Value.split(",")) {
if ($split -ne "-") {
$item = new-object System.Windows.Forms.ToolStripButton
$isplit = $split.split("|")
$item.name = $isplit[0]
if ($(substr $isplit[1] 0 2) -eq 'ht') {
$item.image = $(streamimage $isplit[1])
}
else {
$item.image = $(fileimage $isplit[1])
}
$item.text = $isplit[2]
$item.Add_Click({&toolstripitemclick $this})
}
else {
$item = new-object System.Windows.Forms.ToolStripSeparator
$item.name = $split
$item.text = $split
}
$oolbuttons.Items.Add($item) | Out-Null
}
}
# $b.Controls.Add($toolbuttons)
return $oolbuttons
}
default{
if ($ctrol -eq "MenuStrip"){
$global:designribbonctrl = New-Object System.Windows.Forms.$ctrol
$designribbonctrl.imagescalingsize = new-object System.Drawing.Size([int]($ctscale * 16),[int]($ctscale * 16))
$enutitle = new-object System.Windows.Forms.ToolStripMenuItem
$enutitle.Name = $mControl.Name
$enutitle.Text = $mControl.Name
$global:designribbonctrl.Items.add($enutitle) | Out-Null
foreach ($mProperty in $mControl.Properties){
foreach ($split in $mProperty.Value.split(",")) {
if ($split -ne "-") {
$innersplit = $split.split("|")
$split = $innersplit[0]
$item = new-object System.Windows.Forms.ToolStripMenuItem
if ($innersplit[2]) {
if ($(substr $innersplit[2] 0 2) -eq 'ht') {
$item.image = $(streamimage $innersplit[2])
}
else {
$item.image = $(fileimage $innersplit[2])
}
}
if ($innersplit[1]) {
$item.ShortCutKeys = $innersplit[1]
$item.ShowShortCutKeys = $true
}
$item.name = $split
$item.text = $split
$item.Add_Click({
&menuitemclick $this
})
}
else {
$item = new-object System.Windows.Forms.ToolStripSeparator
$item.name = $split
$item.text = $split
}
$enutitle.DropDownItems.Add($item) | Out-Null
}
}
return $global:designribbonctrl
}
else{
$mReturnControl = New-Object System.Windows.Forms.$ctrol
$mReturnControl.Name = $mControl.Name
$mSizeX=$null
$mSizeY=$null
foreach ($mProperty in $mControl.Properties){
switch ($mProperty.Name){
# 'Top' {$mReturnControl.Top=$mProperty.Value}
# 'Left' {$mReturnControl.Left=$mProperty.Value}
'Width' {$mSizeX=$mProperty.Value}
'Height' {$mSizeY=$mProperty.Value}
# 'Text' {$mReturnControl.Text=$mProperty.Value}
'AccessibilityObject' {}
'CanFocus' {}
'CanSelect' {}
'CompanyName' {}
'Container' {}
'ContainsFocus' {}
'Controls' {}
'Created' {}
'DataBindings' {}
'DeviceDpi' {}
'DisplayRectangle' {}
'Disposing' {}
'Focused' {}
'Handle' {}
'HasChildren' {}
'InvokeRequired' {}
'IsDisposed' {}
'IsHandleCreated' {}
'IsMirrored' {}
'LayoutEngine' {}
'PreferredHeight' {}
'PreferredSize' {}
'ProductName' {}
'ProductVersion' {}
'RecreatingHandle' {}
'Right' {}
'AccessibleName' {}
'AccessibleDefaultActionDescription' {}
'AccessibleDescription' {}
'AccessibleRole' {}
'ImeMode' {}
'IsAccessible' {}
'Location' {}
'Name' {}
'Parent' {}
'Region' {}
'Site' {}
'WindowTarget' {}
default{
$prop = $mProperty.Name
$val = $mProperty.Value
if ($mProperty.value -ne $null){
$mReturnControl.$prop = $val
}
}
}
}
$mReturnControl.Size = New-Object System.Drawing.Size($mSizeX,$mSizeY)
$mReturnControl.Top = $mReturnControl.Top * $ctscale
$mReturnControl.Left = $mReturnControl.Left * $ctscale
$mReturnControl.Height = $mReturnControl.Height * $ctscale
$mReturnControl.Width = $mReturnControl.Width * $ctscale
######THIS IS A GOOD SPOT TO BOUNCE BACK PROPERTIES INTO LIST#####
Return $mReturnControl
}
}
}
}
switch ($a) {
add {
switch ($c) {
default {
if ($c -eq $null) {
$Control = New-Object System.Windows.Forms.$b
}
else {
$Control = New-Object System.Windows.Forms.$c
}
if ($d -is [int]) {
$Control.Top = $d * $ctscale
$Control.Left = $e * $ctscale
$Control.Width = $f * $ctscale
$Control.Height = $g * $ctscale
$Control.Text = $h
}
if ($c -ne $null) {
$b.Controls.Add($Control)
}
return $Control
}
items {
$c.items.add($d)
}
statusstrip {
$statusstrip = new-object System.Windows.Forms.StatusStrip