Solved Win 10 Startup Batchfile doesn't work

May 2, 2018 at 03:37:25
Specs: Windows 10
For about the last 20 years I've had a batch file that runs when th computer starts, and it logs the start time. But now, with Win 10,
a)
I can't get it to run on startup. I had great difficulty in creating an Autoexec.bat - and when I did, it doesn't work ! And I am also blocked from accessing my User's Start folder; and
b)
the .bat file doesn't work when I run it, but when I paste the commands into a DOS window, they each work fine !

Here are the relevant lines:-
rem ==============[ StartUp ]============
:StartUp
echo on
H:
CD H:\Belfry
path %path;H:/Belfry
REM -----------[ Start log process ]------------------
Copy C:\WINDOWS\WindowsUpdate.log StartUp /Y
dir StartUp > Scrap.txt
Find /I "StartUp" < Scrap.txt >> Use-Log.txt
REM -----------[ End log process ]----------------------------------------------------
pause
Exit

It appears that "it" doesn't recognise the FIND command in a Batch file, but will as a direct command.


See More: Win 10 Startup Batchfile doesnt work

Report •

✔ Best Answer
May 3, 2018 at 08:39:24
1) As hidde663 has pointed out, you're messing up your PATH. Without a working PATH, CMD isn't able to locate FIND.EXE. Looking at the rest of your posted script, I don't see where this script would take advantage of the new PATH, so it's probably better to remove the line.

2) If you're looking for computer startup times, Windows already does that. Has for years. Look in the Event Viewer's System log. Specifically the entries from Microsoft-Windows-Kernel-Power / Kernel-Power.

How To Ask Questions The Smart Way



#1
May 2, 2018 at 10:12:11
to log startuptime to a file run this code:


echo %date% %time% >> "FULL PATH to file location here"


::example of "FULL PATH to file location here" == "C:\Users\%USERNAME%\Desktop\Startuptimes.log"

Find /I "StartUp" < Scrap.txt >> Use-Log.txt
need to be changed to:
Find /I "StartUp" "Scrap.txt" >> Use-Log.txt

path %path;H:/Belfry
should be:
set "path=%path%;H:/Belfry"

i5-6600K[delid]@4.8GHz/4.4GHz@1.39v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-13-13-28 1T 2800MHz@1.37v
MSI Armor RX 570 4GB@1435Mhz core@1.262v/1900MHz BiosModded

message edited by hidde663


Report •

#2
May 3, 2018 at 02:40:13
Thank you for your response.

Here's the error that I get when the command is in a Batch file:-

H:\Belfry>Find /I "StartUp" 0<Scrap.txt 1>>Use-Log.txt
'Find' is not recognized as an internal or external command,
operable program or batch file.

Yet it works just FINE when entered as a command !
------------------------------------------------------------------------

Your
echo %date% %time% >>

I have used, but I wanted to note the bootup time. I erred, above, it's actually NOT
Copy C:\WINDOWS\WindowsUpdate.log StartUp /Y

but

Copy C:\WINDOWS\bootstat.dat StartUp /Y

----------------------------------------------------------------
Your suggestion :-
Find /I "StartUp" < Scrap.txt >> Use-Log.txt
need to be changed to:
Find /I "StartUp" "Scrap.txt" >> Use-Log.txt
produces a different answer ;-)

The first gives just:-

03/05/2018 10:19 276 StartUp

which is what I want, while your suggestion gives:-

[crlf]
---------- SCRAP.TXT
03/05/2018 10:19 276 StartUp

But thank you for your suggestions.


Do you know how to solve the first question, though ?
HOW do I get it to run the batchfile on startup ?
It no longer runs autoexec.bat, and I'm not allowed (on my own computer!) to access the "User\StartUp" folder !

message edited by RobinClay


Report •

#3
May 3, 2018 at 03:20:50
Lets say i have very little experience with "User Permissions" ( And I am also blocked from accessing my User's Start folder)

anyways could you try this .bat file:

rem ==============[ StartUp ]============
@echo on
PUSHD "H:\Belfry"
set "PATH=%PATH%;H:\Belfry"
REM -----------[ Start log process ]-------------
Copy "%WINDIR%\bootstat.dat" "%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup\bootstat.dat" /Y
dir StartUp > Scrap.txt
for %%a in ('FINDSTR /I "StartUp" "Scrap.txt"') do echo %%a >> Use-Log.txt
REM -----------[ End log process ]---------------
echo DONE, exiting in 3 seconds...
timeout 3 >nul
exit/b

i5-6600K[delid]@4.8GHz/4.4GHz@1.39v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-13-13-28 1T 2800MHz@1.37v
MSI Armor RX 570 4GB@1420Mhz core@1.218v/1900MHz BiosModded


Report •

Related Solutions

#4
May 3, 2018 at 08:39:24
✔ Best Answer
1) As hidde663 has pointed out, you're messing up your PATH. Without a working PATH, CMD isn't able to locate FIND.EXE. Looking at the rest of your posted script, I don't see where this script would take advantage of the new PATH, so it's probably better to remove the line.

2) If you're looking for computer startup times, Windows already does that. Has for years. Look in the Event Viewer's System log. Specifically the entries from Microsoft-Windows-Kernel-Power / Kernel-Power.

How To Ask Questions The Smart Way


Report •

#5
May 3, 2018 at 12:35:28
Thanks again for having another go.

....rem ==============[ StartUp ]============
....@echo on
....PUSHD "H:\Belfry"

Not a command I have ever met before ! Thank you for the introduction.

....set "PATH=%PATH%;H:\Belfry"

Yes, I got that one wrong, didn't I !

....REM -----------[ Start log process ]-------------
....Copy "%WINDIR%\bootstat.dat" "%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup\bootstat.dat" /Y

Erm - No. It should be
Copy "%WINDIR%\bootstat.dat" "Startup" /Y
I copy that file so that I can capture its datestamp.
Which I do with this:-

....dir StartUp > Scrap.txt

....for %%a in ('FINDSTR /I "StartUp" "Scrap.txt"') do echo %%a >> Use-Log.txt

That didn't work for me - this is what it generated in the Use-Log.txt file :-

'FINDSTR
/I
"StartUp"
"Scrap.txt"'

So I changed it to:-
FINDSTR /I "StartUp" "Scrap.txt" >> Use-Log.txt
and it produced what I wanted:-
03/05/2018 13:34 67,584 StartUp

Thank you so much for your help - I am much obliged to you.


Report •

#6
May 3, 2018 at 12:40:55
I thank you, too, for your input.

1) Yes, indeed. Of course that's why it couldn't find FIND ! Silly me.
And, as you say, it's not necessary anyway !

2) MY "Use-Log.txt" I use to log other things as well, such as start & end times for coffee break, lunch, different Clients, "housekeeping", etc.

Thanks again.


Report •

Ask Question