Ganz ehrlich: Bitte nutze #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 damit kannst du shcon viele Fehler/Probleme vermeiden.
Es gibt keine Lokal Variablen im globalen Kontext und man deklariert keine Global Variablen in einer (lokalen) Funktion. Ich selber empfehle auch nicht mitten im Code eine Variable zu deklarieren (bei dir: Zeile 34), sondern diese immer an einem Ort (Global z.B. start im Script, bei Funktionen in den ersten Zeilen der Funktion), dann muss man diese später nicht suchen und hat es auf einen Blick und eine klare Strucktur.
Opt('MustDeclareVars', 1)
#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#include <GuiConstants.au3>
#include <FileConstants.au3>
#include <EditConstants.au3>
#include <MsgBoxConstants.au3>
; GUI
Global $Label, $GUI, $msg
; Drag&Drop
Global $dropFile_1, $dropFile_2
; pfx
Global $pfxFile, $pfxPassword, $PfxPath
$GUI = GuiCreate('Drag and Drop', 530, 120, @DesktopWidth / 2 - 192, @DesktopHeight / 2 - 235, -1, $WS_EX_ACCEPTFILES + $WS_EX_TOPMOST)
$Label = GUICtrlCreateLabel('Bitte ziehen Sie mit der Maus die erhaltene PFX-Datei in dieses Fenster und lassen es hier los. Danach geben Sie Ihr Passwot ein, welches Sie per Mail erhalten haben. Den Rest erledige ich für Sie.', 0, 0, 530, 120)
GUICtrlSetBkColor($Label, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetState($Label, $GUI_DROPACCEPTED)
GuiSetState()
While 1
$msg = GuiGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
GUIDelete()
ExitLoop
Case $msg = $GUI_EVENT_DROPPED
If @GUI_DropId = $dropFile_1 Then
GUICtrlSetData($dropFile_1, @GUI_DragFile)
ElseIf @GUI_DropId = $dropFile_2 Then
GUICtrlSetData($dropFile_2, @GUI_DragFile)
Else;If @GUI_DropId = $label Then
;MsgBox(262144, "Drop Result", @GUI_DragFile)
$PfxPath = @GUI_DragFile
;MsgBox(262144, 'Drop Result', $PfxPath)
$pfxPassword = Password()
if $pfxPassword = '' then
MsgBox(0, 'Fehler', 'Der Vorgang wurde abgebrochen.')
ContinueLoop
Endif
if not MakeCert($pfxPassword, $PfxPath) then MsgBox(0, 'Fehler', 'Fehler beim einlesen des Zertifikats.')
EndIf
EndSelect
WEnd
;~ Exit
Func MakeCert($pass, $file)
Local $cmd = 'certutil -f -p ' & $pass & ' -user -importpfx "' & $file & '"'
ConsoleWrite($cmd & @CRLF) ;nur zum Debugging per F5
Run(@ComSpec & ' /c ' & $cmd, '', @SW_HIDE) ;Debugging: /k und @SW_SHOW ; compiled: /c und @SW_HIDE
if @error <> 0 Then
Consolewrite('@error: ' & @error)
Return False
Else
Return True
EndIf
EndFunc
Func Password()
Local $Return
While @error <> 0
$Return = InputBox('Sicherheit', 'Geben Sie das Passwort für das Zertifikat ein.', '', ' M20')
If $Return = '' then
If MsgBox($MB_YESNO, 'Fehler', 'Es wurde keine Eingabe für das Passwort erkannt, soll abgebrochen werden?') = $IDYES then Return ''
Else
Return $Return
Endif
WEnd
EndFunc
Alles anzeigen