Jump to content

Run file at startup


Recommended Posts

Hi,

I have written a code which does too many work. I needed the file to launch at the system login. I have added the Startup entry at the initial of the code as below but when the machine logs in, the file gets enabled only in the Startup but does not runs in the Task automatically.

I have even added this code as a seperate AU3 file giving the same as Startup to call my existing file with all the codes inside and I am adding this new file to Startup but it still does the same action as Above.

 

Could you please let me know why the code does not shows as running in Task Process even though the Startup shows as Enabled?

 

RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Run", "Test", "REG_SZ", "Test File Path")
    Run("Test File Path")

 

Edited by sunshinesmile84
Link to comment
Share on other sites

RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Run", "Test", "REG_SZ", "Test File Path")     Run("Test File Path")

 

is this the code you wish to run ?

 

try this as a test

run ("cmd.exe")
WinWaitActive("Administrator: C:\WINDOWS\system32\cmd.exe")

as you can see once pc boots up and user has logged in command prompt will open.

if the code your using has to do with registry you may require admin rights.

 

 

Link to comment
Share on other sites

well, replacing with the CMD as per your's works out here So I would suspect something wrong from my end. Except here is the issue.

I had already added #RequireAdmin at the top of the code. Not sure why it doesn't work if I remove your WinWaitActive line.

Basically, what I needed was to keep the file in the Startup so it runs at login and running the complete script as Loop.

#RequireAdmin

RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Run", "Test", "REG_SZ", @DesktopDir & "\ProcessTest.exe")
Run(@DesktopDir & "\ProcessTest.exe")

 

Now, this ProcessTest.exe should always run in Startup and Processes as Loop, so it would keep on checking for the lines I have written in a loop.

#RequireAdmin

While ProcessExists("ProcessTest.exe")
    MsgBox(0, "", "1", 3)
    MsgBox(0, "", "2", 3)
    MsgBox(0, "", "3", 3)
    MsgBox(0, "", "4", 3)
    ContinueLoop
WEnd

 

Link to comment
Share on other sites

well, replacing with the CMD as per your's works out here So I would suspect something wrong from my end. Except here is the issue.

I had already added #RequireAdmin at the top of the code. Not sure why it doesn't work if I remove your WinWaitActive line.

Basically, what I needed was to keep the file in the Startup so it runs at login and running the complete script as Loop.

#RequireAdmin

RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Run", "Test", "REG_SZ", @DesktopDir & "\ProcessTest.exe")
Run(@DesktopDir & "\ProcessTest.exe")

 

Now, this ProcessTest.exe should always run in Startup and Processes as Loop, so it would keep on checking for the lines I have written in a loop.

#RequireAdmin

While ProcessExists("ProcessTest.exe")
    MsgBox(0, "", "1", 3)
    MsgBox(0, "", "2", 3)
    MsgBox(0, "", "3", 3)
    MsgBox(0, "", "4", 3)
    ContinueLoop
WEnd

 

good making progress. What i want to know is why are you using regwrite?

Use code i sent and compile as .exe then open start menu -> statup (folder) and paste .exe in this folder.

Any .exe in here will be exeicuted once logged in

Link to comment
Share on other sites

You can't use #RequireAdmin with a start up script because the script is going to wait for you to allow it to run, and it's probably not running in the same session as the user session. Take the #RequireAdmin out and see if it runs.

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

Link to comment
Share on other sites

You can't use #RequireAdmin with a start up script because the script is going to wait for you to allow it to run, and it's probably not running in the same session as the user session. Take the #RequireAdmin out and see if it runs.

Interesting. Somewhere else the solution was to link it with a batch file. So I created a "call c:\myEXE\myEXE.exe" batch file and placed THAT in the startup.  Solved the problem and I can retain #RequireAdmin in my EXE. 

Skysnake

Why is the snake in the sky?

Link to comment
Share on other sites

  • 5 years later...
  • 2 weeks later...

Beside the run keys available "in" HKCU as well as HKLM you also can use the Startup folder:

 

#RequireAdmin

$lnk=@StartupCommonDir & "\" & StringTrimRight(@ScriptName,4) & ".lnk"
if FileExists($lnk) Then
    MsgBox(0,"Startup Shortcut Check","LNK file already in place")
Else
    FileCreateShortcut(@ScriptFullPath,$lnk)
EndIf

But if your script needs to run with #RequireAdmin it will come up with a UAC prompt asking for admin creds for common user accounts.

Maybe installing as a sevice might be an alternative way to solve your task?

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

You won't bypass windows security. 

But if you are admin already with the current user, and you want to disable the UAC "prompt" then you can by writing in the registry. Without #RequireAdmin, so only in this case you can have a prompt activated before the script disable it during the script and enable it back, if wanted after.

 

In the others cases in which you've not the admin rights already with the current user. Then you will be prompt using the #RequireAdmin

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

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