Jump to content

[Solved] Comment out a function for subsequent executions


Recommended Posts

Hello,

 

I'm working on having a program that when executed a message box will pop up informing the user on how it is to be used. It will offer a choice to not display the message again. The only way I was able to think of achieving this is by using the  _FileWriteToLine function, which would require me to know the line in which to comment out this message box. I want the code to be more rust though then just saying change line "X" as if in the future more code gets added this line might change. I was trying to find another function that returns the line in the file it is one but couldn't find such a thing. Here is what I'm thinking:

 

#include <File.au3>

;======Main=====


UserMSG();#UserMSG()#
FunStuff()

;======Functions=====

Func UserMSG()

$infomsg = MsgBox(4,"Info","Bla bla bla" & @CRLF & @CRLF & "Never see this again press ""YES""")

$MSGFuncLineNum = *****Return line number with string "#UserMSG()#"*****

If $infomsg == 6 Then
    _FileWriteToLine("test.au3",$MSGFuncLineNum,"#cs")
    _FileWriteToLine("test.au3",$MSGFuncLineNum+2,"#ce")
EndIf

endFunc;UserMSG()

Func FunStuff()
EndFunc

 

Edited by AnonymousX
Link to comment
Share on other sites

Or you just write something to the users HKCU or to AppData, registry is generally better for this type of thing:

#include <File.au3>

;======Main=====


UserMSG();#UserMSG()#
FunStuff()

;======Functions=====

Func UserMSG()
If RegRead('HKCU\Software\MyProgram', 'Show Message') = 0 Then Return
$infomsg = MsgBox(4,"Info","Bla bla bla" & @CRLF & @CRLF & "Never see this again press ""YES""")
If $infomsg == 6 Then RegWrite('HKCU\Software\MyProgram', 'Show Message', 'REG_DWORD', 0)

endFunc;UserMSG()

Func FunStuff()
EndFunc

 

Link to comment
Share on other sites

Why would you use a registry for showing a message box or not?

@AnonymousX just use an ini file, or some kind of blank file

#include <MsgBoxConstants.au3>

If (FileExists(@ScriptDir & "\ShowMsg") = False) Then
    If (MsgBox(4,"Info","Bla bla bla" & @CRLF & @CRLF & "Never see this again press ""YES""") = $IDYES) Then
        FileClose(FileOpen(@ScriptDir & "\ShowMsg", 10))
    EndIf
EndIf

Use an ini file if you want to save other settings for your program.

Link to comment
Share on other sites

@InunoTaishou - Why wouldn't you?  Most software will write to the HKCU registry to say that Eula has been read or Start-up message has been shown.  A flag is a flag, however there are some differences between system flags and user flags.  If this program is to be run by multiple users, by using your Ini method none of the other users that logon will see that message.

Link to comment
Share on other sites

If you write the Ini-file into the users @AppDataDir then this should work for multiple users.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Thanks for input. I'll have to look into that further, never used Ini-files or HKCU before. 

I figured out what I was originally trying to do, as well. Here is the code for anyone else in the future:

#include <File.au3>

;======Main=====


UserMSG();#usermsg#
FunStuff()

;======Functions=====

Func UserMSG()

$infomsg = MsgBox(4,"Info","Bla bla bla" & @CRLF & @CRLF & "Never see this again press ""YES""")

$MSGFuncLineNum = Findlinenum()

If $infomsg == 6 Then
    _FileWriteToLine(@scriptname,$MSGFuncLineNum,"#cs")
    _FileWriteToLine(@scriptname,$MSGFuncLineNum+2,"#ce")
EndIf

endFunc;UserMSG()

Func Findlinenum();Used to find line with usermsg()
    $All_linecount = _FileCountLines(@ScriptName)

For $i = $All_linecount To 1 Step -1
    If StringInStr(FileReadLine(@ScriptName, $i), "#usermsg#") Then
        $linenum = $i
    EndIf
Next

Return $linenum
EndFunc

Func FunStuff()
EndFunc

 

Link to comment
Share on other sites

  • Moderators

 

On 1/28/2017 at 6:21 AM, Subz said:

@InunoTaishou - Why wouldn't you?  Most software will write to the HKCU registry to say that Eula has been read or Start-up message has been shown. 

If you actually tear apart modern day applications, you will find that app-specific configuration information is not stored in HKCU per best practices. If stored anywhere it would be in HKLM; HKCU is reserved for "personalization" of an application by a single user. Most applications would use .ini or other config files, stored in a central location, as suggested by InunoTaishou

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

@JLogan3o13 - The OP wrote: " I'm working on having a program that when executed a message box will pop up informing the user on how it is to be used. It will offer a choice to not display the message again. "  If this message is only meant for only one user then @InunoTaishou solution would work fine, the solution I offered was for "personalization" of an application by a single user.

Link to comment
Share on other sites

  • Moderators

I understand what the OP is after; I was responding to your sweeping generalization that most software writes to HKCU. I also don't see a EULA as personalization. Regardless, the OP has several ways now to accomplish what he is after.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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...