Jump to content

Why this script does not work at startup unless i execute it with double click ?


Recommended Posts

Never mind, i tried to push arguments from autoit directly into net.exe

ShellExecuteWait (@SystemDir & "/NET.exe", "USE N: /DELETE",@SystemDir)
ShellExecuteWait (@SystemDir & "/NET.exe", "USE N: " & $Address,@SystemDir)

Still does not work.

Only works when script is executed at start up from C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

Executing script from "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" at start up does not work.

Clearly, there is a problem with autoit because it does not like to be executed from registry. It likes to be executed from a shortcut.

End of story.

Link to comment
Share on other sites

  • Replies 65
  • Created
  • Last Reply

Top Posters In This Topic

8 hours ago, tonycst said:

End of story.

Hey, I appreciate you taking the painstaking time to detail the problem with your Batman scenario.  I got it, I really did.  It works from startup folder, doesn't work from Run key in Registry; 'nuff said. 

I am interested in / unclear with what you meant in the second scenario when Batman said he is 'some user' to paraphrase and not 'I am Batman'.  I don't understand whyt the script would run in that manner.

I'll do some testing on my computer and see if I spot something.  Have you tried alternative methods / scripts besides AutoIt (BAT, vbscript, powershell, etc.)?

Link to comment
Share on other sites

By the second scenario user is exactly the same in both cases, but because it was executed from a different location, its treated as someone who has rights to execute but not a known user.

Its just a speculation but i think autoit either does not like to run from registry or when it does, it does not forward user credentials correctly.

I cant confirm that other then by looking at the failed commands. Someone who has the autoit source and understand it, needs to look at it and see how it operates running from registry VS from start menu start up.
 DEBUG autoit.

Link to comment
Share on other sites

1. C:\Users\Administrator\  (administrator local account)

2."HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" (currently logged in user/Any user)

are 2 different things. Are you sure that when you test you do it by logging with the same account ?

Link to comment
Share on other sites

@tonycst

Have you tried a simpler script that just runs NET USE with a hard coded mapping (just for testing purposes) through the registry?  After looking over your script, I wonder if the script is having a problem finding Address.txt to set your $Address variable when ran from the registry.

 

 

Link to comment
Share on other sites

On 3/21/2016 at 2:06 AM, Juvigy said:

1. C:\Users\Administrator\  (administrator local account)

2."HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" (currently logged in user/Any user)

are 2 different things. Are you sure that when you test you do it by logging with the same account ?

No other users on the computer. Only Administrator.
 

 

On 3/21/2016 at 5:56 AM, MuffinMan said:

@tonycst

Have you tried a simpler script that just runs NET USE with a hard coded mapping (just for testing purposes) through the registry?  After looking over your script, I wonder if the script is having a problem finding Address.txt to set your $Address variable when ran from the registry.

It does, but script generates it if its missing.

Funny thing, it generated it in the C:\Windows\SysWOW64 folder.  That tells me that something is wrong at the execution lever of autoit.

If file is missing, it should generate it in where the script ran from instead of from where it was executed.

So if script is executed by a user from D:\Script, it generates the address.txt in D:\Script\Address.txt

But if script is generated by registry, Address.txt is then generated in C:\Windows\SysWOW64

 

I've seen this before.

I cant trace it so i cant post a bug.

All i know is that when it executes via registry, its executed differently then from a shortcut in start up menu, and thats where the problem is located, at its execution behavior.

 

Link to comment
Share on other sites

When script runs from registry here it whats happening.

MsgBox (0,'',@ScriptDir) says "D:\Script\Network Drive Startup.exe"

The D:\Script DOES have Address.txt in it with valid address, yet next line of code $Address = FileReadLine ("Address.txt",1) says it does not.

So that tells me absolutely nothing.

It tells me that the scriptdir is correct, yet its not executed from where scriptdir returns its value.

 

 

This problem existed for long time and needs to be fixed.

Link to comment
Share on other sites

  • Developers
4 hours ago, tonycst said:

Funny thing, it generated it in the C:\Windows\SysWOW64 folder.  That tells me that something is wrong at the execution lever of autoit.

Not sure what you want to prove with this snippet:

MsgBox (0,'',@ScriptDir) says "D:\Script\Network Drive Startup.exe"

but it only proves to you what the scriptdirectory is, not the workdir where the subsequent FileReadLine() will try to find the file.
So you better change that to:

MsgBox (0,'',@WorkingDir)

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

You lucked out.  My test network was between projects, and I had a few minutes on my hands.

The problem is definitely your script, and not AutoIt.

With only a couple of fixes, I was able to make the script work on my text network double clicking to launch, running in a startup folder, AND from within the registry.

Before I tell you what I had to fix, I would like to point out that your major problem was that you were not willing to listen to any suggestions that people were giving you.  You seem to be suffering from the "I know what I know.  You are the problem, not me" syndrome.  A little humility will go a long way.  I was guilty of it in my earlier years, so I won't hold it against you.  But, I would suggest you avoid phrases like "I am not going to try that" (I read a few too may of those in this thread).

Now to the solution.

As Jos alluded to, you are not specifying paths for you "Address.txt" file, so the path it looks in will depend on how you launch it.  I would recommend using @AppDataCommonDIr, since it is available regardless how you launch your script.

$Address = FileReadLine (@AppDataCommonDir & "\Address.txt",1)
If $Address = "" Then
    FileDelete (@AppDataCommonDir & "\Address.txt")
    FileWrite (@AppDataCommonDir & "\Address.txt","192.168.1.1" & @CRLF & "Avobe address is used to connect to network drive")

Next, your NET USE command is not correct.  You were not preceding the IP address with the double backslash, nor were you pointing to a share.  In effect, you were just executing

%ComSpec% /K NET USE N: 192.168.1.1

By adding the double backslash and adding a share, the command worked properly

RunWait('"' & @ComSpec & '" /K NET USE N: \\' & $Address, '\sharename', @SW_SHOW)

Giving the effective command as

%ComSpec% /K NET USE N: \\192.168.1.1\sharename

After those two simple changes, the script works regardless which method you use to launch it.

Good luck.

Link to comment
Share on other sites

Quote

you are not specifying paths for you "Address.txt"

$Address = FileReadLine ("Address.txt",1)

If $Address = "" Then
    FileDelete ("Address.txt")
    FileWrite ("Address.txt","192.168.1.1" & @CRLF & "Avobe address is used to connect to network drive")
    MsgBox (16,"Error","No valid address was found." & @CRLF & "New Address.txt file was written. Please edit it for correct address and restart this application.")
EndIf

 

This means that if file is not found (where ever scrips is executed from) it will generate it and will read the address next time, yet it does not happen.

 

I also dont want to change file path, i want it in the script directory.

Quote

Next, your NET USE command is not correct

It works when i double click the script or run the script from the editor, how is that incorrect ?


My counter comment to you is that YOU are not even trying to run the script to know better.
You probably dont even  have a network drive to try to map it using my script to confirm that it only works when double clicked or ran from start up folder.

All most of people do is just look at the script and try to find a problem.

Its plane simple code.

ShellExecuteWait (@SystemDir & "/NET.exe", "USE N: /DELETE",@SystemDir)
ShellExecuteWait (@SystemDir & "/NET.exe", "USE N: \\readyshare\USB_Storage",@SystemDir)
RegWrite ("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run","Network Drive StartUp","REG_SZ",@ScriptFullPath)

#1 Compile the code (Edit the address if needed), and run it once.

It will add its self to start from registry.

#2 Restart the computer and observe that network drive is not mapped.

#3 Double click the script and observe, network drive is mapped.

#4 Resolve the problem without changing the location from which script starts (registry)

Unless you run it, i cant take your comments seriously because they are based on a theory of observation but not actual test. Kinda like evolution with the exception that no one even observed it.

Edited by tonycst
Link to comment
Share on other sites

  • Developers
59 minutes ago, tonycst said:

Unless you run it, i cant take your comments seriously because they are based on a theory of observation but not actual test. Kinda like evolution with the exception that no one even observed it.

I like the attitude. :idiot:

Just tried this compiled as x86 script both Logout-Login and restart and worked fine:

FileDelete(@ScriptDir & "\test.log")
FileWriteLine(@ScriptDir & "\test.log","ShellExecute:")
$rc=ShellExecuteWait (@SystemDir & "/NET.exe", "USE S: /DELETE",@SystemDir)
FileWriteLine(@ScriptDir & "\test.log",$rc)
$rc=ShellExecuteWait (@SystemDir & "/NET.exe", "USE S: \\server\Backups",@SystemDir)
FileWriteLine(@ScriptDir & "\test.log",$rc)
RegWrite ("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run","Network Drive StartUp","REG_SZ",@ScriptFullPath)

test.log:

ShellExecute:
0
0

Your turn. ;)

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

tonycst

You might want to try re-reading my post.

On Monday, March 28, 2016 at 3:17 PM, willichan said:

You lucked out.  My test network was between projects, and I had a few minutes on my hands.

The problem is definitely your script, and not AutoIt.

With only a couple of fixes, I was able to make the script work on my text network double clicking to launch, running in a startup folder, AND from within the registry.

So ... yes, I did run your code.  I do understand your code on a practical (tested) level, not just theoretical, even if I don't agree with most of your methodologies.  Alhough, it did not take actually running your code for me to identify what your problems are.

If you don't want to use the folder I suggested, that is fine.  I really don't care where you store it.  It was a practical suggestion based on recommended standards and personal experience, but just a suggestion none the less.  You still should specify the path to the file, wherever you put it, but it is your script ... your decision.

You've been handed the answer on a platter, and had several people attempt to help and guide you.  I wish you luck.  You are on your own now.

Edited by willichan
Link to comment
Share on other sites

Perhaps my problem is that windows 7 is on Administrator account instead of regular user with administrative privileges ?

I had issues with scripts because of that when i jumped back and forth from 7 to 10.

Link to comment
Share on other sites

6 hours ago, tonycst said:

Perhaps my problem is that windows 7 is on Administrator account instead of regular user with administrative privileges ?

I had issues with scripts because of that when i jumped back and forth from 7 to 10.

Perhaps your problem is what willichan point out in post #30 "your NET USE command is not correct."

Post #20 you said "net command returns error 67 (i looked it up) which means absolutely nothing wrong with the arguments"

Do the following steps:

1) Open command prompt

2) Type net helpmsg 67 press enter

You get the following message "The network name cannot be found."

Once you fix the NET USE  in your script because you are executing the script on the Administrator account you may get error 5 meaning "Access is denied."

Edited by Danny35d
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

On 3/30/2016 at 3:08 PM, Jos said:

 

test.log:

ShellExecute:
0
0

Your turn. ;)

Jos

ShellExecute:
2
2

Danny35d

Quote

Perhaps your problem is what willichan point out in post #30 "your NET USE command is not correct."

You make no sense. Command is 100% correct because it does what it suppose to do when i run the script.

It returns 0's on shellexecute as per Jos attempt, but returns 2's when its ran from registry.

Edited by tonycst
Link to comment
Share on other sites

  • Developers

Lets do another experiment and try running this compiled script at login, doing it the old fashioned way:

FileDelete(@ScriptDir & "\test.bat")
FileWriteLine(@ScriptDir & "\test.bat",'Echo @ALL')
FileWriteLine(@ScriptDir & "\test.bat",'Echo NET USE N: /DELETE > "' & @ScriptDir & '\test.log" 2>&1')
FileWriteLine(@ScriptDir & "\test.bat",'NET USE N: /DELETE>> "' & @ScriptDir & '\test.log" 2>&1')
FileWriteLine(@ScriptDir & "\test.bat",'Echo NET USE N: \\readyshare\USB_Storage >> "' & @ScriptDir & '\test.log" 2>&1')
FileWriteLine(@ScriptDir & "\test.bat",'NET USE N: \\readyshare\USB_Storage >> "' & @ScriptDir & '\test.log" 2>&1')
RunWait(@ComSpec & ' /c "' & @ScriptDir & '\test.bat"')

Curious how the test.log will look for you.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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