Advertisement
Najeebsk

CREATE-SCRIPT.au3

Nov 3rd, 2022
2,445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 14.67 KB | None | 0 0
  1. #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
  2. #AutoIt3Wrapper_Res_SaveSource=y
  3. #AutoIt3Wrapper_Res_Language=1033
  4. #AutoIt3Wrapper_Res_requestedExecutionLevel=highestAvailable
  5. #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
  6. ; *** Start added by AutoIt3Wrapper ***
  7. #include <AutoItConstants.au3>
  8. #include <FileConstants.au3>
  9. #include <MsgBoxConstants.au3>
  10. #include <StringConstants.au3>
  11. ; *** End added by AutoIt3Wrapper ***
  12. #include <ButtonConstants.au3>
  13. #include <EditConstants.au3>
  14. #include <GUIConstantsEx.au3>
  15. #include <StaticConstants.au3>
  16. #include <WindowsConstants.au3>
  17. #include <GuiEdit.au3>
  18. #include <Constants.au3>
  19. #include <Array.au3>
  20. If Not FileExists ( @ScriptDir & "\CREATE-SCRIPT.ini" ) Then
  21.     If Not FileExists ( @ScriptDir & "\CREATE-SCRIPT" ) Then
  22.         DirCreate ( @ScriptDir & "\CREATE-SCRIPT" )
  23.     EndIf
  24.     $folder = FileSelectFolder ( "Select the folder where you want to store saved scripts.", @ScriptDir )
  25.     If $folder = "" Then
  26.         Exit
  27.     Else
  28.         IniWrite ( @ScriptDir & "\CREATE-SCRIPT.ini", "Settings", "Script folder", $folder )
  29.     EndIf
  30. EndIf
  31.  
  32. #Region ### START Koda GUI section ### Form=c:\users\whiggs\onedrive\always script\form\script creator.kxf
  33. $Form1 = GUICreate("NAJEEB-CREATE-SCRIPT", 410, 375, 192, 124, BitOR($GUI_SS_DEFAULT_GUI, $DS_SETFOREGROUND), BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
  34. $Label1 = GUICtrlCreateLabel("File name", 160, 0, 89, 29)
  35. GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
  36. $Input1 = GUICtrlCreateInput("", 38, 40, 337, 21)
  37. GUIStartGroup()
  38. $Radio1 = GUICtrlCreateRadio("Powershell", 38, 80, 75, 17)
  39. $Radio2 = GUICtrlCreateRadio("AutoIt", 118, 80, 57, 17)
  40. $Radio3 = GUICtrlCreateRadio("Visual Basic Script", 175, 80, 105, 17)
  41. $Radio4 = GUICtrlCreateRadio("Batch Script", 285, 80, 105, 17)
  42. GUIStartGroup()
  43. $Label2 = GUICtrlCreateLabel("Script Content", 140, 112, 128, 29)
  44. GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
  45. $Edit1 = GUICtrlCreateEdit("", 32, 152, 329, 169, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN, $WS_VSCROLL))
  46. $Button1 = GUICtrlCreateButton("Create file", 152, 328, 105, 33, $BS_NOTIFY)
  47. GUICtrlSetState(-1, $GUI_DISABLE)
  48. GUICtrlSetCursor(-1, 0)
  49. GUISetState(@SW_SHOW)
  50. #EndRegion ### END Koda GUI section ###
  51. $aRect = _GUICtrlEdit_GetRECT($Edit1)
  52. $aRect[0] += 10
  53. $aRect[1] += 10
  54. $aRect[2] -= 10
  55. $aRect[3] -= 10
  56. _GUICtrlEdit_SetRECT($Edit1, $aRect)
  57. While 1
  58.     If _GUICtrlEdit_GetTextLen($Input1) > 0 And _GUICtrlEdit_GetTextLen($Edit1) > 0 And BitAND(GUICtrlGetState($Button1), 128) Then
  59.         GUICtrlSetState($Button1, $GUI_ENABLE)
  60.     EndIf
  61.     If (_GUICtrlEdit_GetTextLen($Input1) = 0 Or _GUICtrlEdit_GetTextLen($Edit1) = 0) And BitAND(GUICtrlGetState($Button1), 64) Then
  62.         GUICtrlSetState($Button1, $GUI_DISABLE)
  63.     EndIf
  64.  
  65.     $nMsg = GUIGetMsg()
  66.     Switch $nMsg
  67.  
  68.         Case $GUI_EVENT_CLOSE
  69.             Exit
  70.  
  71.         Case $Input1
  72.             If StringRight(GUICtrlRead($Input1), 4) = ".ps1" Then
  73.                 GUICtrlSetState($Radio2, $GUI_UNCHECKED)
  74.                 GUICtrlSetState($Radio3, $GUI_UNCHECKED)
  75.                 GUICtrlSetState($Radio1, $GUI_ENABLE)
  76.                 GUICtrlSetState($Radio1, $GUI_CHECKED)
  77.                 GUICtrlSetState($Radio2, $GUI_DISABLE)
  78.                 GUICtrlSetState($Radio3, $GUI_DISABLE)
  79.             ElseIf StringRight(GUICtrlRead($Input1), 4) = ".au3" Then
  80.                 GUICtrlSetState($Radio1, $GUI_UNCHECKED)
  81.                 GUICtrlSetState($Radio3, $GUI_UNCHECKED)
  82.                 GUICtrlSetState($Radio2, $GUI_ENABLE)
  83.                 GUICtrlSetState($Radio2, $GUI_CHECKED)
  84.                 GUICtrlSetState($Radio1, $GUI_DISABLE)
  85.                 GUICtrlSetState($Radio3, $GUI_DISABLE)
  86.             ElseIf StringRight(GUICtrlRead($Input1), 4) = ".vbs" Then
  87.                 GUICtrlSetState($Radio1, $GUI_UNCHECKED)
  88.                 GUICtrlSetState($Radio2, $GUI_UNCHECKED)
  89.                 GUICtrlSetState($Radio3, $GUI_ENABLE)
  90.                 GUICtrlSetState($Radio3, $GUI_CHECKED)
  91.                 GUICtrlSetState($Radio1, $GUI_DISABLE)
  92.                 GUICtrlSetState($Radio2, $GUI_DISABLE)
  93.             ElseIf StringRight(GUICtrlRead($Input1), 4) = ".bat" Then
  94.                 GUICtrlSetState($Radio2, $GUI_UNCHECKED)
  95.                 GUICtrlSetState($Radio3, $GUI_UNCHECKED)
  96.                 GUICtrlSetState($Radio4, $GUI_ENABLE)
  97.                 GUICtrlSetState($Radio4, $GUI_CHECKED)
  98.                 GUICtrlSetState($Radio2, $GUI_DISABLE)
  99.                 GUICtrlSetState($Radio3, $GUI_DISABLE) 
  100.             Else
  101.                 If BitAND(GUICtrlGetState($Radio1), 128) Or BitAND(GUICtrlGetState($Radio2), 128) Or BitAND(GUICtrlGetState($Radio3), 128) Or BitAND(GUICtrlGetState($Radio4), 128) Then
  102.                     GUICtrlSetState($Radio1, $GUI_ENABLE)
  103.                     GUICtrlSetState($Radio1, $GUI_UNCHECKED)
  104.                     GUICtrlSetState($Radio2, $GUI_ENABLE)
  105.                     GUICtrlSetState($Radio2, $GUI_UNCHECKED)
  106.                     GUICtrlSetState($Radio3, $GUI_ENABLE)
  107.                     GUICtrlSetState($Radio3, $GUI_UNCHECKED)
  108.                     GUICtrlSetState($Radio4, $GUI_ENABLE)
  109.                     GUICtrlSetState($Radio4, $GUI_UNCHECKED)
  110.                 EndIf
  111.             EndIf
  112.  
  113.         Case $Edit1
  114.  
  115.         Case $Button1
  116.             If GUICtrlRead($Radio1) = 4 And GUICtrlRead($Radio2) = 4 And GUICtrlRead($Radio3) = 4 And GUICtrlRead($Radio4) = 4 Then
  117.                 If Not IsDeclared("sToolTipAnswer") Then Local $sToolTipAnswer
  118.                 $sToolTipAnswer = ToolTip("You need to select one of the script types item.", Default, Default, "Make a selection", 0, 0)
  119.                 Sleep(3000)
  120.                 ToolTip("")
  121.             Else
  122.  
  123.                 If GUICtrlRead($Radio1) = 1 Then
  124.                     If StringRight(GUICtrlRead($Input1), 4) = ".ps1" Then
  125.                         $file = IniRead ( @ScriptDir & "\CREATE-SCRIPT.ini", "Settings", "Script folder", "Error" ) & "\" & GUICtrlRead($Input1)
  126.                     Else
  127.                         $file = IniRead ( @ScriptDir & "\CREATE-SCRIPT.ini", "Settings", "Script folder", "Error" ) & "\" & GUICtrlRead($Input1) & ".ps1"
  128.                     EndIf
  129.  
  130.                 ElseIf GUICtrlRead($Radio2) = 1 Then
  131.                     If StringRight(GUICtrlRead($Input1), 4) = ".au3" Then
  132.                         $file = IniRead ( @ScriptDir & "\CREATE-SCRIPT.ini", "Settings", "Script folder", "Error" ) & "\" & GUICtrlRead($Input1)
  133.                     Else
  134.                         $file = IniRead ( @ScriptDir & "\CREATE-SCRIPT.ini", "Settings", "Script folder", "Error" ) & "\" & GUICtrlRead($Input1) & ".au3"
  135.                     EndIf
  136.                 ElseIf GUICtrlRead($Radio3) = 1 Then
  137.                     If StringRight(GUICtrlRead($Input1), 4) = ".vbs" Then
  138.                         $file = IniRead ( @ScriptDir & "\CREATE-SCRIPT.ini", "Settings", "Script folder", "Error" ) & "\" & GUICtrlRead($Input1)
  139.                     Else
  140.                         $file = IniRead ( @ScriptDir & "\CREATE-SCRIPT.ini", "Settings", "Script folder", "Error" ) & "\" & GUICtrlRead($Input1) & ".vbs"
  141.                     EndIf
  142.                 ElseIf GUICtrlRead($Radio4) = 1 Then
  143.                     If StringRight(GUICtrlRead($Input1), 4) = ".bat" Then
  144.                         $file = IniRead ( @ScriptDir & "\CREATE-SCRIPT.ini", "Settings", "Script folder", "Error" ) & "\" & GUICtrlRead($Input1)
  145.                     Else
  146.                         $file = IniRead ( @ScriptDir & "\CREATE-SCRIPT.ini", "Settings", "Script folder", "Error" ) & "\" & GUICtrlRead($Input1) & ".bat"
  147.                     EndIf
  148.                 Else
  149.                     SetError(3)
  150.                 EndIf
  151.                 If @error Then
  152.                     SetError(0)
  153.                 Else
  154.                     $hand = Null
  155.                     If FileExists($file) And Not filetextcompare(_GUICtrlEdit_GetText($Edit1), $file) Then
  156.                         ShellExecute($file, "", IniRead ( @ScriptDir & "\CREATE-SCRIPT.ini", "Settings", "Script folder", "Error" ), $SHEX_OPEN)
  157.                         #Region --- CodeWizard generated code Start ---
  158.  
  159.                         ;MsgBox features: Title=Yes, Text=Yes, Buttons=Yes, No, and Cancel, Icon=Warning
  160.                         If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
  161.                         $iMsgBoxAnswer = MsgBox($MB_YESNOCANCEL + $MB_ICONEXCLAMATION, "File Exists", 'The file already exists, but it appears the contents are different.  Would you like to replace the existing file?  Select "no" to rename.')
  162.                         Select
  163.                             Case $iMsgBoxAnswer = $IDYES
  164.                                 If StringRight($file, 4) = "au3" Then
  165.                                     $hand = FileOpen($file, $FO_OVERWRITE)
  166.                                 Else
  167.                                     $hand = FileOpen($file, 514)
  168.                                 EndIf
  169.  
  170.                                 FileWrite($hand, _GUICtrlEdit_GetText($Edit1))
  171.                                 FileClose($hand)
  172.                             Case $iMsgBoxAnswer = $IDNO
  173.                                 $b = 0
  174.                                 Do
  175.                                     $b += 1
  176.                                 Until Not FileExists(_GetFilenameDrive($file) & _GetFilenamePath($file) & _GetFilename($file) & "(" & $b & ")." & _GetFilenameExt($file))
  177.                                 If StringRight($file, 3) = "au3" Then
  178.                                     $hand = FileOpen(_GetFilenameDrive($file) & _GetFilenamePath($file) & _GetFilename($file) & "(" & $b & ")." & _GetFilenameExt($file), $FO_OVERWRITE)
  179.                                 Else
  180.                                     $hand = FileOpen(_GetFilenameDrive($file) & _GetFilenamePath($file) & _GetFilename($file) & "(" & $b & ")." & _GetFilenameExt($file), 514)
  181.                                 EndIf
  182.                                 FileWrite($hand, _GUICtrlEdit_GetText($Edit1))
  183.                                 FileClose($hand)
  184.  
  185.                             Case $iMsgBoxAnswer = $IDCANCEL
  186.  
  187.                         EndSelect
  188.                         #EndRegion --- CodeWizard generated code Start ---
  189.                     Else
  190.                         If StringRight($file, 3) = "au3" Then
  191.                             $hand = FileOpen($file, $FO_OVERWRITE)
  192.                         Else
  193.                             $hand = FileOpen($file, 514)
  194.                         EndIf
  195.                         FileWrite($hand, _GUICtrlEdit_GetText($Edit1))
  196.                         FileClose($hand)
  197.                     EndIf
  198.                     _GUICtrlEdit_SetText($Edit1, "")
  199.                     GUICtrlSetData($Input1, "")
  200.                 EndIf
  201.  
  202.             EndIf
  203.  
  204.     EndSwitch
  205. WEnd
  206.  
  207.  
  208. Func filetextcompare($text1, $two)
  209.     $same = True
  210.     $arr = StringSplit($text1, @CRLF, $STR_NOCOUNT)
  211.     $ext2 = _GetFilenameExt($two)
  212.     $arr2 = FileReadToArray($two)
  213.     $search = _ArraySearch($arr2, "; Script Start - Add your code below here")
  214.     If @error Then
  215.         SetError(0)
  216.     Else
  217.         _ArrayDelete($arr2, "0-" & $search)
  218.     EndIf
  219.  
  220.     $hol = ""
  221.     $hol2 = ""
  222.  
  223.     For $i = 0 To UBound($arr) - 1 Step 1
  224.         If StringIsSpace($arr[$i]) Then
  225.             $hol = $hol & $i & ";"
  226.             ContinueLoop
  227.         Else
  228.             $arr[$i] = StringStripWS($arr[$i], 3)
  229.             ContinueLoop
  230.         EndIf
  231.     Next
  232.     _ArrayDelete($arr, StringTrimRight($hol, 1))
  233.     For $i = 0 To UBound($arr2) - 1 Step 1
  234.         If StringIsSpace($arr2[$i]) Then
  235.             $hol2 = $hol2 & $i & ";"
  236.             ContinueLoop
  237.         Else
  238.             $arr2[$i] = StringStripWS($arr2[$i], 3)
  239.             ContinueLoop
  240.         EndIf
  241.     Next
  242.     _ArrayDelete($arr2, StringTrimRight($hol2, 1))
  243.  
  244.  
  245.     If UBound($arr) <> UBound($arr2) Then
  246.         $same = False
  247.     Else
  248.         $same2 = True
  249.         $where = 0
  250.         $val1 = ""
  251.         $val2 = ""
  252.         For $i = 0 To UBound($arr2) - 1 Step 1
  253.             If $arr[$i] <> $arr2[$i] Then
  254.                 $same2 = False
  255.                 $where = $i
  256.                 $val1 = $arr[$i]
  257.                 $val2 = $arr2[$i]
  258.                 ExitLoop
  259.             Else
  260.                 ContinueLoop
  261.             EndIf
  262.         Next
  263.         If $same2 Then
  264.             $same = True
  265.         Else
  266.             $same = False
  267.         EndIf
  268.     EndIf
  269.     Return $same
  270. EndFunc   ;==>filetextcompare
  271.  
  272.  
  273.  
  274.  
  275. Func _GetFilename($sFilePath)
  276.     Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
  277.     Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace($sFilePath, "\", "\\") & "'")
  278.     If IsObj($oColFiles) Then
  279.         For $oObjectFile In $oColFiles
  280.             Return $oObjectFile.FileName
  281.         Next
  282.     EndIf
  283.     Return SetError(1, 1, 0)
  284. EndFunc   ;==>_GetFilename
  285.  
  286. Func _GetFilenameExt($sFilePath)
  287.     Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
  288.     Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace($sFilePath, "\", "\\") & "'")
  289.     If IsObj($oColFiles) Then
  290.         For $oObjectFile In $oColFiles
  291.             Return $oObjectFile.Extension
  292.         Next
  293.     EndIf
  294.     Return SetError(1, 1, 0)
  295. EndFunc   ;==>_GetFilenameExt
  296.  
  297. Func _GetFilenameInt($sFilePath)
  298.     Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
  299.     Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace($sFilePath, "\", "\\") & "'")
  300.     If IsObj($oColFiles) Then
  301.         For $oObjectFile In $oColFiles
  302.             Return $oObjectFile.Name
  303.         Next
  304.     EndIf
  305.     Return SetError(1, 1, 0)
  306. EndFunc   ;==>_GetFilenameInt
  307.  
  308. Func _GetFilenameDrive($sFilePath)
  309.     Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
  310.     Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace($sFilePath, "\", "\\") & "'")
  311.     If IsObj($oColFiles) Then
  312.         For $oObjectFile In $oColFiles
  313.             Return StringUpper($oObjectFile.Drive)
  314.         Next
  315.     EndIf
  316.     Return SetError(1, 1, 0)
  317. EndFunc   ;==>_GetFilenameDrive
  318.  
  319. Func _GetFilenamePath($sFilePath)
  320.     Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
  321.     Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace($sFilePath, "\", "\\") & "'")
  322.     If IsObj($oColFiles) Then
  323.         For $oObjectFile In $oColFiles
  324.             Return $oObjectFile.Path
  325.         Next
  326.     EndIf
  327.     Return SetError(1, 1, 0)
  328. EndFunc   ;==>_GetFilenamePath
  329.  
  330.  
  331.  
  332.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement