Jump to content
Ackerz

Open a generated filename

Recommended Posts

Ackerz

Hi all,

I have been using autoit this week and I have been scoping your forum. I have found many useful tips and learnt a lot.

However I am now at the point where I understand what I need to use or do but I can't achieve it. Time is critical but I'm not going to give up just because I've made this post so I will update if I find anything.

Straight to the point. I generate a notepad file which holds a randomly generated password. The text file is then saved and the naming convention is the machine name and the date.

However all I want to simply do is open that file after being generated so I can input some more data into it. Such a simple ask, apologies if this annoys anyone if it helps it's annoying me.

 

run("notepad.exe C:\Users\Admin060\Desktop\"$PCName &" "-" "& $newname ".txt")
WinWaitActive("Untitled - Notepad","",1)

Many thanks

Share this post


Link to post
Share on other sites
Jfish

@SlackerAl is right, FileOpen will return a handle to you and you can use it to edit the file etc.  You never explained what was not working - but if you can't open that file it is likely your path or filename.   Here is a small tester to show the FileOpen concept and then using notepad to open and view its contents:

$testfile = FileOpen(@ScriptDir&"\testfile.txt",2)
FileWriteLine($testfile,"this is a test file")
FileClose($testfile)
run("notepad.exe"&" " &@ScriptDir&"\testfile.txt")

Again, you don't need notepad at all - just closing the loop in case that was part of your issue.  You could simply read the file with code using the file functions.   


Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites
Subz

Here is another example:

Local $sFileName = @DesktopDir & "\" & @ComputerName & "-" & @MDAY & @MON & @YEAR & ".txt"
Local $hFileName = FileOpen($sFileName, 2)
FileWrite($hFileName, _Random_Password(8) & @CRLF)
FileClose($hFileName)
ShellExecute($sFileName)

;~ Function by GaryFrost, Valik
Func _Random_Password($iMaxLength)
   Local $sPassword = '', $sLetter, $I
   For $i = 1 To $iMaxLength
      $sLetter = Random(33, 126)
      $sPassword = $sPassword & Chr($sLetter)
   Next
   Return $sPassword
EndFunc   ;==>Random_Password

 

Share this post


Link to post
Share on other sites
Ackerz

Thank you for the much appreciated speedy responses @SlackerAl @Jfish @Subz.

Correct, apologies @Jfish. The drama was that I could not open the generated file because of how I gave it it's naming convention.

I will post again once I've tested your brilliant methods guys. Currently on a virtualization course but I'll do it as soon as I can.

Thanks again.

Share this post


Link to post
Share on other sites
Ackerz

Update: I grabbed Subz's first line but edited it to suit me and that fixed the problem. So much neater that way too, obviously.

I've managed to read about calling and I've been looking at mouse clicks too. However I don't really want to use the mouse and the password script I am using makes it a little bit more complicated to automatically click okay.

$Len =  InputBox("Password Generator - Ackerz",$msgPrompt,"9")
            $len =  StringStripWS($len,$STR_STRIPALL)

                           ;Check that user has entered a vaild password length
                           if not StringIsDigit($len) or $len = 0 Then
                              MsgBox(48,"Error","Invaild Integer was entered" & @CRLF & "Program will now exit.")
                              Exit
                           EndIf

                           ;This creates the random password.
                           for $i = 1 to $Len
                              ;Pick a random char between 1 and the pwsMask Length
                              $n = int(random(1,StringLen($pwsMask)))
                              _Submit()
                              ;Concat each char that has been picked out of pwsMask to $buff
                              $buff = $Buff & StringMid($pwsmask,$n,1)
                           Next

So as we can see here, great I can get a msg box appearing asking for value to be inserted. I am then presented with a gui with two buttons. "Ok" and "cancel". I want to automate the press of the "Ok" button. I do NOT wish to be pressing enter. I just can't work out where I would fit this into the current presented code.

I'm enjoying this and I'm learning but when help is needed I find it best to just ask. This is also for work purposes, so it's bonuses all round really. Hope I have explained this well enough.

Thank you

Edited by Ackerz

Share this post


Link to post
Share on other sites
BrewManNH

Please post a fully working example of what it is you're working with. Where does the GUI with the ok and cancel buttons come from? Is this from your code, or some other program? What is the _Submit function for?

You're not giving us anything to work with.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
SlackerAl

Look at help for ControlClick, be sure to also read the help on Controls. You can find out information on a window and a specific control using the program Au3Info_x64.exe which is included as part of the AutoIt installation.

And as BrewManNH said, if you want specific help, post some code... ideally the simplest replicator of your problem that you can make (yes, even if that involves writing your only simplified version). And whilst I'm being grumpy... new problem, new topic :-)

Edited by SlackerAl

Problem solving step 1: Write a simple, self-contained, running, replicator of your problem.

Share this post


Link to post
Share on other sites
Ackerz

Completely agree. I'll make a new topic. I'm happy for this topic to get deleted too, if anyone can do that.

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

×