-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
1026 lines (820 loc) · 32.6 KB
/
__init__.py
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
'''
--Base Process--
import subprocess, os
with open('test.vbs', 'x') as f:
f.write('msgbox \"Hello\"')
CREATE_NO_WINDOW = 0x08000000
DETACHED_PROCESS = 0x00000008
subprocess.run('cscript test.vbs', creationflags=CREATE_NO_WINDOW)
print('True')
os.remove('test.vbs')
You can go a step farther by forcing the child to have no console at all:
DETACHED_PROCESS = 0x00000008
subprocess.call('taskkill /F /IM exename.exe', creationflags=DETACHED_PROCESS)
--Base Process--
'''
import subprocess as sub
import os
from pathlib import Path
import ast
import time
#print(os.path.abspath("main.py"))
#print(os.path.abspath("main.py").split("\\")[-1])
currentid = 0
class makefile:
filename = ""
def __init__(self, filename=None):
self.inputvar = False
self.runasadmin = False
filename2 = filename
global currentid
if filename == None: filename2 = 'file' if currentid == 0 else f'file{currentid}'
self.filename = filename2
self.save_copied = False
filename = self.filename
currentid += 1
if not os.path.exists(str(Path( __file__ ).absolute())[:-11]+"\\copied.txt"):
with open(f'{str(Path( __file__ ).absolute())[:-11]}\\copied.txt', 'w') as f:
f.write('temp')
try: #if the file not exists
with open(f'{str(Path( __file__ ).absolute())[:-11]}\\files\\{filename2}.vbs', 'x') as f:
pass #makes the file
except: #if the file already exists
try:
for f in os.listdir(f'{str(Path( __file__ ).absolute())[:-11]}\\files'):
os.remove(os.path.join(f'{str(Path( __file__ ).absolute())[:-11]}\\files', f)) #clears the directory
with open(f'{str(Path( __file__ ).absolute())[:-11]}\\files\\{filename2}.vbs', 'x') as f: #re-creates the file
pass
except:
os.mkdir(f'{str(Path( __file__ ).absolute())[:-11]}\\files')
with open(f'{str(Path( __file__ ).absolute())[:-11]}\\var.txt', "x"):
pass
with open(f'{str(Path(__file__).absolute())[:-11]}\\files\\{filename2}.vbs', 'x') as f: # re-creates the file
pass
with open(f'{str(Path( __file__ ).absolute())[:-11]}\\files\\{self.filename}.vbs', 'a') as f: #writes it into the .vbs file
f.write(f'all_vars = \"[\"\n')
def tts(self):
from .tts import tts
return tts(self)
def msgbox(self, text=None, title=None, icon="0", options="0", getoutput=True, variable=None): #make a msgbox
'''
:param text: The text in the msgbox
:param title: The title of the msgbox
:param icon: The icon. Can be gotten from itemattributes
:param options: The options the user has. Can be gotten from itemattributes
:param getoutput: If you want to get output from the msgbox.
:param variable: The variable from the Variable class
:return:
'''
if getoutput is True: self.inputvar = True
if text == None: text = "" #if the text, title is None
if title == None: title = ""
opts = ""
if options == None and icon != None:
opts += icon
if icon == None and options != None:
opts += options
if icon != None and options != None:
opts += options + "+" + icon
with open(f'{str(Path( __file__ ).absolute())[:-11]}\\files\\{self.filename}.vbs', 'a') as f: #writes it into the .vbs file
if variable is not None:
fstrstart = "\" & "
fstrend = " & \""
f.write(f"{variable[0] if not variable[1] else 'unused = '}msgbox(\"{text+fstrstart+variable[0]+fstrend if variable[1] else text}\",{opts},\"{title}\")\n")
elif getoutput:
f.write(f"txt = msgbox(\"{text}\",{opts},\"{title}\")\n"
f"all_vars = all_vars + \"\"\"\" & txt & \"\"\"\" & \",\"\n")
else:
f.write(f"msgbox(\"{text}\",{opts},\"{title}\")\n")
def system(self, cmd, showprompt=False, getouput=True, variable=None):
'''
:param cmd: The command to execute.
:param showprompt: If the command prompt should be shown.
:param getouput: If you want to get the output from the command.
:param variable: A variable from the Variable class. To set or user
'''
sprompt = ", 0, True" if not showprompt else ""
if getouput: self.inputvar = True
with open(f'{str(Path( __file__ ).absolute())[:-11]}\\files\\{self.filename}.vbs', 'a') as f:
if variable is not None:
f.write("Set oShell = CreateObject (\"WScript.Shell\")\n"
f"Set {variable[0] if not variable[1] else 'unused = '}oShell.Exec(\"cmd.exe /C {variable[0] if variable[1] else cmd}\")\n"
f"Do While {variable[0][:-3] if not variable[1] else 'unused'}.Status <> 1\n"
"WScript.Sleep 100\n"
"Loop\n"
f"{variable[0] if not variable[1] else 'unused = '}{variable[0][:-3] if not variable[1] else 'unused'}.StdOut.Readall()\n")
elif getouput:
f.write("Set oShell = CreateObject (\"WScript.Shell\")\n"
f"Set out = oShell.Exec(\"cmd.exe /C {cmd}\")\n"
f"all = out.StdOut.ReadAll\n"
f"all_vars = all_vars + \"\"\"\"\"\"\"\" & all & \"\"\"\"\"\"\"\" & \",\"\n"
)
else:
f.write("Set oShell = CreateObject (\"WScript.Shell\")\n"
f"oShell.Run \"cmd.exe /C {cmd}\" {sprompt}\n")
def execute(self, item):
'''
:param item: Item to execute.
:returns Same as system. But for opening things.
'''
with open(f'{str(Path( __file__ ).absolute())[:-11]}\\files\\{self.filename}.vbs', 'a') as f:
f.write("Set oShell = CreateObject (\"WScript.Shell\")\n"
f"oShell.Run \"{item}\"\n"
)
def Variable(self, name):
from .variable import Variable
return Variable(name, self)
def createshortcut(self, filepath, lnkpath, icon, shrtname="shortcut"):
'''
:param filepath: The filepath of the item for the shortcut.
:param lnkpath: Path the shortcut will be made in
:param icon: The icon of the shortcut needs to be int or a .ico
:param shrtname: Name of the shortcut.
'''
if isinstance(icon, int):
icon = "%SystemRoot%\System32\SHELL32.dll," + str(icon)
with open(f'{str(Path(__file__).absolute())[:-11]}\\files\\{self.filename}.vbs', 'a') as f:
f.write("Set obj = createObject(\"wscript.shell\")\n"
f"Set shrt = obj.CreateShortcut(\"{os.path.abspath(lnkpath+ shrtname + '.lnk')}\")\n"
f"shrt.TargetPath = \"{os.path.abspath(filepath)}\"\n"
f"shrt.IconLocation = \"{icon}\"\n"
"shrt.Save\n"
)
with open(f'{str(Path( __file__ ).absolute())[:-11]}\\files\\{self.filename}.vbs', 'a') as f:
f.write("Set obj = createObject(\"wscript.shell\")\n"
f"Set shrt = obj.CreateShortcut(\"{os.path.abspath(lnkpath)}\")\n"
f"shrt.TargetPath = {filepath}\n"
f"shrt.IconLocation = \"{os.path.abspath(icon)}\"\n"
"shrt.Save\n"
)
def input(self, text="", title="", getoutput=True, variable=None): #pretty much the same as msgbox
'''
:param text: The text to appear in the input box.
:param title: The title of the input box.
:param getoutput: If you want to get output from the answer from the input box.
:param variable: To set or use a variable from the Variable class
'''
if getoutput is True: self.inputvar = True
with open(f'{str(Path( __file__ ).absolute())[:-11]}\\files\\{self.filename}.vbs', 'a') as f:
if variable is not None:
fstrstart = "\" & "
fstrend = " & \""
f.write(f"{variable[0] if not variable[1] else 'unused = '}Inputbox(\"{text+fstrstart+variable[0]+fstrend if variable[1] else text}\",\"{title}\")\n")
elif not getoutput:
f.write(f'Inputbox \"{text}\",\"{title}\"\n')
elif getoutput:
f.write(f'txt=Inputbox(\"{text}\",\"{title}\")\n'
f'all_vars = all_vars + \"\"\"\" & txt & \"\"\"\" & \",\"\n')
def presskeys(self, keys):
'''
:param keys: Keys to press
'''
with open(f'{str(Path(__file__).absolute())[:-11]}\\files\\{self.filename}.vbs', 'a') as f:
f.write(
f"set oShell = Createobject(\"wscript.shell\")\n"
f"oShell.sendkeys(\"{keys}\")\n"
)
def sleep(self, amount):
'''
:param amount: Time to sleep in ms
'''
amount *= 1000
with open(f'{str(Path(__file__).absolute())[:-11]}\\files\\{self.filename}.vbs', 'a') as f:
f.write(
f"set oShell = Createobject(\"wscript.shell\")\n"
f"wscript.sleep {amount}\n"
)
def presskey(self, key=None):
'''
:param key: The special key to press
'''
if key == None:
print(
"List of keys:\n"
"""
Key Code
Backspace: BACKSPACE, BKSP or: BS
Break: BREAK
Caps Lock: CAPSLOCK
Delete DELETE or: DEL
Down Arrow: DOWN
End: END
Enter: ENTER or ~
Escape: ESC
Help: HELP
Home: HOME
Insert: INSERT or INS
Left Arrow: LEFT
Num Lock: NUMLOCK
Page Down: PGDN
Page Up: PGUP
Print Screen: PRTSC
Right Arrow: RIGHT
Scroll Lock: SCROLLLOCK
Tab: TAB
Up Arrow: UP
F1: F1
F2: F2
F3: F3
F4: F4
F5: F5
F6: F6
F7: F7
F8: F8
F9: F9
F10: F10
F11: F11
F12: F12
F13: F13
F14: F14
F15: F15
F16: F16
"""
)
return
key_to_send1 = "{"
key_to_send2 = "}"
with open(f'{str(Path(__file__).absolute())[:-11]}\\files\\{self.filename}.vbs', 'a') as f:
f.write(
f"set oShell = Createobject(\"wscript.shell\")\n"
f"oShell.sendkeys(\"{key_to_send1}{key}{key_to_send2}\")\n"
)
def loop(self, *args):
'''
:param *args: The amount of times to loop.
'''
def inner(func):
with open(f'{str(Path(__file__).absolute())[:-11]}\\files\\{self.filename}.vbs', 'a') as f:
if len(args) >= 1:
f.write(
"ffffffffffffggg = 1\n"
f"do While ffffffffffffggg < {int(args[0])}\n"
"ffffffffffffggg = ffffffffffffggg + 1\n"
)
else:
f.write("do\n")
func()
with open(f'{str(Path(__file__).absolute())[:-11]}\\files\\{self.filename}.vbs', 'a') as f:
f.write(
f"loop\n"
)
return inner
def runas(self, file=None):
'''
:param file: The file to run must be a python file.
'''
if not file.endswith('.py'):
raise Exception("You can at the minute only use .py files.")
with open(f'{str(Path(__file__).absolute())[:-11]}\\files\\{self.filename}.vbs', 'a') as f:
if file is None:
f.write(
"Sub RunAsAdmin()\n"
"If WScript.Arguments.Named.Exists(\"RunAsAdmin\") Then Exit Sub\n"
"CreateObject(\"Shell.Application\").ShellExecute _\n"
"\"WScript.exe\", \"\"\"\" & WScript.ScriptFullName & \"\"\" /RunAsAdmin\",\"\",\"runas\", 1\n"
"WScript.Quit()\n"
"End Sub\n"
"RunAsAdmin()\n")
return
else:
f.write(
"Set shell = CreateObject(\"Shell.Application\")"
f"shell.ShellExecute \"python.exe\", \"{os.path.abspath(file)}\",,\"runas\", 1"
)
self.runasadmin = True
def copyfile(self, oldpath, newpath):
'''
:param oldpath: The path of the copied file
:param newpath: The new path of the copied file
'''
with open(f'{str(Path(__file__).absolute())[:-11]}\\files\\{self.filename}.vbs', 'a') as f:
f.write(
f"Set fso = CreateObject(\"Scripting.FileSystemObject\")\n"
f"fso.CopyFile \"{os.path.abspath(oldpath)}\" , \"{os.path.abspath(newpath)}\\\"\n"
)
def copyfolder(self, oldpath, newpath):
with open(f'{str(Path(__file__).absolute())[:-11]}\\files\\{self.filename}.vbs', 'a') as f:
f.write(
f"Set fso = CreateObject(\"Scripting.FileSystemObject\")\n"
f"fso.CopyFolder \"{os.path.abspath(oldpath)}\", \"{os.path.abspath(newpath)}\\\"\n"
)
def movefile(self, oldpath, newpath):
'''
:param oldpath: The path of the file
:param newpath: The new path of the moved file.
'''
with open(f'{str(Path(__file__).absolute())[:-11]}\\files\\{self.filename}.vbs', 'a') as f:
f.write(
f"Set fso = CreateObject(\"Scripting.FileSystemObject\")\n"
f"fso.MoveFile \"{os.path.abspath(oldpath)}\" , \"{os.path.abspath(newpath)}\\\"\n"
)
def movefolder(self, oldpath, newpath):
'''
:param oldpath: Path of the folder to move.
:param newpath: The new path of the moved folder
'''
with open(f'{str(Path(__file__).absolute())[:-11]}\\files\\{self.filename}.vbs', 'a') as f:
f.write(
f"Set fso = CreateObject(\"Scripting.FileSystemObject\")\n"
f"fso.MoveFolder \"{os.path.abspath(oldpath)}\", \"{os.path.abspath(newpath)}\\\"\n"
)
def createfolder(self, path):
'''
:param path: Path of the folder to create.
'''
with open(f'{str(Path(__file__).absolute())[:-11]}\\files\\{self.filename}.vbs', 'a') as f:
f.write(
f"Set fso = CreateObject(\"Scripting.FileSystemObject\")\n"
f"fso.CreateFolder \"{path}\"\n"
)
def deletefolder(self, path):
'''
:param path: Path of the folder to delete.
'''
with open(f'{str(Path(__file__).absolute())[:-11]}\\files\\{self.filename}.vbs', 'a') as f:
f.write(
f"Set fso = CreateObject(\"Scripting.FileSystemObject\")\n"
f"fso.DeleteFolder \"{os.path.abspath(path)}\"\n"
)
def copy(self, item):
'''
:param item: Item to copy to clipboard.
'''
with open(f'{str(Path(__file__).absolute())[:-11]}\\files\\{self.filename}.vbs', 'a') as f:
f.write(
"Set shell = CreateObject(\"wscript.shell\")\n"
"Set clip = shell.Exec(\"clip\")\n"
f"clip.Stdin.Write \"{item}\"\n"
"clip.Stdin.Close()\n"
)
def getcopied(self, getouput=True, variable=None):
'''
:param getouput: If you want to see output when you run it yes or no.
:param variable: For the variable in the Variable class
'''
with open(f'{str(Path(__file__).absolute())[:-11]}\\files\\{self.filename}.vbs', 'a') as f:
if variable is not None:
f.write(
"Set html = CreateObject(\"htmlfile\")\n"
f"{variable[0] if not variable[1] else 'unused = '} = html.ParentWindow.ClipboardData.GetData(\"Text\")\n"
)
elif getouput:
self.save_copied = True
f.write(
"Set html = CreateObject(\"htmlfile\")\n"
"copied = html.ParentWindow.ClipboardData.GetData(\"Text\")\n"
)
else:
f.write(
"Set html = CreateObject(\"htmlfile\")\n"
"html.ParentWindow.ClipboardData.GetData \"Text\" \n")
def createhotkey(self, execute, hotkey, custom_name=currentid):
'''
:param execute: The path of the item of the file to run
:param hotkey: The hotkey to press to execute the item.
:param custom_name: The custom name of the hotkey. Used for multiple hotkeys.
'''
with open(f'{str(Path(__file__).absolute())[:-11]}\\files\\{self.filename}.vbs', 'a') as f:
f.write(
f"""
set obj = WScript.CreateObject(\"WScript.Shell\")
Desktop = obj.specialfolders(\"Desktop\")
set shortcut = obj.CreateShortcut(Desktop & \"\\vbspythonhotkey_{custom_name}.lnk\")
shortcut.TargetPath = \"{os.path.abspath(execute)}\"
shortcut.Hotkey = \"{hotkey}\"
shortcut.IconLocation = "notepad.exe, 0"
shortcut.WorkingDirectory = \"C:\\\"
shortcut.Save
Set fso = CreateObject(\"Scripting.FileSystemObject\")
fso.GetFile(Desktop & \"\\vbspythonhotkey_{custom_name}.lnk\").Attributes = 34
"""
)
def specialfolder(self, folder=None, getoutput=True, variable=None):
'''
:param folder: The special folder.
:param getoutput: If you want to get output from the function.
:param variable: The variable for the Variable class.
'''
if folder == None:
print(
"""
All special folders are:
This function will give their location on this pc.
AllUsersDesktop
AllUsersStartMenu
AllUsersPrograms
AllUsersStartup
Desktop
Favorites
Fonts
MyDocuments
NetHood
PrintHood
Programs
Recent
SendTo
StartMenu
Startup
Templates
"""
)
return
with open(f'{str(Path(__file__).absolute())[:-11]}\\files\\{self.filename}.vbs', 'a') as f:
if variable is not None:
f.write("Set obj = createObject(\"wscript.shell\")\n"
f"{variable[0] if not variable[1] else 'unused = '}obj.specialfolders(\"{variable[0] if variable[1] else folder}\")\n")
return
f.write(
"Set obj = createObject(\"wscript.shell\")\n"
f"txt = obj.specialfolders(\"{folder}\")\n"
)
if getoutput:
f.write(
f'all_vars = all_vars + \"\"\"\" & txt & \"\"\"\" & \",\"\n'
)
self.inputvar = True
def deletefile(self, path):
'''
:param path: Path to the file to delete.
'''
with open(f'{str(Path(__file__).absolute())[:-11]}\\files\\{self.filename}.vbs', 'a') as f:
f.write(
f"Set fso = CreateObject(\"Scripting.FileSystemObject\")\n"
f"fso.DeleteFile \"{os.path.abspath(path)}\"\n"
)
def filelocation(self):
return f"{str(Path(__file__).absolute())[:-11]}files\\{self.filename}.vbs"
def filecontent(self):
with open(f"{str(Path(__file__).absolute())[:-11]}files\\{self.filename}.vbs") as f:
return f.read()
def code(self):
with open(f'{str(Path(__file__).absolute())[:-11]}\\files\\{self.filename}.vbs', 'r') as f:
return f.read()
def run(self, deletefile=True, showprompt=False): #runs the file
if self.inputvar:
with open(f'{str(Path(__file__).absolute())[:-11]}\\files\\{self.filename}.vbs', 'a') as f: # writes it into the .vbs file
f.write(
'all_vars = all_vars + \"]\"\n'
'a = Left(wscript.scriptfullname, Len(wscript.scriptfullname) - '
'Len(wscript.scriptname) - 6)\n'
'Set fleobj = CreateObject(\"Scripting.FileSystemObject\")'
'.OpenTextFile(a & \"var.txt\",2)\n'
'fleobj.WriteLine(all_vars)\n'
'fleobj.close\n'
f'Set fleobj = Nothing\n')
if self.save_copied:
with open(f'{str(Path(__file__).absolute())[:-11]}\\files\\{self.filename}.vbs', 'a') as f: # writes it into the .vbs file
f.write(
'a = Left(wscript.scriptfullname, Len(wscript.scriptfullname) - '
'Len(wscript.scriptname) - 6)\n'
'Set fleobj = CreateObject(\"Scripting.FileSystemObject\")'
'.OpenTextFile(a & \"copied.txt\",2)\n'
'fleobj.WriteLine(copied)\n'
'fleobj.close\n'
)
if self.runasadmin:
sub.run(f'cscript {str(Path(__file__).absolute())[:-11]}\\files\\{self.filename}.vbs', creationflags=0x08000000)
if deletefile:
time.sleep(0.2)
os.remove(f'{str(Path(__file__).absolute())[:-11]}\\files\\{self.filename}.vbs')
return
if showprompt:
sub.run(f'cscript {str(Path( __file__ ).absolute())[:-11]}\\files\\{self.filename}.vbs')
if deletefile:
os.remove(f'{str(Path( __file__ ).absolute())[:-11]}\\files\\{self.filename}.vbs')
elif not showprompt:
sub.run(f'cscript {str(Path( __file__ ).absolute())[:-11]}\\files\\{self.filename}.vbs', creationflags=0x08000000) #turns off the prompt
if deletefile:
os.remove(f'{str(Path( __file__ ).absolute())[:-11]}\\files\\{self.filename}.vbs')
else:
print('Something went wrong')
if self.inputvar:
with open(f'{str(Path( __file__ ).absolute())[:-11]}\\var.txt', 'r') as r:
self.inpvar = r.read()
if self.save_copied:
with open(f'{str(Path(__file__).absolute())[:-11]}\\copied.txt', 'r') as r:
copied = r.read()
try:
out = ast.literal_eval(self.inpvar)
if self.save_copied:
out.append(copied)
return out #returns the inpvar given
except:
self.inpvar = self.inpvar.replace('\\', "/")
out = ast.literal_eval(self.inpvar)
if self.save_copied:
out.append(copied)
return out # returns the inpvar given
elif self.save_copied:
with open(f'{str(Path(__file__).absolute())[:-11]}\\copied.txt', 'r') as r:
copied = r.read()
return [copied]
return
def delete(self, file=None, allfiles=False):
if file == None:
file = self.filename
if allfiles:
for i in os.listdir(f'{str(Path( __file__ ).absolute())[:-11]}\\files'):
os.remove(os.path.join(f'{str(Path( __file__ ).absolute())[:-11]}\\files', i))
if not allfiles:
os.remove(f'{str(Path( __file__ ).absolute())[:-11]}\\files\\{file}.vbs')
class help:
def __init__(self):
sub.getoutput("explorer https://github.com/J3ldo/vbspython/blob/main/README.md#example-code")
'''class makefile:
def __init__(self):
pass
def help(self):
print("Makes the file.\n\n"
"Fields: \n"
"filename (Indicates the filename)\n\n"
"Example: \n"
"file = vbspython.makefile()\n"
"file.run() (runs the file)")
def msgbox(self):
print("Will show a message box/prompt\n\n"
"Fields: \n"
"title (Shows the title of the message box)\n"
"text (The text displayed in the box)\n\n"
"Example: \n"
"file = vbspython.makefile()\n"
"file.msgbox(title=\"Im the title!\", text=\"Im the text\")")
def system(self):
print("Runs a command via the command prompt\n\n"
"Fields: \n"
"cmd (the command that you want to execute)\n"
"getoutput (If you want to get output from to commmand)\n\n"
"Example:"
"file = vbspython.makefile()\n"
"file.system(cmd=\"whoami\", getoutput=True)\n"
"output = file.run()\n"
"print(output)")
def input(self):
print(
"Get an input from a user\n\n"
"Fields: \n"
"text (text of the input box)\n"
"title (the title of the input box)\n"
"getoutput (gets the output from the input)\n\n"
"Example: \n"
"file = vbspython.makefile()\n"
"file.input(title=\"Title!\", text=\"Text\", getoutput=True)"
"varfrominput = file.run()\n"
"print(varfrominput)"
)
def presskeys(self):
print(
"Simulates key presses.\n\n"
"Fields: \n"
"keys (The keys you want to press)\n\n"
"Example: \n"
"file = vbspython.makefile()\n"
"file.presskeys(\"Hello!\")\n"
"file.run()"
)
def presskey(self):
print(
"Presses a special key like enter or backspace. Leave empty for a list of them\n\n"
"Fields: \n"
"key (The key you want to press)\n\n"
"Example:"
"file = vbspython.makefile()\n"
"file.presskey(\"enter\")\n"
"file.run()"
)
def sleep(self):
print(
"Makes the program sleep ONLY THE VBS FILE\n\n"
"Fields: \n"
"amount (How long you want to let it sleep in seconds)\n\n"
"Example: \n"
"file = vbspython.makefile()\n"
"file.sleep(10)"
"file.run()"
)
def loop(self):
print(
"Makes a part of the file loop\n\n"
"Fields: \n"
"none\n\n"
"Example: \n"
"file = vbspython.makefile()\n"
"@file.loop\n"
"def itemtoloop():"
"\tfile.sendkeys(\"Hello!\")\n"
"file.run()"
)
def run(self):
print(
"Runs the file\n\n"
"Fields: \n"
"deletefile (if you want to delete the file after running)\n"
"showprompt (shows everything that you normallyy couldnt see)\n\n"
"Example:\n"
"file = vbspython.makefile()\n"
"file.run()"
)
def delete(self):
print(
"Deletes a file of choice\n\n"
"Fields: \n"
"file (The file you want to delete. If left empty will delete the current file your using.)\n"
"allfiles (Will delete all files in the files directory)\n\n"
"Example:\n"
"file = vbspython.makefile(filename=\"filename\")\n"
"file.run(deletefile=False)\n"
"file.run(deletefile=False)\n"
"file.delete(file=\"filename\", allfiles=True)"
)
def runfile(self):
print("Runs a file without the need for a makefile\n\n"
"Fields:\n"
"file (The file you want to run (Say file if you dont know the file name)\n"
"showprompt (If you want to show the prompt)\n\n"
"Example:\n"
"file = vbspython.makefile(filename=\"myfile\")\n"
"vbspython.runfile(file=\"myfile\", showprompt=True)"
"")'''
def runfile(file:str, showprompt:bool=False):
if file.endswith(".vbs"):
pass
else:
file += ".vbs"
if showprompt:
sub.run(f'cscript {str(Path(__file__).absolute())[:-11]}\\files\\{file}')
elif not showprompt:
sub.run(f'cscript {str(Path(__file__).absolute())[:-11]}\\files\\{file}',
creationflags=0x08000000) # turns off the prompt
'''
Here will the instant use items go.
'''
def presskey(key=None):
file = makefile()
if key == None:
file.presskey()
return
file.presskey(key)
file.run()
def msgbox(text=None, title=None, icon=None, options=None, getoutput=True):
file = makefile()
file.msgbox(text=text, title=title, icon=icon, options=options, getoutput=getoutput)
if getoutput:
return file.run()[0]
file.run()
def input(text=None, title=None, getoutput=True):
file = makefile()
if text == None:
text = ""
if title == None:
title = ""
file.input(text=text, title=title, getoutput=getoutput)
if getoutput:
return file.run()[0]
file.run()
def system(cmd, showprompt=False):
file = makefile()
if showprompt:
file.system(cmd, showprompt=True, getouput=True)
if not showprompt:
file.system(cmd, getouput=True)
return file.run()[0]
def presskeys(keys):
file = makefile()
file.presskeys(keys)
file.run()
def sleep(amount:int):
file = makefile()
file.sleep(amount)
file.run()
def createfolder(path):
file = makefile()
file.createfolder(path)
file.run()
def copyfolder(oldpath, newpath):
file = makefile()
file.copyfolder(oldpath, newpath)
file.run()
def copyfile(oldpath, newpath):
file = makefile()
file.copyfile(oldpath, newpath)
file.run()
def movefolder(oldpath, newpath):
file = makefile()
file.movefolder(oldpath, newpath)
file.run()
def movefile(oldpath, newpath):
file = makefile()
file.movefile(oldpath, newpath)
file.run()
def deletefolder(path):
file = makefile()
file.deletefolder(path)
file.run()
def deletefile(path):
file = makefile()
file.deletefile(path)
file.run()
def execute(item):
file = makefile()
file.execute(item)
file.run()
def speak(text):
file = makefile()
file.tts().speak(text)
file.run()
def say(text):
file = makefile()
file.tts().say(text)
file.run()
def copy(item):
file = makefile()
file.copy(item)
file.run()
def getcopied():
file = makefile()
file.getcopied()
return file.run()[0]
def runas(file):
file = makefile()
file.runas(file)
file.run()
def specialfolder(folder=None, getoutput=True):
file = makefile()
file.specialfolder(folder, getoutput)
if getoutput:
if folder != None:
return file.run()[0]
file.run()
def createshortcut(filepath, lnkpath, icon, shrtname="shortcut"):
file = makefile()
file.createshortcut(filepath, lnkpath, icon, shrtname)
file.run(deletefile=False)
def createhotkey(execute, hotkey, custom_name=currentid + 1):
file = makefile()
file.createhotkey(execute, hotkey, custom_name)
file.run()
def docs():
sub.getoutput("explorer \"https://github.com/J3ldo/vbspython/blob/main/README.md\"")
class itemattributes:
class tts:
@staticmethod
def voice_1():
return "0"
@staticmethod
def voice_2():
return "1"
class msgbox:
class returns:
@staticmethod
def ok():
return "1"
@staticmethod
def cancel():
return "2"
@staticmethod
def abort():
return "3"
@staticmethod
def retry():
return "4"
@staticmethod
def ignore():
return "5"
@staticmethod
def yes():
return "6"
@staticmethod
def no():
return "7"
class options:
@staticmethod
def ok():
return "0"
@staticmethod
def ok_cancel():
return "1"
@staticmethod
def retry_abort_ignore():
return "2"
@staticmethod
def yes_no_cancel():
return "3"