Jump to content

Running script vs compiled exe


Recommended Posts

Ok, so this is a question that has been on my mind for a while, and only recently have I had I good example to demonstrate what I mean.  I was working on updating my Cmail GUI front-end script, and I have run into an issue where, when the script is run (using "GO" in the Scite tools menu), the GUI recognizes and executes the code I have designated for the drop event (for when a file is dragged and dropped), but will not recognize the event (and therefore not execute the code) when the application is run from the compiled exe.  As for my question, what is the difference between running a script directly vs running the exe compiled from it, as I have run into several instances where scripts can only be run as the script and do not work if run as the compiled exe.  Thanks in advance.  Below is code:

**Edit: Ok.  So I figured out that it was because I was compiling it with the "require Administrator" execution level.  But why would that make such a difference?

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_SaveSource=y
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; *** Start added by AutoIt3Wrapper ***
#include <ListBoxConstants.au3>
; *** End added by AutoIt3Wrapper ***
; *** Start added by AutoIt3Wrapper ***
#include <AutoItConstants.au3>
; *** End added by AutoIt3Wrapper ***
; *** Start added by AutoIt3Wrapper ***
#include <MsgBoxConstants.au3>
; *** End added by AutoIt3Wrapper ***
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.15.0 (Beta)
 Author:        William Higgs

 Script Function:
    Provides a graphical user interface for the command line utility "Cmail", which lets one send emails via command line.  I wrote this
    specificially to reduced the ammount of time needed to send messages to potential employers.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <GuiEdit.au3>
#include <GuiListBox.au3>
#include <Constants.au3>
#include <Word.au3>
#include <Array.au3>
OnAutoItExitRegister ( "_Exit" )
Global $trans = False
;_WordErrorHandlerRegister()
If Not FileExists ( @MyDocumentsDir & "\settings.ini" ) Then
If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer
$sInputBoxAnswer = InputBox("Name","What is the name wou want the recipients of your messages to see in regards to the sender? (Should be your name)",""," ")
If @error = 1 Then
    Exit
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "Name", $sInputBoxAnswer )
EndIf
If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer
$sInputBoxAnswer = InputBox("Email address","What is your email address or the email address of the account sending the mail?",""," ")
If @error = 1 Then
    Exit
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "Email Address", $sInputBoxAnswer )
EndIf
If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer
$sInputBoxAnswer = InputBox("SMTP server","What is the address of the SMTP server for your outgoing mail?",""," ")
If @error = 1 Then
    Exit
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "SMTP Server", $sInputBoxAnswer )
EndIf
$sInputBoxAnswer = InputBox("Email Port","What is the port used by smtp server?",""," ")
If @error = 1 Then
    Exit
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "Port", $sInputBoxAnswer )
EndIf
$sInputBoxAnswer = InputBox("Email Username","What is the username used to login to your email?",""," ")
If @error = 1 Then
    Exit
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "User name", $sInputBoxAnswer )
EndIf
$sInputBoxAnswer = InputBox("Email Password","What is the password used to login to your email?",""," ")
If @error = 1 Then
    Exit
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "Password", $sInputBoxAnswer )
EndIf
If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox($MB_YESNO + $MB_ICONQUESTION + $MB_SYSTEMMODAL,"Proxy server?","Does your network utilize a proxy server?")
If $iMsgBoxAnswer = $IDYES  Then
    $sInputBoxAnswer = InputBox("Proxy server","What is the proxy server address?",""," ")
If @error = 1 Then
    Exit
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "Proxy", $sInputBoxAnswer )
EndIf
Else
    IniWrite ( @MyDocumentsDir & "\settings.ini", "Config", "Proxy", "False" )
EndIf
EndIf

Global $oWordApp = _Word_Create(False)
Global $oDoc = _Word_DocAdd ( $oWordApp )
Global $oRange = $oDoc.Range
Global $oSpellCollection, $oAlternateWords
HotKeySet ( "^d", "stylish" )
Global $attach = ""
Global $array
$Form2 = GUICreate("Form2", 406, 514, 320, 200, -1, BitOR($WS_EX_ACCEPTFILES,$WS_EX_WINDOWEDGE))
$handle = WinGetHandle ( $Form2 )
$MenuItem1 = GUICtrlCreateMenu("configure")
$MenuItem2 = GUICtrlCreateMenuItem("Attachments", $MenuItem1)
$Label1 = GUICtrlCreateLabel("Email Address", 128, 0, 130, 29)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
$Input1 = GUICtrlCreateInput("", 70, 32, 273, 21)
$Label2 = GUICtrlCreateLabel("Attachments (Can drag and drop below)", 27, 64, 351, 29)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
$Input2 = GUICtrlCreateInput("", 32, 104, 337, 21)
GUICtrlSetState ( -1, $GUI_DROPACCEPTED )
$Button9 = GUICtrlCreateButton("Add/Browse", 158, 136, 89, 33, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
$Label4 = GUICtrlCreateLabel("Subject", 160, 184, 157, 29)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
$Input3 = GUICtrlCreateInput("", 32, 216, 337, 21)
$Label3 = GUICtrlCreateLabel("Message", 160, 240, 172, 29)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
$Edit1 = GUICtrlCreateEdit("", 32, 272, 345, 153, BitOR($ES_WANTRETURN, $WS_VSCROLL))
$Button1 = GUICtrlCreateButton("Send", 30, 440, 113, 33, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
$Button2 = GUICtrlCreateButton("Save As Template", 160, 440, 105, 33, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
$Button6 = GUICtrlCreateButton ( "Use Template", 282, 440, 113, 33, $BS_NOTIFY )
GUICtrlSetCursor (-1, 0)
$Form1 = GUICreate("Spell check", 345, 251, 302, 218)
Global $handle2 = WinGetHandle ( $Form1 )
$ListBox1 = GUICtrlCreateList("", 8, 8, 137, 149, $LBS_NOTIFY + $WS_VSCROLL )
$ListBox2 = GUICtrlCreateList("", 200, 8, 137, 149, $LBS_NOTIFY + $WS_VSCROLL )
$Button3 = GUICtrlCreateButton("Send", 32, 201, 75, 25, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
$Button4 = GUICtrlCreateButton("&Cancel", 240, 201, 75, 25, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
$Button5 = GUICtrlCreateButton("Correct spelling", 128, 201, 83, 25, $BS_NOTIFY)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetCursor (-1, 0)
$Form3 = GUICreate("Form3", 286, 283, 192, 124)
$Label5 = GUICtrlCreateLabel("Attachments", 86, 8, 113, 29)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$List1 = GUICtrlCreateList("", 16, 40, 249, 188, BitOR($GUI_SS_DEFAULT_LIST,$LBS_HASSTRINGS))
$Button7 = GUICtrlCreateButton("Delete", 40, 240, 81, 33, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
$Button8 = GUICtrlCreateButton("Back", 160, 240, 81, 33, $BS_NOTIFY)
GUICtrlSetCursor (-1, 0)
$Form4 = GUICreate("Form4", 242, 95, 216, 123)
$Combo1 = GUICtrlCreateCombo("", 40, 56, 169, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
$Label6 = GUICtrlCreateLabel("Templates", 72, 8, 96, 29)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
GUISetState(@SW_DISABLE, $Form4)
GUISetState( @SW_DISABLE, $Form3 )
GUISetState( @SW_DISABLE, $Form1 )
GUISetState( @SW_SHOW, $Form2 )
$aRect = _GUICtrlEdit_GetRECT($Edit1)
$aRect[0] += 10
$aRect[1] += 10
$aRect[2] -= 10
$aRect[3] -= 10
_GUICtrlEdit_SetRECT($Edit1, $aRect)

While 1
    Global $nMsg = GUIGetMsg(1)
    Switch $nMsg[1]
        Case $Form2
            Switch $nMsg[0]
                Case $GUI_EVENT_CLOSE
                    _Exit()
                Case $GUI_EVENT_DROPPED
                    Sleep ( 200 )
                    $mult = StringSplit ( GUICtrlRead ( $Input2 ), "|" )
                    If @error Then
                        WinActivate ( $Form2 )
                        WinWaitActive ( $Form2 )
                        GUICtrlSetState ( $Input2, $GUI_FOCUS )
                        Send ( "{ENTER}", 0 )
                    Else
                        For $v = 1 To $mult[0] Step 1
                            $attach = $attach & $mult[$v] & ";"
                        Next
                        GUICtrlSetData ( $Input2, "" )
                            $sToolTipAnswer = ToolTip("The attachments were added!",Default,Default,"Success")
                        Sleep ( 3000 )
                        ToolTip ("")
                    EndIf

                Case $MenuItem2
                    GUISetState ( @SW_HIDE, $Form2 )
                    GUISetState ( @SW_DISABLE, $Form2 )
                    GUISwitch ( $Form3 )
                    GUISetState ( @SW_ENABLE, $Form3 )
                    GUISetState ( @SW_SHOW, $Form3 )
                    If $attach <> "" Then
                        $array = StringSplit ( StringTrimRight ( $attach, 1 ), ";" )
                        If @error Then
                            SetError ( 0 )
                            _GUICtrlListBox_AddString ( $List1, _GetFilename ( StringTrimRight ( $attach, 1 ) ) & "." & _GetFilenameExt ( StringTrimRight ( $attach, 1 ) ) )
                        Else
                            For $l = 1 To $array[0] Step 1
                                _GUICtrlListBox_AddString ( $List1, _GetFilename ( $array[$l] ) & "." & _GetFilenameExt ( $array[$l] ) )
                            Next
                        EndIf
                    Else
                        _GUICtrlListBox_AddString ( $List1, "You currently do not have any attachments." )
                    EndIf
                Case $Input2
                    $attach = $attach & GUICtrlRead ( $Input2 ) & ";"
                    GUICtrlSetData ( $Input2, "" )
                    $sToolTipAnswer = ToolTip("The attachment was added!",Default,Default,"Success")
                    Sleep ( 3000 )
                    ToolTip ("")

                Case $Button9
                    If GUICtrlRead ( $Input2 ) <> "" Then
                        $attach = $attach & GUICtrlRead ( $Input2 ) & ";"
                        GUICtrlSetData ( $Input2, "" )
                        $sToolTipAnswer = ToolTip("The attachment was added!",Default,Default,"Success")
                        Sleep ( 3000 )
                        ToolTip ("")
                    Else
                        $file = FileOpenDialog ( "Choose the file you want to attach.", "", "All (*.*)", 7, "", $Form2 )
                        $files = StringSplit ( $file, "|" )
                        If @error Then
                            SetError ( 0 )
                            $attach = $attach & $file & ";"
                            GUICtrlSetData ( $Input2, $file )
                            $sToolTipAnswer = ToolTip("The attachment was added!",Default,Default,"Success")
                            Sleep ( 1000 )
                            ToolTip ("")
                            GUICtrlSetData ( $Input2, "" )
                        Else
                            For $p = 2 To $files[0] Step 1
                                $attach = $attach & $files[1] & "\" & $files[$p] & ";"
                            Next
                            $sToolTipAnswer = ToolTip("The attachment was added!",Default,Default,"Success")
                            Sleep ( 1000 )
                            ToolTip ("")
                        EndIf
                    EndIf
                Case $Button1
                    _GUICtrlEdit_SetSel ( $Edit1, 0, -1 )
                    _SpellCheck ()
                Case $Button2;save as template
                    If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer
                    $sInputBoxAnswer = InputBox("Template Name","What do you want to name this template?",""," ")
                    If @Error = 1 Then

                    Else
                        $name = $sInputBoxAnswer
                        $num = Int ( IniRead ( @MyDocumentsDir & "\settings.ini", "Number", "Template", "0" ) )
                        $num += 1
                        $bodcap = _GUICtrlEdit_GetText ( $Edit1 )
                        $subcap = GUICtrlRead ( $Input3 )
                        $attcap = $attach
                        Local $holdarr[5][2] = [[3, ""], ["Name", $name], ["Body", $bodcap], ["Subject", $subcap], ["Attachments", $attcap]]
                        IniWriteSection ( @MyDocumentsDir & "\settings.ini", "Template " & $num, $holdarr )
                        IniWrite ( @MyDocumentsDir & "\settings.ini", "Number", "Template", $num )
                        $sToolTipAnswer = ToolTip("The attachment was added!",Default,Default,"Success")
                        Sleep ( 2000 )
                        ToolTip ( "" )
                    EndIf

                Case $Button6
                    GUISetState ( @SW_HIDE, $Form2 )
                    GUISetState ( @SW_DISABLE, $Form2 )
                    GUISwitch ( $Form3 )
                    GUISetState ( @SW_ENABLE, $Form4 )
                    GUISetState ( @SW_SHOW, $Form4 )
                    $numag = Int ( IniRead ( @MyDocumentsDir & "\settings.ini", "Number", "Template", "0" ) )
                    If $numag = 0 Then
                        MsgBox($MB_OK + $MB_ICONHAND,"No templates","You have not configured any templates.")
                    Else
                        For $h = 1 To $numag Step 1
                            GUICtrlSetData ( $Combo1, IniRead ( @MyDocumentsDir & "\settings.ini", "Template " & $h, "Name", "NA" ) )
                        Next
                    EndIf

            EndSwitch
        Case $Form1
            Switch $nMsg[0]
                Case $GUI_EVENT_CLOSE
                    GUISetState ( @SW_HIDE, $Form1 )
                    GUISetState ( @SW_DISABLE, $Form1 )
                    GUISwitch ( $Form2 )
                    GUISetState ( @SW_ENABLE, $Form2 )
                    GUISetState ( @SW_SHOW, $Form2 )
                Case $ListBox1
                    _SpellingSuggestions()
                Case $ListBox2
                    GUICtrlSetState($Button5, $GUI_ENABLE)
                Case $Button3
                    SendMessage ()
                Case $Button4
                    GUISetState ( @SW_HIDE, $Form1 )
                    GUISetState ( @SW_DISABLE, $Form1 )
                    GUISwitch ( $Form2 )
                    GUISetState ( @SW_ENABLE, $Form2 )
                    GUISetState ( @SW_SHOW, $Form2 )
                Case $Button5
                    _ReplaceWord()
            EndSwitch
        Case $Form3
            ToolTip ("")
            Switch $nMsg[0]
                Case $GUI_EVENT_CLOSE, $Button8
                    ToolTip ("")
                    GUISetState ( @SW_HIDE, $Form3 )
                    GUISetState ( @SW_DISABLE, $Form3 )
                    GUISwitch ( $Form2 )
                    GUISetState ( @SW_ENABLE, $Form2 )
                    GUISetState ( @SW_SHOW, $Form2 )
                    If UBound ( $array ) = 1 Then
                            $attach = ""
                        Else
                            $attach = ""
                            For $ff = 1 To UBound ( $array ) - 1 Step 1
                                $attach = $attach & $array[$ff] & ";"
                            Next
                        EndIf
                        _GUICtrlListBox_ResetContent ( $List1 )
                Case $List1
                    ToolTip ("")
                Case $Button7
                    If _GUICtrlListBox_GetSelCount = -1 Then
                        $sToolTipAnswer = ToolTip("Select something to delete first numbnuts.",Default,Default,"Idiot")
                    Else
                        ToolTip ("")
                        $seltext = _GUICtrlListBox_GetText ( $List1, _GUICtrlListBox_GetCurSel ( $List1 ) )
                        For $ff = 1 To $array[0] Step 1
                            If StringInStr ( $array[$ff], $seltext ) > 0 Then
                                _ArrayDelete ( $array, $ff )
                                _GUICtrlListBox_DeleteString ( $List1, _GUICtrlListBox_GetCurSel ( $List1 ) )
                                ExitLoop
                            EndIf
                        Next
                    EndIf
            EndSwitch
        Case $Form4
            Switch $nMsg[0]
                Case $GUI_EVENT_CLOSE
                    GUISetState ( @SW_HIDE, $Form4 )
                    GUISetState ( @SW_DISABLE, $Form4 )
                    GUISwitch ( $Form2 )
                    GUISetState ( @SW_ENABLE, $Form2 )
                    GUISetState ( @SW_SHOW, $Form2 )
                Case $Combo1
                    $sec = ""
                    $numag2 = Int ( IniRead ( @MyDocumentsDir & "\settings.ini", "Number", "Template", "0" ) )
                    If $numag2 = 0 Then

                    Else
                        $use = GUICtrlRead ( $Combo1 )
                        For $h = 1 To $numag2 Step 1
                            If StringCompare ( IniRead ( @MyDocumentsDir & "\settings.ini", "Template " & $h, "Name", "NA" ), $use ) = 0 Then
                                $sec = "Template " & $h
                                ExitLoop
                            Else
                                ContinueLoop
                            EndIf
                        Next
                        GUISetState ( @SW_HIDE, $Form4 )
                        GUISetState ( @SW_DISABLE, $Form4 )
                        GUISwitch ( $Form2 )
                        GUISetState ( @SW_ENABLE, $Form2 )
                        GUISetState ( @SW_SHOW, $Form2 )
                        $attach = IniRead ( @MyDocumentsDir & "\settings.ini", $sec, "Attachments", "NA" )
                        GUICtrlSetData ( $Input3, IniRead ( @MyDocumentsDir & "\settings.ini", $sec, "Subject", "NA" ) )
                        _GUICtrlEdit_SetText ( $Edit1, IniRead ( @MyDocumentsDir & "\settings.ini", $sec, "Body", "NA" ) )
                    EndIf
            EndSwitch
    EndSwitch
WEnd
Func stylish ()
    $thestyle = GUIGetStyle ( $handle )
    If $trans = False Then
        GUISetStyle ( -1, $thestyle[1] + 32, $handle )
        WinSetTrans ( $handle, "", 170 )
        $trans = True
    Else
        GUISetStyle ( -1, $thestyle[1] - 32, $handle )
        WinSetTrans ( $handle, "", 255 )
        $trans = False
    EndIf
EndFunc
Func GetHoveredHwnd()
    Local $iRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1))
    If IsArray($iRet) Then Return HWnd($iRet[0])
    Return SetError(1, 0, 0)
EndFunc
Func _SpellCheck()
    Local $sText, $tText, $sWord

    $sText = _GUICtrlEdit_GetText ( $Edit1 )
    $oRange = $oWordApp.ActiveDocument.Range
    $oRange.Delete
    $oRange.InsertAfter($sText)
    _SetLanguage()

    $oSpellCollection = $oRange.SpellingErrors
    If $oSpellCollection.Count > 0 Then
        If BitAND ( WinGetState ( $handle ), 2 ) Then
            If $trans = True Then
                stylish ()
            EndIf
            GUISetState ( @SW_DISABLE, $Form2 )
            GUISetState ( @SW_HIDE, $Form2 )
            GUISwitch ( $Form1 )
            GUISetState ( @SW_SHOW, $Form1 )
            GUISetState ( @SW_ENABLE, $Form1 )
        EndIf

            ;
        _GUICtrlListBox_ResetContent($ListBox1)
        _GUICtrlListBox_ResetContent($ListBox2)
        GUICtrlSetState($Button5, $GUI_DISABLE)
            For $i = 1 To $oSpellCollection.Count
                $sWord = $oSpellCollection.Item($i).Text
                _GUICtrlListBox_AddString($ListBox1, $sWord)
            Next
        GUICtrlSetData($Edit1, $oRange.Text)
    Else
        SendMessage ()
    EndIf
EndFunc   ;==>_SpellCheck

Func _SpellingSuggestions()
    Local $iWord, $sWord
    ;
    _GUICtrlListBox_ResetContent($ListBox2)
    GUICtrlSetState($Button5, $GUI_DISABLE)

    $iWord = _GUICtrlListBox_GetCurSel($ListBox1) + 1
    $sWord = $oSpellCollection.Item($iWord).Text

    $oAlternateWords = $oWordApp.GetSpellingSuggestions($sWord)
    If $oAlternateWords.Count > 0 Then
        For $i = 1 To $oAlternateWords.Count
            _GUICtrlListBox_AddString($ListBox2, $oAlternateWords.Item($i).Name)
        Next
    Else
        _GUICtrlListBox_AddString($ListBox2, "No suggestions.")
    EndIf
EndFunc   ;==>_SpellingSuggestions

Func _HighlightWord()
    Local $sText, $iWord, $sWord, $iEnd, $iStart
    ;
    $iWord = _GUICtrlListBox_GetCurSel($ListBox1) + 1
    $sWord = $oSpellCollection.Item($iWord).Text
    $sText = $oRange.Text

    $iStart = ($oSpellCollection.Item($iWord).Start)
    $iEnd = ($oSpellCollection.Item($iWord).End)
    _GUICtrlEdit_SetSel($Edit1, $iStart, $iEnd)
EndFunc   ;==>_HighlightWord

Func _ReplaceWord()
    Local $iWord, $iNewWord, $sWord, $sNewWord, $sText, $sNewText
    ;
    $iWord = _GUICtrlListBox_GetCurSel($ListBox1) + 1
    $iNewWord = _GUICtrlListBox_GetCurSel($ListBox2) + 1
    If $iWord == $LB_ERR Or $iNewWord == $LB_ERR Then
        MsgBox(48, "Error", "You must first select a word to replace, then a replacement word.")
        Return
    EndIf
    $oSpellCollection.Item($iWord).Text = $oAlternateWords.Item($iNewWord).Name

    GUICtrlSetData($Edit1, $oRange.Text)

    _SpellCheck()

    GUICtrlSetState($Button5, $GUI_DISABLE)
EndFunc   ;==>_ReplaceWord

Func _SetLanguage()
    $sLang = "English"
        $oWordApp.CheckLanguage = False
        $WdLangID = Number(1033)

        If $WdLangID Then
            With $oRange
                .LanguageID = $WdLangID
                .NoProofing = False
            EndWith
        EndIf
EndFunc   ;==>_SetLanguage

Func SendMessage ()
    If BitAND ( WinGetState ( $handle2 ), 2 ) Then
        GUISetState ( @SW_HIDE, $Form1 )
        GUISetState ( @SW_DISABLE, $Form1 )
        GUISwitch ( $Form2 )
        GUISetState ( @SW_ENABLE, $Form2 )
        GUISetState ( @SW_SHOW, $Form2 )
    EndIf
    $change = StringStripWS ( GUICtrlRead ( $Input1 ), 3 )
    GUICtrlSetData ( $Input1, $change )
    $body = GUICtrlRead ( $Edit1 )
    _GUICtrlEdit_SetText ( $Edit1, "" )
    ;$attach = StringStripCR ( $attach )
    $subject = GUICtrlRead ( $Input3 )
    If $attach <> "" Then
        $split = StringSplit ( StringTrimRight ( $attach, 1 ), ';' )
        If @error Then
            SetError ( 0 )
            $finattach = '-a:"' & $attach & '" '
        Else
            $finattach = Null
            For $i = 1 To $split[0] Step 1
                $finattach = $finattach & '-a:"' & $split[$i] & '" '
            Next
        EndIf
    EndIf
    $body = StringReplace ( $body, @CRLF, "\n" )
    #cs
    $split = StringSplit ( $body, "", $STR_NOCOUNT )
    For $i = 0 To UBound ( $split ) - 1 Step 1
        If $split[$i] = Chr ( 10 ) Then
            $split[$i] = "\n"
        ElseIf $split[$i] = Chr ( 13 ) Then
            $split[$i] = Null
        Else
            ContinueLoop
        EndIf
    Next
    $body = _ArrayToString ( $split, "" )
    ConsoleWrite ( $body )
    #ce
    If StringRegExp ( GUICtrlRead ( $Input1 ), "^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$" ) = 1 Then
        If $attach = "" Then
            $proc = Run ( 'CMail -from:' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Email Address", "NA" ) & ':"' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Name", "NA" ) & '" -to:' & GUICtrlRead ( $Input1 ) & ' -subject:"' & $subject & '" -body:"' & $body & '" -host:' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "User name", "NA" ) & ':' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Password", "NA" ) & '@' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "SMTP Server", "NA" ) & ':' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Port", "NA" ) & ' -starttls -requiretls -d', 'C:\ProgramData\chocolatey\bin', @SW_SHOW, $STDOUT_CHILD )
        Else
            $proc = Run ( 'CMail -from:' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Email Address", "NA" ) & ':"' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Name", "NA" ) & '" -to:' & GUICtrlRead ( $Input1 ) & ' -subject:"' & $subject & '" -body:"' & $body & '" ' & $finattach & '-host:' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "User name", "NA" ) & ':' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Password", "NA" ) & '@' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "SMTP Server", "NA" ) & ':' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Port", "NA" ) & ' -starttls -requiretls -d', 'C:\ProgramData\chocolatey\bin', @SW_SHOW, $STDOUT_CHILD )
            ClipPut ( 'CMail -from:' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Email Address", "NA" ) & ':"' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Name", "NA" ) & '" -to:' & GUICtrlRead ( $Input1 ) & ' -subject:"' & $subject & '" -body:"' & $body & '" ' & $finattach & '-host:' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "User name", "NA" ) & ':' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Password", "NA" ) & '@' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "SMTP Server", "NA" ) & ':' & IniRead ( @MyDocumentsDir & "\settings.ini", "Config", "Port", "NA" ) & ' -starttls -requiretls -d' )
    ProcessWaitClose ( $proc )
    $text = StdoutRead ( $proc )
    ClipPut ( $text )
    MsgBox($MB_OK + $MB_SYSTEMMODAL,"Sent!","Message Sent!!")
        EndIf
    Else
MsgBox(16,"Not a valid email","Enter a correct email address please")
    EndIf
EndFunc

Func _GetFilename($sFilePath)
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace($sFilePath, "\", "\\") & "'")
    If IsObj($oColFiles) Then
        For $oObjectFile In $oColFiles
            Return $oObjectFile.FileName
        Next
    EndIf
    Return SetError(1, 1, 0)
EndFunc   ;==>_GetFilename

Func _GetFilenameExt($sFilePath)
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace($sFilePath, "\", "\\") & "'")
    If IsObj($oColFiles) Then
        For $oObjectFile In $oColFiles
            Return $oObjectFile.Extension
        Next
    EndIf
    Return SetError(1, 1, 0)
EndFunc   ;==>_GetFilenameExt

Func _GetFilenameInt($sFilePath)
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace($sFilePath, "\", "\\") & "'")
    If IsObj($oColFiles) Then
        For $oObjectFile In $oColFiles
            Return $oObjectFile.Name
        Next
    EndIf
    Return SetError(1, 1, 0)
EndFunc   ;==>_GetFilenameInt

Func _GetFilenameDrive($sFilePath)
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace($sFilePath, "\", "\\") & "'")
    If IsObj($oColFiles) Then
        For $oObjectFile In $oColFiles
            Return StringUpper($oObjectFile.Drive)
        Next
    EndIf
    Return SetError(1, 1, 0)
EndFunc   ;==>_GetFilenameDrive

Func _GetFilenamePath($sFilePath)
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColFiles = $oWMIService.ExecQuery("Select * From CIM_Datafile Where Name = '" & StringReplace($sFilePath, "\", "\\") & "'")
    If IsObj($oColFiles) Then
        For $oObjectFile In $oColFiles
            Return $oObjectFile.Path
        Next
    EndIf
    Return SetError(1, 1, 0)
EndFunc   ;==>_GetFilenamePath

Func _Exit()
    _Word_Quit ( $oWordApp )
    Exit
EndFunc   ;==>_Exit

 

Edited by MattHiggs
Link to comment
Share on other sites

  • Developers
20 minutes ago, MattHiggs said:

**Edit: Ok.  So I figured out that it was because I was compiling it with the "require Administrator" execution level.  But why would that make such a difference?

It matters when both programs run at different credential levels. So by running at AdminLevel should also work, but not when only one is runnung as Admin.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

4 minutes ago, spudw2k said:

Unencrypted login credentials....gives me the heebeegeebees. :(

About gave me a heart-attack.  Thought I posted my credentials in there.  Hold on one sec while I recover......

 

19 minutes ago, Jos said:

It matters when both programs run at different credential levels. So by running at AdminLevel should also work, but not when only one is runnung as Admin.

Jos

Not sure what you mean.....  Are you referring to the permissions of the current user in relation to the application?  The file permissions in relation to application?  Still very much lost.

Link to comment
Share on other sites

1 minute ago, MattHiggs said:

Thought I posted my credentials in there.

No, but you are storing them in cleartext in your Ini.  That is what I meant.

Link to comment
Share on other sites

  • 3 years later...

Thank you guys so much for this post!!!  I've been trying to figure out why I've been unable to pass a password to an application (thick client on Windows) and coming up blank for hours.  My script runs perfectly when running from the editor but when I compile the .EXE it seemed to pass garbage to the password field.  Still can't explain what's going on between the two variations of running my script but this thread reminded our admins lock down certain types of installs to the domain laptops via some crappy GPO's.  Anyway I forced my script to be compiled to "requireAdministrator" and sure enough that fixed it!  Such a pain but had to say thanks for the inspiration!

 

-mario

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...