Sign in to follow this  
Followers 0
knowledge

writting out ps1 files and batch files

6 posts in this topic

So iam trying to make an autoit script that opens notepad or a cmd shell and write out code for either batch or powershell then save the code as a file for later execution. The computer doesnt have a reliable internet connection so just downloading and executing the code from the net is not feasable.  So when i try this the file saves okay, and on skimming the written out code seems fine too, but when i try to execute the file nothing happens.  So heres what im doing

$1 = FileOpen(C:tempxxxx.bat)

FileWrite($1, "a bunch of code which i copy and paste from a WORKING batch file")

 

I know the code is correct because i wrote it and it works but for some reason when i use autoit to write it out for me i get nothing. No errors or nothing it just opens a cmd shell and quickly dissapears with no action happening    anyone know whats going on?  

I also tried doing this from the cmd shell with      "echo a bunch of batch code or powershell code >> C:tempxxx.bat

also not working

Share this post


Link to post
Share on other sites



Well not really cuz the code is a powershell script which has been tested and works, then that powershell script because it has so many characters like @ " , etc that it has been encoded using powershell so the code looks like this

powershell -EncodedCommand jkhHUIHuihuhHHSbdbgbGGGGvytgvsygvguBU      all the way through, but that encoded base64 powershell code which actually launches initially from a cmd shell which switches to a powershell then executes the code, works when i click on it as a batch file,,,then that same exact code is copy and pasted into   FileWrite($1, "powershell -EncodedCommand uihiuhUIHHHIUHiuhiuhiuhuiHIUHIUHuygtyfTRFRTdREDrtYGyuiHu" &@CRLF _

&"IUHuihiuhHUHIUHUYGBGTYFVRTfrtfGUYHiujOjJiuHuytgFrtfrtFytUi")

 

I look at the file $1  and the code is written in there just fine but wont execute for some reason    perhaps im messing up something using the @CRLF _ &"" commands?

Share this post


Link to post
Share on other sites

or im thinking autoit is perhaps incapable of automating the writing out complex code to files which work as executables?   i know simple one liner type of codes can work but seems like bigger more complicated code wont run when written out by autoit

Share this post


Link to post
Share on other sites

How are you trying to execute the code, Run, RunAs, ShellExecute?


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

#6 ·  Posted (edited)

I also tried doing this from the cmd shell with      "echo a bunch of batch code or powershell code >> C:tempxxx.bat

also not working

 

As long as this is the case, I would not be looking at your autoitscript but rather at your environment. Are you sure you are echoing to a dir/file you actually have write permissions for?

Also, on your au3 code:

1 - the default mode for FileOpen is read-only. Read the helpfile for FileOpen and specify the write options that you need. Your current call is not going to work.

2 - you need to FileClose the file after writing.

3 - log the return values of the FileOpen, the FileWrite and the FileClose calls so you know where it goes wrong.

4 - if you need admin permissions, add #RequireAdmin on top of your script

(1 - 4 can be summed up by: read the friendly manual  :) )

 

5 - check the content you are trying to write for strange characters.

6 - still trouble? Show more code (what you have now is not enough to correctly write a file) and if possible also an example of the intended content of one of your files-to-write.

(Also, autoit code posted on this forum should be in autoit tags (use the blue autoit button in the button bar above the post entry field.)

Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

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
Sign in to follow this  
Followers 0