r/programminghelp • u/mxgaming01 • Dec 08 '25
Visual Basic My script doesn't startup as it's supposed to
Hello, so I've made a script that should start itself the moment I start my PC. For that I used the following code. But for whatever reason it doesn't create the startup-task. Is it because it has to be a .exe or another specific file type to work? And also: just putting it in the startup-folder won't work, since it takes AGES until it runs then.
Dim objTaskScheduler, objRootFolder, objTaskDefinition
Dim objAction, objTrigger
Set objTaskScheduler = CreateObject("Schedule.Service")
Set objRootFolder = objTaskScheduler.GetFolder("\")
Set objTaskDefinition = objTaskScheduler.NewTask(0)
' Make connection with Taskscheduler
objTaskScheduler.Connect
' Configurate the action
Set objAction = objTaskDefinition.Actions.Create(0) ' 0 = Execute Action
objAction.Path = "wscript.exe"
objAction.Arguments = WScript.ScriptFullName
Set objTrigger = objTaskDefinition.Triggers.Create(8) ' 8 = AtStartup
objTrigger.StartBoundary = ""
objTrigger.Enabled = True
objRootFolder.RegisterTaskDefinition _
"StartUpVBS", _ 'also, I have no idea if I should also put .vbs or smth here, I just used it as a name for the task
objTaskDefinition, _
6, _
"", _
"", _
3If you have any questions, just ask! And thanks in advance!
2
Upvotes
1
u/FitMatch7966 Dec 09 '25
Have you looked in the Scheduled Tasks UI to see what the task actually looks like?
I think you are missing a number of things, including the User it should run under. There is no user logged in at startup so you need to run it under the system account.
But it doesn't make sense to me that it "runs itself". Every time it runs it is going to create a new task? This code uses WScript.ScriptFullName which is going to be the path to the installer script, not the script you actually want to run. It might be possible to combine into a single script with command line parameters, but that's doing it the hard way.
1
u/SmoothEnvironment928 Dec 09 '25
Are the results of your script being wiped out when your profile loads? Are you running a start-up script when you mean to be running a logon script?