Jewtus

Hyperlink with arguments

9 posts in this topic

I have a compiled tool that has a few options for command line arguments to kick off specific functions. I've tested them via the cmd line and they work great. What I'd like to do next is make it so my email notification contains a hyperlink to the file with the argument included. This is what I have for my email function that DOES work:

Func SendEmails($addAddressee,$id)
    IsOutLookOpen()
    $olApp = ObjCreate("Outlook.Application")
    $objMail = $olApp.CreateItem(0) ;$olMailItem
    With $objMail
        .Save
        .Subject = ("A form needs review - ID: "&$id)
        .HTMLBody = ('Please open the tool by clicking <a href="'&@ScriptDir&"\"&@ScriptName&'">HERE</a>.')
        $oRecipients=.Recipients
        .Display
    EndWith
    For $z=0 to UBound($addAddressee)-1
        If $addAddressee[$z]<> ''  Then
            $resolver=$oRecipients.Add($addAddressee[$z])
            $resolver.Resolve
        EndIf
    Next
EndFunc

and this works without issue but I want to make it so when they click the link, it also passes the command line arg:

.HTMLBody = ('Please open the tool by clicking <a href="'&@ScriptDir&"\"&@ScriptName&" -CMD "&$id&'">HERE</a>.')

Does anyone know how I can achieve this?

Share this post


Link to post
Share on other sites

I think you need to encode the spaces. Try %20 for a space.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Ok so I messed around with it a bit:

.HTMLBody = ('Please open the tool by clicking <a href='&StringReplace(@ScriptDir,' ','%20')&'\'&@ScriptName&'%20-CMD%20'&$id&'">HERE</a>.')

and this generates the link but when I open the link it says the file isn't found... Something like this

Cannot find the file '\\host\path\files\Test.exe -CMD 1'. Please verify the path or internet address is correct

So I tried to put quotes around the path and put the -CMD outside the quotes:

.HTMLBody = ('Please open the tool by clicking <a href="'&StringReplace(@ScriptDir,' ','%20')&'\'&@ScriptName&'"%20-EMC%20'&$id&'">HERE</a>.')

and when I do that, it just opens the EXE and doesn't pass the arg to the exe.

Edited by Jewtus
formatting

Share this post


Link to post
Share on other sites

I searched the web and got to the conclusion that it is not possible to call an exe and pass parameters using a link.

I'd suggest to just start the exe without parameters and then use Outlook to grab the ID from the subject line of the current mail item.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I'm not sure what you mean. I want the tool to operate normally, but I have a notifications section so when X action is performed, it notifies someone that they need to open the tool and go to a specific section. I was hoping to jump right to that section from the email. If I launch the tool normally, how would I go about grabbing the id from the email and passing it through to the application?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

When the tool is started you should

  • Check that Outlook is running
  • A mail item is active
  • the mail item has a subject of format "A form needs review - ID: "

If this is True then grab the ID from the subject and jump to the section needed. Else run the program normally.
This approach only works when the mail is being opened by Outlook.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

hmmm seems it could leave room for a lot of potential errors... I did figure out a simple solution that does seem to work though... Build a bat and link to the bat file:

Func SendEmails($addAddressee,$id)
    IsOutLookOpen()
    $olApp = ObjCreate("Outlook.Application")

    ;Build Launcher
    If FileExists(@ScriptDir&"\CMD\")=0 then DirCreate(@ScriptDir&"\CMD\")
    $cmdFile=@ScriptDir&"\CMD\"&$id&@MON&@MDAY&@YEAR&@HOUR&@MIN&@SEC&".bat"
    FileWrite($cmdFile,'"'&@ScriptDir&"\"&@ScriptName&'" -CMD '&$id)

    $objMail = $olApp.CreateItem(0) ;$olMailItem
    With $objMail
        .Save
        .Subject = ("A new form needs review - Project ID: "&$id)
        .HTMLBody = ('Please open the tool by clicking <a href="'&$cmdFile&'">HERE</a>.')
        $oRecipients=.Recipients
        .Display
    EndWith
    For $z=0 to UBound($addAddressee)-1
        If $addAddressee[$z]<> ''  Then
            $resolver=$oRecipients.Add($addAddressee[$z])
            $resolver.Resolve
        EndIf
    Next
EndFunc

 

Edited by Jewtus

Share this post


Link to post
Share on other sites

But this only works when the bat file is created on the recipients machine.
But why would you create a mail then?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

The tool is actually on a shared network dir so everyone is using the same folder structure. The mail is because no one will actually keep an eye on it because users suck. They want the system to send emails if anything ever changed and I told them they would get 20-30 notifications an hour if they did that so they settled to me just sending a summary email telling them to check.

 

The launching the bat is just a way of accommodating users who are lame and don't want to do their job or read anything.

Share this post


Link to post
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

  • Similar Content

    • water
      By water
      Extensive library to control and manipulate Microsoft Outlook.
      Theads: Development - General Help & Support - Example Scripts - Wiki
      BTW: If you like this UDF please click the "I like this" button. This tells me where to next put my development effort

      KNOWN BUGS (last changed: 2018-01-26)
      Function _OL_RuleConditionSet does not properly handle parameter rule condition type ($iRuleConditionType) when value $olConditionSentTo is passed. it is being processed the same way as $olConditionFrom.
      Thanks to user Moonscarlet for reporting this bug.
      Fixed with version 1.3.3.1 of the UDF.
    • Simpel
      By Simpel
      Hi.
      Thanks to this post (https://www.autoitscript.com/forum/topic/189553-writing-to-cmd/?do=findComment&comment=1361142) I can now write a helpfile to the cmd when for instance passing parameter -h or -help at cmd. But then cmd is blocked by the script (I had to free it with CTRL+BREAK):
      #include <WinAPI.au3> _WinAPI_AttachConsole() $hConsole = _WinAPI_GetStdHandle(1) _WinAPI_WriteConsole($hConsole, "Print helpfile................" & @CRLF) Inside MSDN Library then I found this sentence: A process can use the FreeConsole function to detach itself from its console.
      But I don't find something like _WinAPI_FreeConsole(). How can I do it in another way?
      Regards, Conrad
    • TheAutomator
      By TheAutomator
      A fullscreen console with custom commands!

      Introduction:
      Hi everyone!
      This funny project started as a question in the help section:
      https://www.autoitscript.com/forum/topic/174404-edit-detect-key-before-updating-content/
      I'd like to share this script with everyone that is interested. 
       
      Why would I want it?
      You like the old style fullscreen console (like in the old day's), You can add custom commands, You can customize the font a lot more compared to cmd.exe, You can share ideas or add tweaks to the script.  
      Still to do:
      Write a simple custom programming language to implement this tool. Writing a little help file / pdf to describe my little programming language. Add little sound effects like a beep if there is a syntax error (optional). Clean up and modify Console.Au3 content. Add an option to have to type a login password (optional). Make an optional installer that also gives scripts for this tool a custom icon and open with command. ...Call Neo?  
      Thanks to:
      xxaviarxx: debugging, some ideas. jguinch: debugging, adding a bunch of tweaks and ideas. kylomas: debugging, new ideas.  
      Edits and updates:
      Added usage of tab key in edit control Edit has focus now on startup I'm currently rewriting a simple custom programming language to implement this tool.  
      UDF download: Console.au3
       
      Regards
      TheAutomator
    • hcI
      By hcI
      Hello I would like to know if there is a way to return a sentence in cmd when I launch from it (because I add arguments).
      For example, diskpart.exe which help to manage the key and hdd connected, when you launch it with the parameter "/f" the app return a sentence saying that it don't recognize the parameter "/f" and it return the sentence in the cmd where i started the application, not a new one.
      That's what I want to do but I couldn't find anything that would solve my problem on internet and on AutoIt like ConsoleWrite / ConsoleWriteError (don't work).
       
      Thanks
    • Duck
      By Duck
      I'm attempting to capture the output from the command line tool PSEXEC. I'm using AutoIT to run an instance of PSEXEC against a remote PC to audit Local Admins in my environment using net.exe (C:\Windows\System32> net localgroup administrators). However the usual trick I use to capture command line output does not appear to work well with PSEXEC, as the bottom portion of the output is missing from the return. Any ideas or recommendations are greatly appreciated.  
       
      Here is what I'm working with: 
      ;This script will read from a list of hosts and report who has local admin privileges on the machine #RequireAdmin Global $fileName = @ScriptDir & '\test.txt' ;hostlist, one host per line readHostList() ;Read list of hosts Func readHostList() Local $file = FileOpen($fileName, 0) While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop ConsoleWrite($line & @CRLF) ;MsgBox(0,0,$line) getLocalAdmins($line) WEnd FileClose($file) EndFunc ;run PSEXEC to list local admins Func getLocalAdmins($remotePC) Local $testFile = @ScriptDir &'\test234.txt' FileOpen($testFile, 1) Local $psexec = 'psexec \\' & $remotePC & ' net localgroup administrators' FileWriteLine($testFile, _RunCmd($psexec) ) FileClose($testFile) EndFunc ;Used to return CLI output Func _RunCmd($sCommand) Local $nPid = Run(@Comspec & " /c" & $sCommand, @SystemDir, @SW_Hide, 8), $sRet = "" If @Error then Return "ERROR:" & @ERROR ProcessWait($nPid) While 1 $sRet &= StdoutRead($nPID) If @error Or (Not ProcessExists ($nPid)) Then ExitLoop WEnd Return $sRet EndFunc  
      ## If i manually run the command on the remote PC via PSEXEC I will get the following output: 
      PsExec v2.11 - Execute processes remotely
      Copyright (C) 2001-2014 Mark Russinovich
      Sysinternals - www.sysinternals.com
      Starting net on PCNAME... on PCNAME...
      net exited on PCNAME with error code 0.
      -------------------------------------------------------------------------------
      admin
      Administrator
      Alias name     administrators
      Domain\Domain Admins
      Comment        Administrators have complete and unrestricted access to the computer/domain
      Members
      The command completed successfully.
       
      ## The returned output from running the above script is as follows:
      PsExec v2.11 - Execute processes remotely
      Copyright (C) 2001-2014 Mark Russinovich
      Sysinternals - www.sysinternals.com
      Alias name     administrators
      Connecting to PCNAME...
      Starting PSEXESVC service on PCNAME...
      Connecting with PsExec service on PCName...
      Starting net on PCNAME..
      net exited on PCNAME with error code 0.
       
      **Note to test this script PSEXEC must be in the system dir or the path in the script changed 
      PSEXEC tool: https://docs.microsoft.com/en-us/sysinternals/downloads/psexec