Sarah2016

Script doesn't create file!

20 posts in this topic

#1 ·  Posted (edited)

Hi,

I am facing a very annoying and confusing problem...

I made a script, one of its function is to create a file in the working directory having the date and time of running the script and it starts once the windows start (by adding registry key)..

Tested my script on my PC and it worked perfectly...

Took this script to another PC and when I run (myself by double click!), it also work perfectly...

BUT when it runs by the windows in start, it does not create any files in the directory (although the script is running as I found in task manager)..

 

Spent HOURS (or DAYS !!) trying to figure out this puzzle...

 

May be it's something related to user permission or something like that? but the user I'm running the script on is an admin!

 

 

EDIT: facing the problem on Windows 7

Edited by Sarah2016

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Pretty sure line 13 is wrong but could confirm that when you post your script portion that creates the file. ;)
there is likely something wrong with the WorkDir.

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
2 minutes ago, Jos said:

Pretty sure line 13 is wrong but could confirm that when you post your script portion that creates the file. ;)
there is likely something wrong with the WorkDir.

Jos

not only with working dir

tried multiple things

added to that, it works perfectly on my PC!

So it's not script issue for sure

Share this post


Link to post
Share on other sites

So if it isn't a script issue I guess we're done here, right? How do you expect anyone to help you without posting the code you're using?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Here it is:

 

#NoTrayIcon
#include <Date.au3>
FileDelete(@WorkingDir & "\start.log")
FileWrite(@WorkingDir & "\start.log", _NowDate() & " // " & _NowTime() & @CRLF)

 

EDIT: also tried something other than @WorkingDIr

 

Edited by Sarah2016

Share this post


Link to post
Share on other sites

So why are you using the @Workdir as target instead of defining a more explicit directory?
Where are you expecting the file to be created?
What happens when you hardcode a directory on the computer that doesn't work?

Jos

 


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Put the file on the desktop and try it. Did you try to run it as admin? (right click and chose run as administrator)

Share this post


Link to post
Share on other sites
3 minutes ago, Juvigy said:

Put the file on the desktop and try it. Did you try to run it as admin? (right click and chose run as administrator)

Agree with your assumption, but even Admin may not have to right to write to certain dirs (depend on each system).

And keep in mind also the way of "run by Windows" might be of interested, autostart, Scheduled, RegistryRun(once).... He did not named the method. So also mine is just a guess...

Share this post


Link to post
Share on other sites

Yes, first thought "run by Windows" may mean the exe is executed in another session, or the file is being created in a location other than where the OP expects, based on the context of the account running the program.

Share this post


Link to post
Share on other sites

#11 ·  Posted

Got the exact problem.. It is because the path is not defined explicitly (as Jos stated, strangely I couldn't figured it out despite he mentioned it from the beginning).

"Run by windows" means when I put the file in startup folder, or when I put it in registry in "Run"

 

Did some googling .. some ppl have the same problem http://stackoverflow.com/questions/2700015/why-cant-my-c-sharp-app-create-files-in-windows-7

So, it is not autoit problem! but how to solve it? in case I don't want to use explicit directory

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

1 hour ago, Sarah2016 said:

in case I don't want to use explicit directory

What is the issue with including the fully qualified path to shell the exe?

Jos 

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#13 ·  Posted

1 hour ago, Jos said:

What is the issue with including the fully qualified path to shell the exe?

Jos 

The exe file will have different directory!

I might run the exe file from my USB Drive ... it will be F:\ for example,

or it may be on the desktop

etc etc

 

I want to keep the created file with the exe in the same folder

Share this post


Link to post
Share on other sites

#14 ·  Posted

So what is the logic to find the exe for the script? is it the PATH env variable you want to depend upon?

Jos 


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#15 ·  Posted

28 minutes ago, Jos said:

So what is the logic to find the exe for the script? is it the PATH env variable you want to depend upon?

Jos 

didn't understand what you meant well..

the idea is that I have several computers .. i want to know when the computers were turned on and when they were shut down..

all have dropbox in them.. but the directory of dropbox differ..

I will keep this simple script in the dropbox folder of all computers  so that I can see the "event log" easily...

that's why I want to use @workingdir       to locate the dropbox

 

P.S. just knew that there are @workingdir and @scirptdir .. do they diffeR?

Share this post


Link to post
Share on other sites

#16 ·  Posted

I would expect the dropbox directory to be in a standard place as well. doesn't it by default exits in  @UserProfileDir\dropbox?

4 minutes ago, Sarah2016 said:

P.S. just knew that there are @workingdir and @scirptdir .. do they diffeR?

We have a pretty nice helpfile that explains that. ;) 

@ScriptDir: Directory containing the running script. Only includes a trailing backslash when the script is located in the root of a drive. 
@WorkingDir: Current/active working directory. Only includes a trailing backslash when the script is located in the root of a drive.

So the workdir is the default directory for the shelled program. 

All clear?

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#17 ·  Posted

2 minutes ago, Jos said:

I would expect the dropbox directory to be in a standard place as well. doesn't it by default exits in  @UserProfileDir\dropbox?

We have a pretty nice helpfile that explains that. ;) 

@ScriptDir: Directory containing the running script. Only includes a trailing backslash when the script is located in the root of a drive. 
@WorkingDir: Current/active working directory. Only includes a trailing backslash when the script is located in the root of a drive.

So the workdir is the default directory for the shelled program. 

All clear?

Jos

dropbox has default directory as you said but: 1) not all pc have dropbox in the default directory 2) even the default directory differs... as not all pc's have the same user account (e.g. some will be c:\user11\dropbox forexample others will hhave c:\user4444\dropbox) so I will need to use @userprofile and not explicit directory so we will get back to the same problem!

Share this post


Link to post
Share on other sites

#18 ·  Posted

Using  @userprofile & "\dropbox" is as pretty explicit to me and would be a good approach.
You somehow have to identify where the program is located before you can properly shell it or guess I am still missing what you are trying to get done here other than magic. :)

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#19 ·  Posted

3 minutes ago, Jos said:

Using  @userprofile & "\dropbox" is as pretty explicit to me and would be a good approach.
You somehow have to identify where the program is located before you can properly shell it or guess I am still missing what you are trying to get done here other than magic. :)

Jos

I'm beginner... Sorry.. but what does "shell" mean?

Share this post


Link to post
Share on other sites

#20 ·  Posted

Sorry for the IT talk but hey, that's what I've been infected with over the last 40 years. :)
Maybe this wiki is a good way to explain it in detail: https://en.wikipedia.org/wiki/Shell_(computing)
What I simply mean with Shell is  to run the program.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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